Returns whether the path has an extension.
public static hasExtension ( string $path, string | array | null $extensions = null, boolean $ignoreCase = false ) : boolean | ||
$path | string | The path string. |
$extensions | string | array | null | If null or not provided, checks if an extension exists, otherwise checks for the specified extension or array of extensions (with or without leading dot). |
$ignoreCase | boolean | Whether to ignore case-sensitivity (requires mbstring extension for correct multi-byte character handling in the extension). |
Результат | boolean | Returns `true` if the path has an (or the specified) extension and `false` otherwise. |
/** * Creates a new runner. * * @param string|null $binDir The path to Composer's "bin-dir". */ public function __construct($binDir = null) { $phpFinder = new PhpExecutableFinder(); if (!($php = $phpFinder->find())) { throw new RuntimeException('The "php" command could not be found.'); } $puliFinder = new ExecutableFinder(); // Search: // 1. in the current working directory // 2. in Composer's "bin-dir" // 3. in the system path $searchPath = array_merge(array(getcwd()), (array) $binDir); // Search "puli.phar" in the PATH and the current directory if (!($puli = $puliFinder->find('puli.phar', null, $searchPath))) { // Search "puli" in the PATH and Composer's "bin-dir" if (!($puli = $puliFinder->find('puli', null, $searchPath))) { throw new RuntimeException('The "puli"/"puli.phar" command could not be found.'); } } if (Path::hasExtension($puli, '.bat', true)) { $this->puli = $puli; } else { $this->puli = $php . ' ' . $puli; } }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The extensions must be strings. Got: stdClass */ public function testHasExtensionFailsIfInvalidExtension() { Path::hasExtension('/style.css', (object) array()); }