4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Process;
15 * Generic executable finder.
17 * @author Fabien Potencier <fabien@symfony.com>
18 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
20 class ExecutableFinder
22 private $suffixes = array('.exe', '.bat', '.cmd', '.com');
25 * Replaces default suffixes of executable.
27 * @param array $suffixes
29 public function setSuffixes(array $suffixes)
31 $this->suffixes = $suffixes;
35 * Adds new possible suffix to check for executable.
37 * @param string $suffix
39 public function addSuffix($suffix)
41 $this->suffixes[] = $suffix;
45 * Finds an executable by name.
47 * @param string $name The executable name (without the extension)
48 * @param string $default The default to return if no executable is found
49 * @param array $extraDirs Additional dirs to check into
51 * @return string The executable path or default value
53 public function find($name, $default = null, array $extraDirs = array())
55 if (ini_get('open_basedir')) {
56 $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
58 foreach ($searchPath as $path) {
59 // Silencing against https://bugs.php.net/69240
63 if (basename($path) == $name && @is_executable($path)) {
70 explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
75 $suffixes = array('');
76 if ('\\' === DIRECTORY_SEPARATOR) {
77 $pathExt = getenv('PATHEXT');
78 $suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
80 foreach ($suffixes as $suffix) {
81 foreach ($dirs as $dir) {
82 if (@is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {