LibraryDiscovery.php in System stream wrapper 8
File
src/Extension/LibraryDiscovery.php
View source
<?php
namespace Drupal\system_stream_wrapper\Extension;
use Drupal\Core\Extension\Extension;
use Drupal\Core\Extension\ExtensionDiscovery;
class LibraryDiscovery extends ExtensionDiscovery {
const LIBRARIES_DIRECTORY = 'libraries';
const EXTENSION_TYPE = 'library';
protected static $files = array();
protected function scanDirectory($dir, $include_tests) {
$files = array();
$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;
}
$flags = \FilesystemIterator::UNIX_PATHS;
$flags |= \FilesystemIterator::SKIP_DOTS;
$flags |= \FilesystemIterator::FOLLOW_SYMLINKS;
$flags |= \FilesystemIterator::CURRENT_AS_SELF;
$directory_iterator = new \RecursiveDirectoryIterator($absolute_dir, $flags);
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);
$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;
}
}