[Process] changed ExecutableFinder to return false instead of throwing an exception when the executable is not found
I've made the change as the executable goal is to find the executable. The fact that it does not find it is part of the contract and it is not exceptional.
This commit is contained in:
parent
f12146d0ec
commit
e2741cefc4
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Bundle\AsseticBundle\DependencyInjection;
|
namespace Symfony\Bundle\AsseticBundle\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\Process\ExecutableFinder;
|
use Symfony\Component\Process\ExecutableFinder;
|
||||||
use Symfony\Component\Process\Exception\ExecutableNotFoundException;
|
|
||||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||||
|
|
||||||
@ -58,9 +57,9 @@ class Configuration implements ConfigurationInterface
|
|||||||
->booleanNode('use_controller')->defaultValue($this->debug)->end()
|
->booleanNode('use_controller')->defaultValue($this->debug)->end()
|
||||||
->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end()
|
->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end()
|
||||||
->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end()
|
->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end()
|
||||||
->scalarNode('java')->defaultValue(function() use ($finder) { try { return $finder->find('java'); } catch(ExecutableNotFoundException $ex) { return null; } })->end()
|
->scalarNode('java')->defaultValue(function() use ($finder) { $java = $finder->find('java'); return $java ? $java : '/usr/bin/java'; })->end()
|
||||||
->scalarNode('node')->defaultValue(function() use ($finder) { try { return $finder->find('node'); } catch(ExecutableNotFoundException $ex) { return null; } })->end()
|
->scalarNode('node')->defaultValue(function() use ($finder) { $node = $finder->find('node'); return $node ? $node : '/usr/bin/node'; })->end()
|
||||||
->scalarNode('sass')->defaultValue(function() use ($finder) { try { return $finder->find('sass'); } catch(ExecutableNotFoundException $ex) { return null; } })->end()
|
->scalarNode('sass')->defaultValue(function() use ($finder) { $saas = $finder->find('saas'); return $saas ? $saas : '/usr/bin/saas'; })->end()
|
||||||
->end()
|
->end()
|
||||||
|
|
||||||
// bundles
|
// bundles
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Component\Process\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base exception interface for this component.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*/
|
|
||||||
interface Exception
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Component\Process\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown when an executable is not found.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*/
|
|
||||||
class ExecutableNotFoundException extends RuntimeException
|
|
||||||
{
|
|
||||||
private $name;
|
|
||||||
|
|
||||||
public function __construct($name)
|
|
||||||
{
|
|
||||||
parent::__construct(sprintf('Could not find executable "%s".', $name));
|
|
||||||
|
|
||||||
$this->name = $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Component\Process\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RuntimeException for this component.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*/
|
|
||||||
class RuntimeException extends \RuntimeException implements Exception
|
|
||||||
{
|
|
||||||
}
|
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Process;
|
namespace Symfony\Component\Process;
|
||||||
|
|
||||||
use Symfony\Component\Process\Exception\ExecutableNotFoundException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic executable finder.
|
* Generic executable finder.
|
||||||
*
|
*
|
||||||
@ -33,6 +31,13 @@ class ExecutableFinder
|
|||||||
$this->suffixes[] = $suffix;
|
$this->suffixes[] = $suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an executable by name.
|
||||||
|
*
|
||||||
|
* @param string $name The executable name (without the extension)
|
||||||
|
*
|
||||||
|
* @return string|false The executable path or false if it cannot be found
|
||||||
|
*/
|
||||||
public function find($name)
|
public function find($name)
|
||||||
{
|
{
|
||||||
$dirs = explode(PATH_SEPARATOR, getenv('PATH') ? getenv('PATH') : getenv('Path'));
|
$dirs = explode(PATH_SEPARATOR, getenv('PATH') ? getenv('PATH') : getenv('Path'));
|
||||||
@ -45,6 +50,6 @@ class ExecutableFinder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ExecutableNotFoundException($name);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,16 @@ class PhpExecutableFinder
|
|||||||
$this->executableFinder = new ExecutableFinder();
|
$this->executableFinder = new ExecutableFinder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds The PHP executable.
|
||||||
|
*
|
||||||
|
* @return string|false The PHP executable path or false if it cannot be found
|
||||||
|
*/
|
||||||
public function find()
|
public function find()
|
||||||
{
|
{
|
||||||
if ($php = getenv('PHP_PATH')) {
|
if ($php = getenv('PHP_PATH')) {
|
||||||
if (!is_executable($php)) {
|
if (!is_executable($php)) {
|
||||||
throw new RuntimeException('The defined PHP_PATH environment variable is not a valid PHP executable.');
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $php;
|
return $php;
|
||||||
@ -53,4 +58,4 @@ class PhpExecutableFinder
|
|||||||
|
|
||||||
return $this->executableFinder->find('php');
|
return $this->executableFinder->find('php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,10 @@ class PhpProcess extends Process
|
|||||||
public function run($callback = null)
|
public function run($callback = null)
|
||||||
{
|
{
|
||||||
if (null === $this->getCommandLine()) {
|
if (null === $this->getCommandLine()) {
|
||||||
$this->setCommandLine($this->executableFinder->find());
|
if (false === $php = $this->executableFinder->find()) {
|
||||||
|
throw new \RuntimeException('Unable to find the PHP executable.');
|
||||||
|
}
|
||||||
|
$this->setCommandLine($php);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::run($callback);
|
return parent::run($callback);
|
||||||
|
Reference in New Issue
Block a user