PageRenderTime 237ms CodeModel.GetById 96ms app.highlight 1ms RepoModel.GetById 79ms app.codeStats 0ms

/lib/LimeCommand.php

http://github.com/bschussek/lime
PHP | 51 lines | 41 code | 8 blank | 2 comment | 0 complexity | 1320b49e6ac22aaa6d61e583c8ee590c MD5 | raw file
 1<?php
 2
 3class LimeCommand
 4{
 5  protected
 6    $command    = null,
 7    $status     = null,
 8    $output     = '',
 9    $errors     = '',
10    $errorFile  = '';
11
12  public function __construct(LimeExecutable $executable, $file)
13  {
14    $this->errorFile = tempnam(sys_get_temp_dir(), 'lime');
15    $executable = str_replace('%file%', escapeshellarg($file), $executable->getCommand());
16
17    // see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing
18    $this->command = sprintf(
19      'cd & %s 2>%s',
20      $executable,
21      $this->errorFile
22    );
23  }
24
25  public function execute()
26  {
27    // clear old errors
28    $this->errors = '';
29    file_put_contents($this->errorFile, '');
30
31    ob_start();
32    passthru($this->command, $this->status);
33    $this->output = ob_get_clean();
34    $this->errors = file_get_contents($this->errorFile);
35  }
36
37  public function getStatus()
38  {
39    return $this->status;
40  }
41
42  public function getOutput()
43  {
44    return $this->output;
45  }
46
47  public function getErrors()
48  {
49    return $this->errors;
50  }
51}