You are here

protected function VideoRemoteStreamWrapper::getLocalPath in Video 8

Same name and namespace in other branches
  1. 8.2 src/StreamWrapper/VideoRemoteStreamWrapper.php \Drupal\video\StreamWrapper\VideoRemoteStreamWrapper::getLocalPath()

Returns the canonical absolute path of the URI, if possible.

Parameters

string $uri: (optional) The stream wrapper URI to be converted to a canonical absolute path. This may point to a directory or another type of file.

Return value

string|bool If $uri is not set, returns the canonical absolute path of the URI previously set by the Drupal\Core\StreamWrapper\StreamWrapperInterface::setUri() function. If $uri is set and valid for this class, returns its canonical absolute path, as determined by the realpath() function. If $uri is set but not valid, returns FALSE.

3 calls to VideoRemoteStreamWrapper::getLocalPath()
VideoRemoteStreamWrapper::dir_opendir in src/StreamWrapper/VideoRemoteStreamWrapper.php
Support for opendir().
VideoRemoteStreamWrapper::realpath in src/StreamWrapper/VideoRemoteStreamWrapper.php
Returns canonical, absolute path of the resource.
VideoRemoteStreamWrapper::url_stat in src/StreamWrapper/VideoRemoteStreamWrapper.php
Support for stat().

File

src/StreamWrapper/VideoRemoteStreamWrapper.php, line 107

Class

VideoRemoteStreamWrapper
Defines a video read only stream wrapper class.

Namespace

Drupal\video\StreamWrapper

Code

protected function getLocalPath($uri = NULL) {
  if (!isset($uri)) {
    $uri = $this->uri;
  }
  $path = $this
    ->getDirectoryPath() . '/' . $this
    ->getTarget($uri);

  // In PHPUnit tests, the base path for local streams may be a virtual
  // filesystem stream wrapper URI, in which case this local stream acts like
  // a proxy. realpath() is not supported by vfsStream, because a virtual
  // file system does not have a real filepath.
  if (strpos($path, 'vfs://') === 0) {
    return $path;
  }
  $realpath = realpath($path);
  if (!$realpath) {

    // This file does not yet exist.
    $realpath = realpath(dirname($path)) . '/' . drupal_basename($path);
  }
  $directory = realpath($this
    ->getDirectoryPath());
  if (!$realpath || !$directory || strpos($realpath, $directory) !== 0) {
    return FALSE;
  }
  return $realpath;
}