/** * Implements hook_xautoload() * * Register additional classes, namespaces, autoload patterns, that are not * already registered by default. * * @param \Drupal\xautoload\Adapter\LocalDirectoryAdapter $adapter * An adapter object that can register stuff into the class loader. */ function hook_xautoload($adapter) { // Register a namespace with PSR-0. $adapter->add('Acme\\GardenKit\\', 'shrubbery/lib'); // Register a namespace with PSR-4. $adapter->absolute()->addPsr4('Acme\\ShrubGardens\\', '/home/karnouffle/php/shrub-gardens/src'); // Scan sites/all/vendor/composer for Composer-generated autoload files, e.g. // 'sites/all/vendor/composer/autoload_namespaces.php', etc. $adapter->absolute()->composerDir('sites/all/vendor/composer'); }
function testComposerJson() { $finder = new ClassFinder(); $masterAdapter = new ClassFinderAdapter($finder, new ClassMapGenerator()); foreach (array(dirname(__DIR__) . '/fixtures/.libraries/ComposerTestLib' => array('ComposerTestLib\\Foo', 'ComposerTestLib\\Other\\Foo'), dirname(__DIR__) . '/fixtures/.libraries/ComposerTargetDirTestLib' => array('Acme\\ComposerTargetDirTestLib\\Foo')) as $dir => $classes) { $localDirectoryAdapter = new LocalDirectoryAdapter($masterAdapter, $dir); $localDirectoryAdapter->composerJson('composer.json'); foreach ($classes as $class) { $this->assertFalse(class_exists($class, FALSE), "Class {$class} not defined yet."); $finder->loadClass($class); $this->assertTrue(class_exists($class, FALSE), "Class {$class} is defined."); } } }
/** * @param ClassFinderAdapter $adapter * The class finder object. * @param string $localDirectory */ function __construct($adapter, $localDirectory) { parent::__construct($adapter, $localDirectory); $this->finder = $adapter->getFinder(); }