Process.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Util;
  12. use Symfony\Component\Process\Process as BaseProcess;
  13. /**
  14. * @author Robert Schönthal <seroscho@googlemail.com>
  15. */
  16. class Process extends BaseProcess
  17. {
  18. /**
  19. * runs a process on the commandline
  20. *
  21. * @static
  22. * @param $command the command to execute
  23. * @param null $output the output will be written into this var if passed
  24. * @return int statuscode
  25. */
  26. public static function execute($command, &$output = null)
  27. {
  28. $process = new static($command);
  29. $process->run(function($type, $buffer) use ($output) {
  30. if (null === $output) {
  31. return;
  32. }
  33. echo $buffer;
  34. });
  35. if (null !== $output) {
  36. $output = $process->getOutput();
  37. }
  38. return $process->getExitCode();
  39. }
  40. }