function Path::hasExtension
Returns whether the path has an (or the specified) extension.
Parameters
string $path the path string:
string|string[]|null $extensions 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)
bool $ignoreCase whether to ignore case-sensitivity:
File
-
vendor/
symfony/ filesystem/ Path.php, line 302
Class
- Path
- Contains utility methods for handling path strings.
Namespace
Symfony\Component\FilesystemCode
public static function hasExtension(string $path, $extensions = null, bool $ignoreCase = false) : bool {
if ('' === $path) {
return false;
}
$actualExtension = self::getExtension($path, $ignoreCase);
// Only check if path has any extension
if ([] === $extensions || null === $extensions) {
return '' !== $actualExtension;
}
if (\is_string($extensions)) {
$extensions = [
$extensions,
];
}
foreach ($extensions as $key => $extension) {
if ($ignoreCase) {
$extension = self::toLower($extension);
}
// remove leading '.' in extensions array
$extensions[$key] = ltrim($extension, '.');
}
return \in_array($actualExtension, $extensions, true);
}