PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.12.4
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.12.4
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / symfony / process / ExecutableFinder.php

ExecutableFinder.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.12.4, at vendor/symfony/process/ExecutableFinder.php

106 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 * Generic executable finder.
16 *
17 * @author Fabien Potencier <[email protected]>
18 * @author Johannes M. Schmitt <[email protected]>
19 */
20 class ExecutableFinder
21 {
22 private const CMD_BUILTINS = [
23 'assoc', 'break', 'call', 'cd', 'chdir', 'cls', 'color', 'copy', 'date',
24 'del', 'dir', 'echo', 'endlocal', 'erase', 'exit', 'for', 'ftype', 'goto',
25 'help', 'if', 'label', 'md', 'mkdir', 'mklink', 'move', 'path', 'pause',
26 'popd', 'prompt', 'pushd', 'rd', 'rem', 'ren', 'rename', 'rmdir', 'set',
27 'setlocal', 'shift', 'start', 'time', 'title', 'type', 'ver', 'vol',
28 ];
29
30 private array $suffixes = [];
31
32 /**
33 * Replaces default suffixes of executable.
34 *
35 * @return void
36 */
37 public function setSuffixes(array $suffixes)
38 {
39 $this->suffixes = $suffixes;
40 }
41
42 /**
43 * Adds new possible suffix to check for executable.
44 *
45 * @return void
46 */
47 public function addSuffix(string $suffix)
48 {
49 $this->suffixes[] = $suffix;
50 }
51
52 /**
53 * Finds an executable by name.
54 *
55 * @param string $name The executable name (without the extension)
56 * @param string|null $default The default to return if no executable is found
57 * @param array $extraDirs Additional dirs to check into
58 */
59 public function find(string $name, ?string $default = null, array $extraDirs = []): ?string
60 {
61 // windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
62 if ('\\' === \DIRECTORY_SEPARATOR && \in_array(strtolower($name), self::CMD_BUILTINS, true)) {
63 return $name;
64 }
65
66 $dirs = array_merge(
67 explode(\PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
68 $extraDirs
69 );
70
71 $suffixes = [];
72 if ('\\' === \DIRECTORY_SEPARATOR) {
73 $pathExt = getenv('PATHEXT');
74 $suffixes = $this->suffixes;
75 $suffixes = array_merge($suffixes, $pathExt ? explode(\PATH_SEPARATOR, $pathExt) : ['.exe', '.bat', '.cmd', '.com']);
76 }
77 $suffixes = '' !== pathinfo($name, \PATHINFO_EXTENSION) ? array_merge([''], $suffixes) : array_merge($suffixes, ['']);
78 foreach ($suffixes as $suffix) {
79 foreach ($dirs as $dir) {
80 if ('' === $dir) {
81 $dir = '.';
82 }
83 if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) {
84 return $file;
85 }
86
87 if (!@is_dir($dir) && basename($dir) === $name.$suffix && @is_executable($dir)) {
88 return $dir;
89 }
90 }
91 }
92
93 if ('\\' === \DIRECTORY_SEPARATOR || !\function_exists('exec') || \strlen($name) !== strcspn($name, '/'.\DIRECTORY_SEPARATOR)) {
94 return $default;
95 }
96
97 $execResult = exec('command -v -- '.escapeshellarg($name));
98
99 if (($executablePath = substr($execResult, 0, strpos($execResult, \PHP_EOL) ?: null)) && @is_executable($executablePath)) {
100 return $executablePath;
101 }
102
103 return $default;
104 }
105 }
106