Skip to content

Instantly share code, notes, and snippets.

@code-poel
Last active August 29, 2015 14:08
Show Gist options
  • Save code-poel/afa748304902ec46cdc3 to your computer and use it in GitHub Desktop.
Save code-poel/afa748304902ec46cdc3 to your computer and use it in GitHub Desktop.
ExecutableFinder
<?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