44
55require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php ' ;
66
7+ use Piwik \Container \StaticContainer ;
8+ use Piwik \Log \Logger ;
79use Piwik \Plugins \PerformanceAudit \Exceptions \DependencyMissingException ;
810use Symfony \Component \Process \ExecutableFinder as BaseExecutableFinder ;
911
@@ -28,6 +30,9 @@ public static function search($name)
2830 [__DIR__ . DIRECTORY_SEPARATOR . 'node_modules ' . DIRECTORY_SEPARATOR . '.bin ' ],
2931 explode (PATH_SEPARATOR , self ::getDefaultPath ())
3032 );
33+ StaticContainer::get (Logger::class)->debug ('Searching for executable in directories. ' ,
34+ ['executable ' => $ name , 'directories ' => $ extraDirs ]);
35+
3136 $ executablePath = (new parent ())->find ($ name , false , $ extraDirs );
3237 if (!$ executablePath ) {
3338 throw new DependencyMissingException ($ name , $ extraDirs );
@@ -42,28 +47,45 @@ public static function search($name)
4247 * @return string
4348 */
4449 public static function getDefaultPath () {
45- return ExecutableFinder::isRunningOnWindows () ?
46- implode ("; " , [
47- '%SystemRoot%\system32 ' ,
48- '%SystemRoot% ' ,
49- '%SystemRoot%\System32\Wbem '
50- ]) :
51- implode (": " , [
52- '/usr/local/sbin ' ,
53- '/usr/local/bin ' ,
54- '/usr/sbin ' ,
55- '/usr/bin ' ,
56- '/sbin ' ,
57- '/bin ' ,
58- '/opt/plesk/node/24/bin ' ,
59- '/opt/plesk/node/22/bin ' ,
60- '/opt/plesk/node/20/bin ' ,
61- '/opt/plesk/node/18/bin ' ,
62- '/opt/plesk/node/16/bin ' ,
63- '/opt/plesk/node/14/bin ' ,
64- '/opt/plesk/node/12/bin ' ,
65- '/opt/plesk/node/10/bin '
66- ]);
50+ $ searchPaths = ExecutableFinder::isRunningOnWindows () ? [
51+ '%SystemRoot%\system32 ' ,
52+ '%SystemRoot% ' ,
53+ '%SystemRoot%\System32\Wbem '
54+ ] : [
55+ '/usr/local/sbin ' ,
56+ '/usr/local/bin ' ,
57+ '/usr/sbin ' ,
58+ '/usr/bin ' ,
59+ '/sbin ' ,
60+ '/bin ' ,
61+ '/opt/plesk/node/24/bin ' ,
62+ '/opt/plesk/node/22/bin ' ,
63+ '/opt/plesk/node/20/bin ' ,
64+ '/opt/plesk/node/18/bin ' ,
65+ '/opt/plesk/node/16/bin ' ,
66+ '/opt/plesk/node/14/bin ' ,
67+ '/opt/plesk/node/12/bin ' ,
68+ '/opt/plesk/node/10/bin '
69+ ];
70+ $ additionalSearchPaths = ExecutableFinder::getPathsFromEnvironmentVariablePath ();
71+ $ finalSearchPaths = array_unique (array_merge ($ searchPaths , $ additionalSearchPaths ));
72+
73+ return implode (PATH_SEPARATOR , $ finalSearchPaths );
74+ }
75+
76+ /**
77+ * Return paths as array if `PATH` environment variable is set,
78+ * empty array otherwise.
79+ *
80+ * @return array
81+ */
82+ private static function getPathsFromEnvironmentVariablePath () {
83+ $ envPath = getenv ('PATH ' );
84+ if (!is_string ($ envPath )) {
85+ return [];
86+ }
87+
88+ return explode (PATH_SEPARATOR , $ envPath );
6789 }
6890
6991 /**
0 commit comments