Last active
August 29, 2015 14:08
-
-
Save code-poel/afa748304902ec46cdc3 to your computer and use it in GitHub Desktop.
ExecutableFinder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function find($name, $default = null, array $extraDirs = array()) | |
{ | |
if (ini_get('open_basedir')) { | |
// ... | |
} else { | |
$dirs = array_merge( | |
explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')), | |
$extraDirs | |
); | |
} | |
$suffixes = array(''); | |
// ... | |
foreach ($suffixes as $suffix) { | |
foreach ($dirs as $dir) { | |
if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && (defined('PHP_WINDOWS_VERSION_BUILD') || is_executable($file))) { | |
return $file; | |
} | |
} | |
} | |
return $default; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment