lime /lib/LimeCommand.php

Language PHP Lines 51
MD5 Hash 1320b49e6ac22aaa6d61e583c8ee590c Estimated Cost $896 (why?)
Repository git://github.com/bschussek/lime.git View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

class LimeCommand
{
  protected
    $command    = null,
    $status     = null,
    $output     = '',
    $errors     = '',
    $errorFile  = '';

  public function __construct(LimeExecutable $executable, $file)
  {
    $this->errorFile = tempnam(sys_get_temp_dir(), 'lime');
    $executable = str_replace('%file%', escapeshellarg($file), $executable->getCommand());

    // see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing
    $this->command = sprintf(
      'cd & %s 2>%s',
      $executable,
      $this->errorFile
    );
  }

  public function execute()
  {
    // clear old errors
    $this->errors = '';
    file_put_contents($this->errorFile, '');

    ob_start();
    passthru($this->command, $this->status);
    $this->output = ob_get_clean();
    $this->errors = file_get_contents($this->errorFile);
  }

  public function getStatus()
  {
    return $this->status;
  }

  public function getOutput()
  {
    return $this->output;
  }

  public function getErrors()
  {
    return $this->errors;
  }
}
Back to Top