You are here

protected function LocalStreamTrait::getTarget in System stream wrapper 8

Returns the local writable target of the resource within the stream.

This function should be used in place of calls to realpath() or similar functions when attempting to determine the location of a file. While functions like realpath() may return the location of a read-only file, this method may return a URI or path suitable for writing that is completely separate from the URI used for reading.

Parameters

string $uri: Optional URI.

Return value

string Returns a string representing a location suitable for writing of a file.

Throws

\InvalidArgumentException If a malformed $uri parameter is passed in.

4 calls to LocalStreamTrait::getTarget()
ExtensionStreamBase::getTarget in src/StreamWrapper/ExtensionStreamBase.php
Returns the local writable target of the resource within the stream.
LocalStream::getLocalPath in src/StreamWrapper/LocalStream.php
Returns the canonical absolute path of the URI, if possible.
LocalStream::mkdir in src/StreamWrapper/LocalStream.php
Support for mkdir().
LocalStreamTrait::dirname in src/StreamWrapper/LocalStreamTrait.php
Gets the name of the directory from a given path.
1 method overrides LocalStreamTrait::getTarget()
ExtensionStreamBase::getTarget in src/StreamWrapper/ExtensionStreamBase.php
Returns the local writable target of the resource within the stream.

File

src/StreamWrapper/LocalStreamTrait.php, line 59
Contains \Drupal\Core\StreamWrapper\LocalStreamTrait.

Class

LocalStreamTrait
Provides common methods for local streams.

Namespace

Drupal\system_stream_wrapper\StreamWrapper

Code

protected function getTarget($uri = NULL) {
  if (!isset($uri)) {
    $uri = $this->uri;
  }
  $uri_parts = explode('://', $uri, 2);
  if (count($uri_parts) === 1) {

    // The delimiter ('://') was not found in $uri, malformed $uri passed.
    throw new \InvalidArgumentException("Malformed uri parameter passed: {$uri}");
  }

  // Remove erroneous leading or trailing forward-slashes and backslashes.
  return trim($uri_parts[1], '\\/');
}