/** * Constructs an wrapper for the composer loader * * @param ClassLoader $original Instance of current loader * @param AspectContainer $container Instance of the container * @param array $options Configuration options */ public function __construct(ClassLoader $original, AspectContainer $container, array $options = []) { $this->options = $options; $this->original = $original; $prefixes = $original->getPrefixes(); $excludePaths = $options['excludePaths']; // Let's exclude core dependencies from that list $excludePaths[] = $prefixes['Dissect'][0]; $excludePaths[] = substr($prefixes['Doctrine\\Common\\Annotations\\'][0], 0, -16); $fileEnumerator = new Enumerator($options['appDir'], $options['includePaths'], $excludePaths); $this->fileEnumerator = $fileEnumerator; $this->cacheState = $container->get('aspect.cache.path.manager')->queryCacheState(); }
public function __construct(ClassLoader $loader, Engine $engine = null) { if (!$engine) { $engine = new Engine(); } $this->engine = $engine; $this->add(null, $loader->getFallbackDirs()); $this->addPsr4(null, $loader->getFallbackDirsPsr4()); foreach ($loader->getPrefixes() as $prefix => $path) { $this->add($prefix, $path); } foreach ($loader->getPrefixesPsr4() as $prefix => $path) { $this->addPsr4($prefix, $path); } $this->setUseIncludePath($loader->getUseIncludePath()); }
/** * {@inheritdoc} */ public function getConfig() { // Initialize empty configuration. $config = ['psr-0' => [], 'psr-4' => [], 'class-location' => []]; // Find the tokenized paths. $psrs = array('psr-0' => $this->classLoader->getPrefixes(), 'psr-4' => $this->classLoader->getPrefixesPsr4()); // Get all the PSR-0 and PSR-0 and detect the ones that have Drupal tokens. foreach ($psrs as $psr_type => $namespaces) { $namespaces = $namespaces ?: []; foreach ($namespaces as $prefix => $paths) { $token_paths = array(); if (!is_array($paths)) { $paths = array($paths); } foreach ($paths as $path) { $token_resolver = $this->tokenFactory->factory($path); if (!$token_resolver->hasToken()) { continue; } $path = $token_resolver->trimPath(); $token_paths[] = $path; } // If there were paths, add them to the config. if (!empty($token_paths)) { $config[$psr_type][$prefix] = $token_paths; } } } // Get the drupal path configuration. $composer_config = json_decode(file_get_contents(static::COMPOSER_CONFIGURATION_NAME)); $config['class-location'] = array(); if (isset($composer_config->autoload->{'class-location'})) { $config['class-location'] = array_merge($config['class-location'], (array) $composer_config->autoload->{'class-location'}); } if (isset($composer_config->{'autoload-dev'}->{'class-location'})) { $config['class-location'] = array_merge($config['class-location'], (array) $composer_config->{'autoload-dev'}->{'class-location'}); } return $config; }
public static function add($namespace, $dir) { if (!in_array($namespace, self::$autoloader->getPrefixes())) { self::$autoloader->add($namespace, dirname($dir)); } }
/** * getPrefixes method should return empty array if ClassLoader does not have any psr-0 configuration */ public function testGetPrefixesWithNoPSR0Configuration() { $loader = new ClassLoader(); $this->assertEmpty($loader->getPrefixes()); }
public function add($prefix, $path, $prepend = false) { $this->mainLoader->add($prefix, $path, $prepend); $this->prefixes = array_merge($this->prefixes, $this->mainLoader->getPrefixes()); return $this; }