function LocalStream::getLocalPath
Same name in other branches
- 9 core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::getLocalPath()
- 8.9.x core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::getLocalPath()
- 10 core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::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.
10 calls to LocalStream::getLocalPath()
- LocalStream::dir_opendir in core/
lib/ Drupal/ Core/ StreamWrapper/ LocalStream.php - Open directory handle.
- LocalStream::mkdir in core/
lib/ Drupal/ Core/ StreamWrapper/ LocalStream.php - Create a directory.
- LocalStream::realpath in core/
lib/ Drupal/ Core/ StreamWrapper/ LocalStream.php - Returns canonical, absolute path of the resource.
- LocalStream::rename in core/
lib/ Drupal/ Core/ StreamWrapper/ LocalStream.php - Renames a file or directory.
- LocalStream::rmdir in core/
lib/ Drupal/ Core/ StreamWrapper/ LocalStream.php - Removes a directory.
1 method overrides LocalStream::getLocalPath()
- PublicStream::getLocalPath in core/
lib/ Drupal/ Core/ StreamWrapper/ PublicStream.php - Returns the canonical absolute path of the URI, if possible.
File
-
core/
lib/ Drupal/ Core/ StreamWrapper/ LocalStream.php, line 118
Class
- LocalStream
- Defines a Drupal stream wrapper base class for local files.
Namespace
Drupal\Core\StreamWrapperCode
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 (str_starts_with($path, 'vfs://')) {
return $path;
}
$realpath = realpath($path);
if (!$realpath) {
// This file does not yet exist.
$realpath = realpath(dirname($path)) . '/' . \Drupal::service('file_system')->basename($path);
}
$directory = realpath($this->getDirectoryPath());
if (!$realpath || !$directory || !str_starts_with($realpath, $directory)) {
return FALSE;
}
return $realpath;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.