public function UriLocator::locate in Libraries API 8.3
Locates a library.
Parameters
\Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library: The library to locate.
Overrides LocatorInterface::locate
See also
\Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
File
- src/
Plugin/ libraries/ Locator/ UriLocator.php, line 73
Class
- UriLocator
- Provides a locator utilizing a URI.
Namespace
Drupal\libraries\Plugin\libraries\LocatorCode
public function locate(LocalLibraryInterface $library) {
/** @var \Drupal\Core\StreamWrapper\LocalStream $stream_wrapper */
$stream_wrapper = $this->streamWrapperManager
->getViaUri($this->uri);
assert($stream_wrapper instanceof \Drupal\Core\StreamWrapper\LocalStream);
// Calling LocalStream::getDirectoryPath() explicitly avoids the realpath()
// usage in LocalStream::getLocalPath(), which breaks if Libraries API is
// symbolically linked into the Drupal installation.
list($scheme, $target) = explode('://', $this->uri, 2);
$base_path = str_replace('//', '/', $stream_wrapper
->getDirectoryPath() . '/' . $target . '/' . $library
->getId());
if (is_dir($base_path) && is_readable($base_path)) {
$library
->setLocalPath($base_path);
return;
}
$library
->setUninstalled();
}