class LibraryDiscovery in System stream wrapper 8
Discovers available libraries in the filesystem.
Hierarchy
- class \Drupal\Core\Extension\ExtensionDiscovery
- class \Drupal\system_stream_wrapper\Extension\LibraryDiscovery
Expanded class hierarchy of LibraryDiscovery
1 file declares its use of LibraryDiscovery
- LibraryStream.php in src/
StreamWrapper/ LibraryStream.php
File
- src/
Extension/ LibraryDiscovery.php, line 11
Namespace
Drupal\system_stream_wrapper\ExtensionView source
class LibraryDiscovery extends ExtensionDiscovery {
/**
* The directory libraries are registered in.
*/
const LIBRARIES_DIRECTORY = 'libraries';
/**
* The type of this extension.
*/
const EXTENSION_TYPE = 'library';
/**
* We don't want to affect the static cache of the core ExtensionDiscovery
* class, so we keep one separately.
*
* @var array
*/
protected static $files = array();
/**
* {@inheritdoc}
*/
protected function scanDirectory($dir, $include_tests) {
$files = array();
// In order to scan top-level directories, absolute directory paths have to
// be used (which also improves performance, since any configured PHP
// include_paths will not be consulted). Retain the relative originating
// directory being scanned, so relative paths can be reconstructed below
// (all paths are expected to be relative to $this->root).
$dir_prefix = ($dir == '' ? '' : "{$dir}/") . self::LIBRARIES_DIRECTORY . '/';
$absolute_dir = $dir == '' ? $this->root : $this->root . "/{$dir}";
$absolute_dir .= '/' . self::LIBRARIES_DIRECTORY;
if (!is_dir($absolute_dir)) {
return $files;
}
// Use Unix paths regardless of platform, skip dot directories, follow
// symlinks (to allow extensions to be linked from elsewhere), and return
// the RecursiveDirectoryIterator instance to have access to getSubPath(),
// since SplFileInfo does not support relative paths.
$flags = \FilesystemIterator::UNIX_PATHS;
$flags |= \FilesystemIterator::SKIP_DOTS;
$flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
$flags |= \FilesystemIterator::CURRENT_AS_SELF;
$directory_iterator = new \RecursiveDirectoryIterator($absolute_dir, $flags);
/**
* @var string $key
* @var \RecursiveDirectoryIterator $fileinfo
*/
foreach ($directory_iterator as $key => $fileinfo) {
if ($this->fileCache && ($cached_extension = $this->fileCache
->get($fileinfo
->getPathname()))) {
$files[$cached_extension
->getType()][$key] = $cached_extension;
continue;
}
if (!$fileinfo
->isDir()) {
continue;
}
$type = self::EXTENSION_TYPE;
$name = $fileinfo
->getBasename();
$pathname = $dir_prefix . $fileinfo
->getSubPathname();
$extension = new Extension($this->root, $type, $pathname);
// Track the originating directory for sorting purposes.
$extension->subpath = self::LIBRARIES_DIRECTORY . '/' . $fileinfo
->getFilename();
$extension->origin = $dir;
$files[$type][$key] = $extension;
if ($this->fileCache) {
$this->fileCache
->set($fileinfo
->getPathname(), $extension);
}
}
return $files;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ExtensionDiscovery:: |
protected | property | The file cache object. | |
ExtensionDiscovery:: |
protected | property | List of installation profile directories to additionally scan. | |
ExtensionDiscovery:: |
protected | property | The app root for the current operation. | |
ExtensionDiscovery:: |
protected | property | The site path. | |
ExtensionDiscovery:: |
protected | function | Filters out extensions not belonging to the scanned installation profiles. | |
ExtensionDiscovery:: |
public | function | Gets the installation profile directories to be scanned. | |
ExtensionDiscovery:: |
constant | Origin directory weight: Core. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Parent site directory of a test site environment. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Installation profile. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Site-wide directory. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: Site-specific directory. | ||
ExtensionDiscovery:: |
constant | Origin directory weight: sites/all. | ||
ExtensionDiscovery:: |
constant | Regular expression to match PHP function names. | ||
ExtensionDiscovery:: |
protected | function | Processes the filtered and sorted list of extensions. | |
ExtensionDiscovery:: |
public | function | Discovers available extensions of a given type. | |
ExtensionDiscovery:: |
public | function | Sets explicit profile directories to scan. | |
ExtensionDiscovery:: |
public | function | Sets installation profile directories based on current site settings. | |
ExtensionDiscovery:: |
protected | function | Sorts the discovered extensions. | |
ExtensionDiscovery:: |
public | function | Constructs a new ExtensionDiscovery object. | |
LibraryDiscovery:: |
protected static | property |
We don't want to affect the static cache of the core ExtensionDiscovery
class, so we keep one separately. Overrides ExtensionDiscovery:: |
|
LibraryDiscovery:: |
constant | The type of this extension. | ||
LibraryDiscovery:: |
constant | The directory libraries are registered in. | ||
LibraryDiscovery:: |
protected | function |
Recursively scans a base directory for the extensions it contains. Overrides ExtensionDiscovery:: |