本文整理汇总了PHP中Composer\Autoload\ClassLoader::addPsr4方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::addPsr4方法的具体用法?PHP ClassLoader::addPsr4怎么用?PHP ClassLoader::addPsr4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Autoload\ClassLoader
的用法示例。
在下文中一共展示了ClassLoader::addPsr4方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerTestNamespaces
/**
* 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;
}
示例2: registerTestNamespaces
/**
* 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;
}
示例3: setUpBeforeClass
public static function setUpBeforeClass()
{
$classLoader = new ClassLoader();
$classLoader->addPsr4('App\\', __DIR__ . '/Fixtures/src/App');
$classLoader->addPsr4('Test\\', __DIR__ . '/Fixtures/src/Test');
$classLoader->register();
}
示例4: load
/**
* {@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;
}
示例5: setUp
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();
}
示例6: load
/**
* 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()));
}
}
示例7: autoloadPlugin
/**
* 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));
}
}
示例8: addPsr4
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;
}
示例9: registerNamespace
/**
* 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;
}
示例10: register
/**
* 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'));
}
示例11: getLoader
/**
* {@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');
}
示例12: __construct
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();
}
示例13: testLoadClass
/**
* 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}'");
}
示例14: registerLoader
/**
* 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;
}
示例15: __construct
/** {@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();
}