PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / symfony / process / ExecutableFinder.php
matomo / app / vendor / symfony / process Last commit date
Exception 1 year ago Pipes 1 year ago ExecutableFinder.php 1 year ago InputStream.php 1 year ago LICENSE 1 year ago PhpExecutableFinder.php 1 year ago PhpProcess.php 1 year ago Process.php 3 months ago ProcessUtils.php 1 year ago README.md 1 year ago
ExecutableFinder.php
83 lines
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 namespace Symfony\Component\Process;
12
13 /**
14 * Generic executable finder.
15 *
16 * @author Fabien Potencier <fabien@symfony.com>
17 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
18 */
19 class ExecutableFinder
20 {
21 private const CMD_BUILTINS = ['assoc', 'break', 'call', 'cd', 'chdir', 'cls', 'color', 'copy', 'date', 'del', 'dir', 'echo', 'endlocal', 'erase', 'exit', 'for', 'ftype', 'goto', 'help', 'if', 'label', 'md', 'mkdir', 'mklink', 'move', 'path', 'pause', 'popd', 'prompt', 'pushd', 'rd', 'rem', 'ren', 'rename', 'rmdir', 'set', 'setlocal', 'shift', 'start', 'time', 'title', 'type', 'ver', 'vol'];
22 private $suffixes = [];
23 /**
24 * Replaces default suffixes of executable.
25 */
26 public function setSuffixes(array $suffixes)
27 {
28 $this->suffixes = $suffixes;
29 }
30 /**
31 * Adds new possible suffix to check for executable.
32 */
33 public function addSuffix(string $suffix)
34 {
35 $this->suffixes[] = $suffix;
36 }
37 /**
38 * Finds an executable by name.
39 *
40 * @param string $name The executable name (without the extension)
41 * @param string|null $default The default to return if no executable is found
42 * @param array $extraDirs Additional dirs to check into
43 *
44 * @return string|null
45 */
46 public function find(string $name, ?string $default = null, array $extraDirs = [])
47 {
48 // windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
49 if ('\\' === \DIRECTORY_SEPARATOR && \in_array(strtolower($name), self::CMD_BUILTINS, \true)) {
50 return $name;
51 }
52 $dirs = array_merge(explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), $extraDirs);
53 $suffixes = [];
54 if ('\\' === \DIRECTORY_SEPARATOR) {
55 $pathExt = getenv('PATHEXT');
56 $suffixes = $this->suffixes;
57 $suffixes = array_merge($suffixes, $pathExt ? explode(\PATH_SEPARATOR, $pathExt) : ['.exe', '.bat', '.cmd', '.com']);
58 }
59 $suffixes = '' !== pathinfo($name, \PATHINFO_EXTENSION) ? array_merge([''], $suffixes) : array_merge($suffixes, ['']);
60 foreach ($suffixes as $suffix) {
61 foreach ($dirs as $dir) {
62 if ('' === $dir) {
63 $dir = '.';
64 }
65 if (@is_file($file = $dir . \DIRECTORY_SEPARATOR . $name . $suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {
66 return $file;
67 }
68 if (!@is_dir($dir) && basename($dir) === $name . $suffix && @is_executable($dir)) {
69 return $dir;
70 }
71 }
72 }
73 if ('\\' === \DIRECTORY_SEPARATOR || !\function_exists('exec') || \strlen($name) !== strcspn($name, '/' . \DIRECTORY_SEPARATOR)) {
74 return $default;
75 }
76 $execResult = exec('command -v -- ' . escapeshellarg($name));
77 if (($executablePath = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) && @is_executable($executablePath)) {
78 return $executablePath;
79 }
80 return $default;
81 }
82 }
83