PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 1ms 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
Possible License(s): ISC
  1. <?php
  2. class LimeCommand
  3. {
  4. protected
  5. $command = null,
  6. $status = null,
  7. $output = '',
  8. $errors = '',
  9. $errorFile = '';
  10. public function __construct(LimeExecutable $executable, $file)
  11. {
  12. $this->errorFile = tempnam(sys_get_temp_dir(), 'lime');
  13. $executable = str_replace('%file%', escapeshellarg($file), $executable->getCommand());
  14. // see http://trac.symfony-project.org/ticket/5437 for the explanation on the weird "cd" thing
  15. $this->command = sprintf(
  16. 'cd & %s 2>%s',
  17. $executable,
  18. $this->errorFile
  19. );
  20. }
  21. public function execute()
  22. {
  23. // clear old errors
  24. $this->errors = '';
  25. file_put_contents($this->errorFile, '');
  26. ob_start();
  27. passthru($this->command, $this->status);
  28. $this->output = ob_get_clean();
  29. $this->errors = file_get_contents($this->errorFile);
  30. }
  31. public function getStatus()
  32. {
  33. return $this->status;
  34. }
  35. public function getOutput()
  36. {
  37. return $this->output;
  38. }
  39. public function getErrors()
  40. {
  41. return $this->errors;
  42. }
  43. }