Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Path.php

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\Filesystem

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal