ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ExecutableFinder.php
Go to the documentation of this file.
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 
13 
21 {
22  private $suffixes = array('.exe', '.bat', '.cmd', '.com');
23 
29  public function setSuffixes(array $suffixes)
30  {
31  $this->suffixes = $suffixes;
32  }
33 
39  public function addSuffix($suffix)
40  {
41  $this->suffixes[] = $suffix;
42  }
43 
53  public function find($name, $default = null, array $extraDirs = array())
54  {
55  if (ini_get('open_basedir')) {
56  $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
57  $dirs = array();
58  foreach ($searchPath as $path) {
59  // Silencing against https://bugs.php.net/69240
60  if (@is_dir($path)) {
61  $dirs[] = $path;
62  } else {
63  if (basename($path) == $name && is_executable($path)) {
64  return $path;
65  }
66  }
67  }
68  } else {
69  $dirs = array_merge(
70  explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
71  $extraDirs
72  );
73  }
74 
75  $suffixes = array('');
76  if ('\\' === DIRECTORY_SEPARATOR) {
77  $pathExt = getenv('PATHEXT');
78  $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
79  }
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))) {
83  return $file;
84  }
85  }
86  }
87 
88  return $default;
89  }
90 }
$path
Definition: aliased.php:25
setSuffixes(array $suffixes)
Replaces default suffixes of executable.
addSuffix($suffix)
Adds new possible suffix to check for executable.
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
find($name, $default=null, array $extraDirs=array())
Finds an executable by name.