X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flibraries%2Fsrc%2FPlugin%2Flibraries%2FLocator%2FUriLocator.php;fp=web%2Fmodules%2Fcontrib%2Flibraries%2Fsrc%2FPlugin%2Flibraries%2FLocator%2FUriLocator.php;h=348be0c247c8aec40cbba68e28c132437b9c0938;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/libraries/src/Plugin/libraries/Locator/UriLocator.php b/web/modules/contrib/libraries/src/Plugin/libraries/Locator/UriLocator.php new file mode 100644 index 000000000..348be0c24 --- /dev/null +++ b/web/modules/contrib/libraries/src/Plugin/libraries/Locator/UriLocator.php @@ -0,0 +1,89 @@ +streamWrapperManager = $stream_wrapper_manager; + $this->uri = (string) $uri; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + if (!isset($configuration['uri'])) { + throw new MissingPluginConfigurationException($plugin_id, $plugin_definition, $configuration, 'uri'); + } + return new static($container->get('stream_wrapper_manager'), $configuration['uri']); + } + + /** + * Locates a library. + * + * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library + * The library to locate. + * + * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate() + */ + 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(); + } + +}