/** * Registers test namespaces of all available extensions. * * @return array * An associative array whose keys are PSR-4 namespace prefixes and whose * values are directory names. */ public function registerTestNamespaces() { if (isset($this->testNamespaces)) { return $this->testNamespaces; } $this->testNamespaces = array(); $existing = $this->classLoader->getPrefixesPsr4(); // Add PHPUnit test namespace of Drupal core. $this->testNamespaces['Drupal\\Tests\\'] = [DRUPAL_ROOT . '/core/tests/Drupal/Tests']; $this->availableExtensions = array(); foreach ($this->getExtensions() as $name => $extension) { $this->availableExtensions[$extension->getType()][$name] = $name; $base_namespace = "Drupal\\{$name}\\"; $base_path = DRUPAL_ROOT . '/' . $extension->getPath(); // Add namespace of disabled/uninstalled extensions. if (!isset($existing[$base_namespace])) { $this->classLoader->addPsr4($base_namespace, "{$base_path}/src"); } // Add Simpletest test namespace. $this->testNamespaces[$base_namespace . 'Tests\\'][] = "{$base_path}/src/Tests"; // Add PHPUnit test namespace. // @todo Move PHPUnit namespace of extensions into Drupal\Tests\$name. // @see https://www.drupal.org/node/2260121 $this->testNamespaces[$base_namespace . 'Tests\\'][] = "{$base_path}/tests/src"; } foreach ($this->testNamespaces as $prefix => $paths) { $this->classLoader->addPsr4($prefix, $paths); } return $this->testNamespaces; }
/** * Registers test namespaces of all available extensions. * * @return array * An associative array whose keys are PSR-4 namespace prefixes and whose * values are directory names. */ public function registerTestNamespaces() { if (isset($this->testNamespaces)) { return $this->testNamespaces; } $this->testNamespaces = array(); $existing = $this->classLoader->getPrefixesPsr4(); // Add PHPUnit test namespaces of Drupal core. $this->testNamespaces['Drupal\\Tests\\'] = [DRUPAL_ROOT . '/core/tests/Drupal/Tests']; $this->testNamespaces['Drupal\\FunctionalTests\\'] = [DRUPAL_ROOT . '/core/tests/Drupal/FunctionalTests']; $this->availableExtensions = array(); foreach ($this->getExtensions() as $name => $extension) { $this->availableExtensions[$extension->getType()][$name] = $name; $base_path = DRUPAL_ROOT . '/' . $extension->getPath(); // Add namespace of disabled/uninstalled extensions. if (!isset($existing["Drupal\\{$name}\\"])) { $this->classLoader->addPsr4("Drupal\\{$name}\\", "{$base_path}/src"); } // Add Simpletest test namespace. $this->testNamespaces["Drupal\\{$name}\\Tests\\"][] = "{$base_path}/src/Tests"; // Add PHPUnit test namespaces. $this->testNamespaces["Drupal\\Tests\\{$name}\\Unit\\"][] = "{$base_path}/tests/src/Unit"; $this->testNamespaces["Drupal\\Tests\\{$name}\\Functional\\"][] = "{$base_path}/tests/src/Functional"; } foreach ($this->testNamespaces as $prefix => $paths) { $this->classLoader->addPsr4($prefix, $paths); } return $this->testNamespaces; }
public static function setUpBeforeClass() { $classLoader = new ClassLoader(); $classLoader->addPsr4('App\\', __DIR__ . '/Fixtures/src/App'); $classLoader->addPsr4('Test\\', __DIR__ . '/Fixtures/src/Test'); $classLoader->register(); }
/** * {@inheritdoc} */ public function load($module) { if (isset($module['autoload'])) { foreach ($module['autoload'] as $namespace => $path) { $this->loader->addPsr4($namespace, $this->resolvePath($module, $path)); } } return $module; }
protected function setUp() { $filesystem = new Filesystem(); $filesystem->remove(__DIR__ . '/Fixtures/tmp'); $filesystem->mirror(__DIR__ . '/Fixtures/template', __DIR__ . '/Fixtures/tmp'); $loader = new ClassLoader(); $loader->addPsr4('Fixtures\\Maba\\Bundle\\', __DIR__ . '/Fixtures/tmp/src'); $loader->addPsr4('Fixtures\\Maba\\', __DIR__ . '/Fixtures/tmp/app'); $loader->register(true); static::bootKernel(); }
/** * Load bundle * * @param BundleInterface $bundle * * @throws MissingBundleException */ public static function load(BundleInterface $bundle) { if (is_dir($bundle->getPath())) { self::$bundlesLoaded[$bundle->getName()] = ['namespace' => $bundle->getNamespace(), 'path' => $bundle->getPath()]; if (!self::$classLoader) { self::$classLoader = new ClassLoader(); } self::$classLoader->addPsr4($bundle->getNamespace(), $bundle->getPath()); self::$classLoader->register(); } else { throw new MissingBundleException(sprintf('Bundle "%s" could not be found.', $bundle->getName())); } }
/** * Registers a plugin's PSR-4 path with the class loader. * * @param string $filename * @param array $info */ private function autoloadPlugin($filename, array $info) { if (!empty($info['Namespace']) && !empty($info['Autoload'])) { $path = WPMU_PLUGIN_DIR . '/' . dirname($filename) . '/' . trim($info['Autoload'], '/\\'); $this->autoloader->addPsr4($info['Namespace'], array($path)); } }
public function addPsr4($prefix, $paths, $prepend = false) { $this->mainLoader->addPsr4($prefix, $paths, $prepend); $this->prefixesPsr4 = array_merge($this->prefixesPsr4, $this->mainLoader->getPrefixesPsr4()); $this->fallbackDirsPsr4 = array_merge($this->fallbackDirsPsr4, $this->mainLoader->getFallbackDirsPsr4()); return $this; }
/** * To register a location to find some classes of a namespace. * A namespace can has several locations. * * @api * * @param string $namespace * @param string $path * * @return LoaderInterface */ public function registerNamespace(string $namespace, string $path) : LoaderInterface { if ('\\' !== $namespace[\strlen($namespace) - 1]) { $namespace = \ltrim($namespace, '\\') . '\\'; } $this->composerInstance->addPsr4($namespace, $path); return $this; }
/** * Register's the annotation driver for the passed configuration. * * @param \AppserverIo\Appserver\Core\Api\Node\AnnotationRegistryNodeInterface $annotationRegistry The configuration node * * @return void */ public function register(AnnotationRegistryNodeInterface $annotationRegistry) { // initialize the composer class loader $classLoader = new ClassLoader(); $classLoader->addPsr4($annotationRegistry->getNamespace(), $annotationRegistry->getDirectoriesAsArray()); // register the class loader to load annotations AnnotationRegistry::registerLoader(array($classLoader, 'loadClass')); }
/** * {@inheritDoc} */ public function getLoader() { $loader = new ClassLoader(); foreach ($this->information as $prefix => $paths) { $loader->addPsr4($prefix, array_map(array($this, 'prependPathWithBaseDir'), (array) $paths)); } return array($loader, 'loadClass'); }
public function __construct() { parent::__construct('fancy_research_links'); $this->directory = WT_MODULES_DIR . $this->getName(); // register the namespace $loader = new ClassLoader(); $loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyResearchLinks\\', WT_MODULES_DIR . $this->getName() . '/app'); $loader->register(); }
/** * Tests regular PSR-0 and PSR-4 class loading. * * @dataProvider getLoadClassTests * * @param string $class The fully-qualified class name to test, without preceding namespace separator. */ public function testLoadClass($class) { $loader = new ClassLoader(); $loader->add('Namespaced\\', __DIR__ . '/Fixtures'); $loader->add('Pearlike_', __DIR__ . '/Fixtures'); $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures'); $loader->loadClass($class); $this->assertTrue(class_exists($class, false), "->loadClass() loads '{$class}'"); }
/** * Register classloader for extension * * @return \Composer\Autoload\ClassLoader */ protected function registerLoader() { $classpath = __DIR__; $nsprefix = __NAMESPACE__ . '\\'; $loader = new ClassLoader(); $loader->addPsr4($nsprefix, $classpath); $loader->register(); return $loader; }
/** {@inheritdoc} */ public function __construct() { parent::__construct(); $this->directory = WT_MODULES_DIR . $this->getName(); // register the namespaces $loader = new ClassLoader(); $loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyTreeviewPdf\\', $this->directory . '/app'); $loader->register(); }
public function __construct() { parent::__construct('modulename'); $this->directory = WT_MODULES_DIR . $this->getName(); $this->action = Filter::get('mod_action'); // register the namespaces $loader = new ClassLoader(); $loader->addPsr4('vendor\\WebtreesModules\\modulename\\', $this->directory); $loader->register(); }
/** {@inheritdoc} */ public function __construct() { parent::__construct('fancy_treeview'); $this->tree = $this->tree(); $this->tree_id = $this->tree->getTreeId(); $this->directory = WT_MODULES_DIR . $this->getName(); $this->action = Filter::get('mod_action'); // register the namespaces $loader = new ClassLoader(); $loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyTreeview\\', $this->directory . '/src'); $loader->register(); }
/** * @param Container $container * @param ClassLoader $classLoader */ public function init(Container $container, ClassLoader $classLoader) { foreach (self::$extensions as $extension) { if ($this->validate($extension)) { $classLoader->addPsr4($extension->getNamespace() . '\\', $extension->getPath()); $configuration = $this->getConfigurationFromExtension($extension); if ($configuration) { $container->configurations->add($configuration); } } } }
public function decorate(ClassLoader $classLoader) { $standards = $this->standardFinder->getStandards(); foreach ($standards as $stadardName => $standardRuleset) { if ($this->isDefaultStandard($stadardName)) { continue; } $standardNamespace = $this->detectStandardNamespaceFromStandardName($stadardName); $standardDir = dirname($standardRuleset); $classLoader->addPsr4($standardNamespace . '\\', $standardDir . DIRECTORY_SEPARATOR . $standardNamespace); } }
/** * @param \Jigoshop\Extensions\Extension $extension */ public function installExtension($extension) { $this->classLoader->addPsr4($extension->getNamespace() . '\\', $extension->getPath()); $configuration = $extension->getConfiguration(); if ($configuration && $configuration instanceof \Jigoshop\Container\Configurations\ConfigurationInterface) { $this->container->configurations->add($configuration); } $installer = $extension->getInstaller(); if ($installer && $installer instanceof \Jigoshop\Extensions\InstallerInterface) { $installer->init($this->container); $installer->install(); } }
/** * Adds autoloader prefixes from user's config */ protected function registerCustomAutoloaders() { if (isset($this->config['autoloaders']) && is_array($this->config['autoloaders'])) { foreach ($this->config['autoloaders'] as $prefix => $path) { $this->autoloader->add($prefix, $path); } } if (isset($this->config['autoloaders_psr4']) && is_array($this->config['autoloaders_psr4'])) { foreach ($this->config['autoloaders_psr4'] as $prefix => $path) { $this->autoloader->addPsr4($prefix, $path); } } }
/** * Check that the auto loading information is correct. * * @param array $information The autoload information. * * @param string $baseDir The base directory. * * @param string[] $messages The error messages. * * @return bool */ public function validateComposerAutoLoadingPsr4($information, $baseDir, &$messages) { $result = true; // Scan all directories mentioned and validate the class map against the entries. foreach ($information as $namespace => $path) { $subPath = str_replace('//', '/', $baseDir . '/' . $path); $classMap = $this->createClassMap($subPath, $namespace); $this->loader->addPsr4($namespace, $subPath); if (!$this->validateComposerAutoLoadingPsr4ClassMap($classMap, $subPath, $namespace, $messages)) { $result = false; } } return $result; }
/** * Load the addon. * * @param $path */ public function load($path) { if (file_exists($autoload = $path . '/vendor/autoload.php')) { include $autoload; return; } if (!file_exists($path . '/composer.json')) { return; } $composer = json_decode(file_get_contents($path . '/composer.json'), true); if (!array_key_exists('autoload', $composer)) { return; } foreach (array_get($composer['autoload'], 'psr-4', []) as $namespace => $autoload) { $this->loader->addPsr4($namespace, $path . '/' . $autoload, false); } foreach (array_get($composer['autoload'], 'psr-0', []) as $namespace => $autoload) { $this->loader->add($namespace, $path . '/' . $autoload, false); } foreach (array_get($composer['autoload'], 'files', []) as $file) { include $path . '/' . $file; } }
/** * Tests regular PSR-0 and PSR-4 class loading. * * @dataProvider getLoadClassTests * * @param string $class The fully-qualified class name to test, without preceding namespace separator. * @param bool $prependSeparator Whether to call ->loadClass() with a class name with preceding * namespace separator, as it happens in PHP 5.3.0 - 5.3.2. See https://bugs.php.net/50731 */ public function testLoadClass($class, $prependSeparator = FALSE) { $loader = new ClassLoader(); $loader->add('Namespaced\\', __DIR__ . '/Fixtures'); $loader->add('Pearlike_', __DIR__ . '/Fixtures'); $loader->addPsr4('ShinyVendor\\ShinyPackage\\', __DIR__ . '/Fixtures'); if ($prependSeparator) { $prepend = '\\'; $message = "->loadClass() loads '{$class}'."; } else { $prepend = ''; $message = "->loadClass() loads '\\{$class}', as required in PHP 5.3.0 - 5.3.2."; } $loader->loadClass($prepend . $class); $this->assertTrue(class_exists($class, false), $message); }
/** * Scan plugin folder and load plugins * * @access public */ public function scan() { if (file_exists(PLUGINS_DIR)) { $loader = new ClassLoader(); $loader->addPsr4('Kanboard\\Plugin\\', PLUGINS_DIR); $loader->register(); $dir = new DirectoryIterator(PLUGINS_DIR); foreach ($dir as $fileInfo) { if ($fileInfo->isDir() && substr($fileInfo->getFilename(), 0, 1) !== '.') { $pluginName = $fileInfo->getFilename(); $this->loadSchema($pluginName); $this->initializePlugin($this->loadPlugin($pluginName)); } } } }
public function testFactoryViewGeneration() { $app = $this->createApplication(); ProjectUtil::runCommand(self::$projectFolder, 'datamodel:generate', ['--configclass' => 'Blend\\Tests\\DataModelBuilder\\Command\\CustomizedModelConfig'], $app); $loader = new ClassLoader(); $loader->addPsr4("DALTest\\", self::$projectFolder . '/src/'); $loader->register(); try { $classRef = new \ReflectionClass('DALTest\\Database\\Common\\Factory\\SysSampleViewFactory'); $this->assertTrue($classRef->hasMethod('getBySecretKey')); $this->assertTrue($classRef->hasMethod('getManyByField1AndGenerateSeries')); $this->assertEquals(1, $classRef->getMethod('getBySecretKey')->getNumberOfParameters()); $this->assertEquals(2, $classRef->getMethod('getManyByField1AndGenerateSeries')->getNumberOfParameters()); } catch (\Exception $ex) { $this->fail($ex->getMessage()); } }
/** * Registers an autoloader based on an autoload map returned by parseAutoloads * * @param array $autoloads see parseAutoloads return value * @return ClassLoader */ public function createLoader(array $autoloads) { $loader = new ClassLoader(); if (isset($autoloads['psr-0'])) { foreach ($autoloads['psr-0'] as $namespace => $path) { $loader->add($namespace, $path); } } if (isset($autoloads['psr-4'])) { foreach ($autoloads['psr-4'] as $namespace => $path) { $loader->addPsr4($namespace, $path); } } return $loader; }
public function addPsr4Path(string $namespace, string $directory) { $this->classLoader->addPsr4($namespace, $directory); }
/** * Registers a list of namespaces with PSR-4 directories for class loading. * * @param array $namespaces * Array where each key is a namespace like 'Drupal\system', and each value * is either a PSR-4 base directory, or an array of PSR-4 base directories * associated with this namespace. */ protected function classLoaderAddMultiplePsr4(array $namespaces = array()) { foreach ($namespaces as $prefix => $paths) { if (is_array($paths)) { foreach ($paths as $key => $value) { $paths[$key] = $this->root . '/' . $value; } } elseif (is_string($paths)) { $paths = $this->root . '/' . $paths; } $this->classLoader->addPsr4($prefix . '\\', $paths); } }
*/ $paths['plugin.' . $vars['namespace']] = __DIR__ . DS; $paths['plugin.' . $vars['namespace'] . '.resources'] = __DIR__ . DS . 'resources' . DS; $paths['plugin.' . $vars['namespace'] . '.admin'] = __DIR__ . DS . 'resources' . DS . 'admin' . DS; themosis_set_paths($paths); /* * Setup plugin config files. */ container('config.finder')->addPaths([themosis_path('plugin.' . $vars['namespace'] . '.resources') . 'config' . DS]); /* * Autoloading. */ $loader = new ClassLoader(); $classes = container('config')->get($vars['config'] . '_loading'); foreach ($classes as $prefix => $path) { $loader->addPsr4($prefix, $path); } $loader->register(); /* * Register plugin public assets folder [dist directory]. */ container('asset.finder')->addPaths([plugins_url('dist', __FILE__) => themosis_path('plugin.' . $vars['namespace']) . 'dist']); /* * Register plugin views. */ container('view.finder')->addLocation(themosis_path('plugin.' . $vars['namespace'] . '.resources') . 'views'); /* * Service providers. */ $providers = container('config')->get($vars['config'] . '_providers'); foreach ($providers as $provider) {