LibrariesFinderPlugin.php in X Autoload 7.5
File
src/Libraries/LibrariesFinderPlugin.php
View source
<?php
namespace Drupal\xautoload\Libraries;
use Drupal\xautoload\ClassFinder\ExtendedClassFinderInterface;
use Drupal\xautoload\ClassFinder\InjectedApi\InjectedApiInterface;
use Drupal\xautoload\ClassFinder\Plugin\FinderPluginInterface;
use Drupal\xautoload\DrupalSystem\DrupalSystemInterface;
use Drupal\xautoload\Phases\PhaseObserverInterface;
class LibrariesFinderPlugin implements FinderPluginInterface {
private $finder;
private $system;
function __construct(ExtendedClassFinderInterface $finder, DrupalSystemInterface $system) {
$this->finder = $finder;
$this->system = $system;
}
function findFile($api, $logical_base_path, $relative_path) {
$backtrace = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace(FALSE);
foreach ($backtrace as $call) {
if ('libraries_info' === $call['function']) {
return FALSE;
}
}
$this->finder
->getNamespaceMap()
->unregisterDeepPath('', '');
$this->finder
->getPrefixMap()
->unregisterDeepPath('', '');
$this
->registerAllLibraries();
return $this->finder
->apiFindFile($api, $api
->getClass());
}
private function registerAllLibraries() {
$adapter = \xautoload_InjectedAPI_hookXautoload::create($this->finder, '');
foreach ($info = $this
->getLibrariesXautoloadInfo() as $name => $pathAndCallback) {
list($path, $callback) = $pathAndCallback;
if (!is_callable($callback)) {
continue;
}
if (!is_dir($path)) {
continue;
}
$adapter
->setExtensionDir($path);
call_user_func($callback, $adapter, $path);
}
}
private function getLibrariesXautoloadInfo() {
$cached = $this->system
->cacheGet(XAUTOLOAD_CACHENAME_LIBRARIES_INFO);
if (FALSE !== $cached) {
return $cached->data;
}
$info = $this
->buildLibrariesXautoloadInfo();
$this->system
->cacheSet(XAUTOLOAD_CACHENAME_LIBRARIES_INFO, $info);
return $info;
}
private function buildLibrariesXautoloadInfo() {
$all = array();
foreach ($this->system
->getLibrariesInfo() as $name => $info) {
if (!isset($info['xautoload'])) {
continue;
}
$callback = $info['xautoload'];
if (!is_callable($callback)) {
continue;
}
$path = isset($info['library path']) ? $info['library path'] : $this->system
->librariesGetPath($name);
if (FALSE === $path) {
continue;
}
$all[$name] = array(
$path,
$callback,
);
}
return $all;
}
}