vendor/symfony/src/Symfony/Component/Process/PhpProcess.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Component\Process;
       
    13 
       
    14 /**
       
    15  * PhpProcess runs a PHP script in an independent process.
       
    16  *
       
    17  * $p = new PhpProcess('<?php echo "foo"; ?>');
       
    18  * $p->run();
       
    19  * print $p->getOutput()."\n";
       
    20  *
       
    21  * @author Fabien Potencier <fabien@symfony.com>
       
    22  *
       
    23  * @api
       
    24  */
       
    25 class PhpProcess extends Process
       
    26 {
       
    27     private $executableFinder;
       
    28 
       
    29     /**
       
    30      * Constructor.
       
    31      *
       
    32      * @param string  $script  The PHP script to run (as a string)
       
    33      * @param string  $cwd     The working directory
       
    34      * @param array   $env     The environment variables
       
    35      * @param integer $timeout The timeout in seconds
       
    36      * @param array   $options An array of options for proc_open
       
    37      *
       
    38      * @api
       
    39      */
       
    40     public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
       
    41     {
       
    42         parent::__construct(null, $cwd, $env, $script, $timeout, $options);
       
    43 
       
    44         $this->executableFinder = new PhpExecutableFinder();
       
    45     }
       
    46 
       
    47     /**
       
    48      * Sets the path to the PHP binary to use.
       
    49      *
       
    50      * @api
       
    51      */
       
    52     public function setPhpBinary($php)
       
    53     {
       
    54         $this->setCommandLine($php);
       
    55     }
       
    56 
       
    57     /**
       
    58      * Runs the process.
       
    59      *
       
    60      * @param Closure|string|array $callback A PHP callback to run whenever there is some
       
    61      *                                       output available on STDOUT or STDERR
       
    62      *
       
    63      * @return integer The exit status code
       
    64      *
       
    65      * @api
       
    66      */
       
    67     public function run($callback = null)
       
    68     {
       
    69         if (null === $this->getCommandLine()) {
       
    70             if (false === $php = $this->executableFinder->find()) {
       
    71                 throw new \RuntimeException('Unable to find the PHP executable.');
       
    72             }
       
    73             $this->setCommandLine($php);
       
    74         }
       
    75 
       
    76         return parent::run($callback);
       
    77     }
       
    78 }