You are here

public function FileSystem::dirname in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::dirname()

Gets the name of the directory from a given path.

PHP's dirname() does not properly pass streams, so this function fills that gap. It is backwards compatible with normal paths and will use PHP's dirname() as a fallback.

Compatibility: normal paths and stream wrappers.

Parameters

string $uri: A URI or path.

Return value

string A string containing the directory name.

Overrides FileSystemInterface::dirname

See also

dirname()

https://www.drupal.org/node/515192

2 calls to FileSystem::dirname()
FileSystem::getDestinationFilename in core/lib/Drupal/Core/File/FileSystem.php
Determines the destination path for a file.
FileSystem::prepareDestination in core/lib/Drupal/Core/File/FileSystem.php
Prepares the destination for a file copy or move operation.

File

core/lib/Drupal/Core/File/FileSystem.php, line 145

Class

FileSystem
Provides helpers to operate on files and stream wrappers.

Namespace

Drupal\Core\File

Code

public function dirname($uri) {
  $scheme = StreamWrapperManager::getScheme($uri);
  if ($this->streamWrapperManager
    ->isValidScheme($scheme)) {
    return $this->streamWrapperManager
      ->getViaScheme($scheme)
      ->dirname($uri);
  }
  else {
    return dirname($uri);
  }
}