@@ -23,6 +23,8 @@ class ExecutableFinder
23
23
24
24
/**
25
25
* Replaces default suffixes of executable.
26
+ *
27
+ * @param array $suffixes
26
28
*/
27
29
public function setSuffixes (array $ suffixes )
28
30
{
@@ -40,15 +42,40 @@ public function addSuffix($suffix)
40
42
}
41
43
42
44
/**
43
- * Finds an executable by name.
45
+ * Finds an executable by name in given directories .
44
46
*
45
47
* @param string $name The executable name (without the extension)
48
+ * @param array $dirs Dirs to check into
46
49
* @param string $default The default to return if no executable is found
47
- * @param array $extraDirs Additional dirs to check into
48
50
*
49
51
* @return string The executable path or default value
50
52
*/
51
- public function find ($ name , $ default = null , array $ extraDirs = array ())
53
+ public function findIn ($ name , array $ dirs = array (), $ default = null )
54
+ {
55
+ $ suffixes = array ('' );
56
+ if ('\\' === DIRECTORY_SEPARATOR ) {
57
+ $ pathExt = getenv ('PATHEXT ' );
58
+ $ suffixes = array_merge ($ suffixes , $ pathExt ? explode (PATH_SEPARATOR , $ pathExt ) : $ this ->suffixes );
59
+ }
60
+ foreach ($ suffixes as $ suffix ) {
61
+ foreach ($ dirs as $ dir ) {
62
+ if (@is_file ($ file = $ dir .DIRECTORY_SEPARATOR .$ name .$ suffix ) && ('\\' === DIRECTORY_SEPARATOR || is_executable ($ file ))) {
63
+ return $ file ;
64
+ }
65
+ }
66
+ }
67
+
68
+ return $ default ;
69
+ }
70
+
71
+ /**
72
+ * Returns the search path directories from environment
73
+ *
74
+ * @param array $extraDirs Additional dirs to check into
75
+ *
76
+ * @return string[] The search paths
77
+ */
78
+ public function path (array $ extraDirs = array ())
52
79
{
53
80
if (ini_get ('open_basedir ' )) {
54
81
$ searchPath = explode (PATH_SEPARATOR , ini_get ('open_basedir ' ));
@@ -70,19 +97,24 @@ public function find($name, $default = null, array $extraDirs = array())
70
97
);
71
98
}
72
99
73
- $ suffixes = array ('' );
74
- if ('\\' === DIRECTORY_SEPARATOR ) {
75
- $ pathExt = getenv ('PATHEXT ' );
76
- $ suffixes = array_merge ($ suffixes , $ pathExt ? explode (PATH_SEPARATOR , $ pathExt ) : $ this ->suffixes );
77
- }
78
- foreach ($ suffixes as $ suffix ) {
79
- foreach ($ dirs as $ dir ) {
80
- if (@is_file ($ file = $ dir .DIRECTORY_SEPARATOR .$ name .$ suffix ) && ('\\' === DIRECTORY_SEPARATOR || is_executable ($ file ))) {
81
- return $ file ;
82
- }
83
- }
84
- }
100
+ return $ dirs ;
101
+ }
85
102
86
- return $ default ;
103
+ /**
104
+ * Finds an executable by name.
105
+ *
106
+ * @param string $name The executable name (without the extension)
107
+ * @param string $default The default to return if no executable is found
108
+ * @param array $extraDirs Additional dirs to check into
109
+ *
110
+ * @return string The executable path or default value
111
+ */
112
+ public function find ($ name , $ default = null , array $ extraDirs = array ())
113
+ {
114
+ return $ this ->findIn (
115
+ $ name ,
116
+ $ this ->path ($ extraDirs ),
117
+ $ default
118
+ );
87
119
}
88
120
}
0 commit comments