You are here

public static function StreamWrapperManager::getTarget in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php \Drupal\Core\StreamWrapper\StreamWrapperManager::getTarget()
  2. 10 core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php \Drupal\Core\StreamWrapper\StreamWrapperManager::getTarget()

Returns the part of a URI after the schema.

Parameters

string $uri: A stream, referenced as "scheme://target" or "data:target".

Return value

string|bool A string containing the target (path), or FALSE if none. For example, the URI "public://sample/test.txt" would return "sample/test.txt".

Overrides StreamWrapperManagerInterface::getTarget

See also

\Drupal\Core\StreamWrapper\StreamWrapperManagerInterface::getScheme()

11 calls to StreamWrapperManager::getTarget()
config_file_download in core/modules/config/config.module
Implements hook_file_download().
hook_file_download in core/lib/Drupal/Core/File/file.api.php
Control access to private file downloads and specify HTTP headers.
ImageStyle::buildUri in core/modules/image/src/Entity/ImageStyle.php
Returns the URI of this image when using this style.
ImageStyleDownloadController::deliver in core/modules/image/src/Controller/ImageStyleDownloadController.php
Generates a derivative, given a style and image path.
ImageStylesPathAndUrlTest::doImageStyleUrlAndPathTests in core/modules/image/tests/src/Functional/ImageStylesPathAndUrlTest.php
Tests building an image style URL.

... See full list

File

core/lib/Drupal/Core/StreamWrapper/StreamWrapperManager.php, line 214

Class

StreamWrapperManager
Provides a StreamWrapper manager.

Namespace

Drupal\Core\StreamWrapper

Code

public static function getTarget($uri) {

  // Remove the scheme from the URI and remove erroneous leading or trailing,
  // forward-slashes and backslashes.
  $target = trim(preg_replace('/^[\\w\\-]+:\\/\\/|^data:/', '', $uri), '\\/');

  // If nothing was replaced, the URI doesn't have a valid scheme.
  return $target !== $uri ? $target : FALSE;
}