public static function detectCmdLocation(string $cmd, string $path = '', array $optionalLocations = []) : string
    {
        $detectionSteps = [
            function($cmd) use ($path) {
                if (!empty($path)) {
                    return self::detectCmdLocationInPath($cmd, $path);
                }
                return '';
            },
            function($cmd) {
                return self::detectCmdLocationWithWhich($cmd);
            },
            function($cmd) {
                $paths = explode(PATH_SEPARATOR, self::getEnvPath());
                return self::detectCmdLocationInPaths($cmd, $paths);
            },
            function($cmd) use ($optionalLocations) {
                return self::detectCmdLocationInPaths($cmd, $optionalLocations);
            }
        ];

        foreach ($detectionSteps as $step) {
            $bin = $step($cmd);
            if (!empty($bin)) {
                return $bin;
            }
        }

        throw new RuntimeException(sprintf('\'%s\' was nowhere to be found please specify the correct path', $cmd));
    }
public static function detectCmdLocation(string $cmd, string $path = '', array $optionalLocations = []) : string
    {
        $detectionSteps = [
            function($cmd) use ($path) {
                if (!empty($path)) {
                    return self::detectCmdLocationInPath($cmd, $path);
                }
                return '';
            },
            function($cmd) {
                return self::detectCmdLocationWithWhich($cmd);
            },
            function($cmd) {
                $paths = explode(PATH_SEPARATOR, self::getEnvPath());
                return self::detectCmdLocationInPaths($cmd, $paths);
            },
            function($cmd) use ($optionalLocations) {
                return self::detectCmdLocationInPaths($cmd, $optionalLocations);
            }
        ];

        foreach ($detectionSteps as $step) {
            $bin = $step($cmd);
            if (!empty($bin)) {
                return $bin;
            }
        }

        throw new RuntimeException(sprintf('\'%s\' was nowhere to be found please specify the correct path', $cmd));
    }
public static function detectCmdLocation ( string $ cmd , string $ path = '' , array $ optionalLocations = [ ] ) : string { $ detectionSteps = [ function ( $ cmd ) use ( $ path ) { if ( ! empty ( $ path ) ) { return self :: detectCmdLocationInPath ( $ cmd , $ path ) ; } return '' ; } , function ( $ cmd ) { return self :: detectCmdLocationWithWhich ( $ cmd ) ; } , function ( $ cmd ) { $ paths = explode ( PATH_SEPARATOR , self :: getEnvPath ( ) ) ; return self :: detectCmdLocationInPaths ( $ cmd , $ paths ) ; } , function ( $ cmd ) use ( $ optionalLocations ) { return self :: detectCmdLocationInPaths ( $ cmd , $ optionalLocations ) ; } ] ; foreach ( $ detectionSteps as $ step ) { $ bin = $ step ( $ cmd ) ; if ( ! empty ( $ bin ) ) { return $ bin ; } } throw new RuntimeException ( sprintf ( '\'%s\' was nowhere to be found please specify the correct path' , $ cmd ) ) ; }
Detect a given command's location.

@param  string $cmd               The command to locate
@param  string $path              Directory where the command should be
@param  array  $optionalLocations Some fallback locations where to search for the command
@return string                    Absolute path to detected command including command itself
@throws \RuntimeException
Detect a given command s location .