当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassLoader::addClassMap方法代码示例

本文整理汇总了PHP中Composer\Autoload\ClassLoader::addClassMap方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassLoader::addClassMap方法的具体用法?PHP ClassLoader::addClassMap怎么用?PHP ClassLoader::addClassMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Composer\Autoload\ClassLoader的用法示例。


在下文中一共展示了ClassLoader::addClassMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findFile

 /**
  * {@inheritdoc}
  * @codeCoverageIgnore
  */
 public function findFile($className)
 {
     /**
      * Composer remembers that files don't exist even after they are generated. This clears the entry for
      * $className so we can check the filesystem again for class existence.
      */
     if ($className[0] === '\\') {
         $className = substr($className, 1);
     }
     $this->autoloader->addClassMap([$className => null]);
     return $this->autoloader->findFile($className);
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:16,代码来源:ClassLoaderWrapper.php

示例2: init

 /**
  * Initializes Maam by generating new class files for all PHP files in the supplied sourcePath
  * and adds the new classmap to Composer's loader.
  *
  * @param ClassLoader $loader Composer's class loader.
  * @throws RuntimeException
  * @return void
  */
 public function init(ClassLoader $loader)
 {
     if ($this->getMode() === self::MODE_DEVELOPMENT) {
         $this->runGeneratorCommand();
     }
     $loader->addClassMap(require $this->getGenerationPath() . '/classmap.php');
 }
开发者ID:michaelmoussa,项目名称:maam,代码行数:15,代码来源:Maam.php

示例3: autoload

 /**
  * Autoloads all registered extension files with an instance of the app.
  *
  * @return void
  **/
 public function autoload($app)
 {
     $loader = new ClassLoader();
     $mapfile = $this->basefolder . '/vendor/composer/autoload_psr4.php';
     if (is_readable($mapfile)) {
         $map = (require $mapfile);
         foreach ($map as $namespace => $path) {
             $loader->setPsr4($namespace, $path);
         }
         $mapfile = $this->basefolder . '/vendor/composer/autoload_classmap.php';
         if (is_readable($mapfile)) {
             $map = (require $mapfile);
             $loader->addClassMap($map);
         }
         $loader->register();
     }
     $filepath = $this->basefolder . '/vendor/composer/autoload_files.php';
     if (is_readable($filepath)) {
         $files = (include $filepath);
         foreach ($files as $file) {
             try {
                 if (is_readable($file)) {
                     require $file;
                 }
             } catch (\Exception $e) {
                 $this->logInitFailure('Error importing extension class', $file, $e, Logger::ERROR);
             }
         }
     }
 }
开发者ID:ClemsB,项目名称:bolt,代码行数:35,代码来源:Extensions.php

示例4: getTestClasses

 /**
  * Discovers all available tests in all extensions.
  *
  * @param string $extension
  *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
  *
  * @return array
  *   An array of tests keyed by the first @group specified in each test's
  *   PHPDoc comment block, and then keyed by class names. For example:
  *   @code
  *     $groups['block'] => array(
  *       'Drupal\block\Tests\BlockTest' => array(
  *         'name' => 'Drupal\block\Tests\BlockTest',
  *         'description' => 'Tests block UI CRUD functionality.',
  *         'group' => 'block',
  *       ),
  *     );
  *   @endcode
  *
  * @throws \ReflectionException
  *   If a discovered test class does not match the expected class name.
  *
  * @todo Remove singular grouping; retain list of groups in 'group' key.
  * @see https://www.drupal.org/node/2296615
  * @todo Add base class groups 'Kernel' + 'Web', complementing 'PHPUnit'.
  */
 public function getTestClasses($extension = NULL)
 {
     if (!isset($extension)) {
         if ($this->cacheBackend && ($cache = $this->cacheBackend->get('simpletest:discovery:classes'))) {
             return $cache->data;
         }
     }
     $list = array();
     $classmap = $this->findAllClassFiles($extension);
     // Prevent expensive class loader lookups for each reflected test class by
     // registering the complete classmap of test classes to the class loader.
     // This also ensures that test classes are loaded from the discovered
     // pathnames; a namespace/classname mismatch will throw an exception.
     $this->classLoader->addClassMap($classmap);
     foreach ($classmap as $classname => $pathname) {
         try {
             $class = new \ReflectionClass($classname);
         } catch (\ReflectionException $e) {
             // Re-throw with expected pathname.
             $message = $e->getMessage() . " in expected {$pathname}";
             throw new \ReflectionException($message, $e->getCode(), $e);
         }
         // Skip interfaces, abstract classes, and traits.
         if (!$class->isInstantiable()) {
             continue;
         }
         // Skip non-test classes.
         if (!$class->isSubclassOf('Drupal\\simpletest\\TestBase') && !$class->isSubclassOf('PHPUnit_Framework_TestCase')) {
             continue;
         }
         $info = static::getTestInfo($class);
         // Skip this test class if it requires unavailable modules.
         // @todo PHPUnit skips tests with unmet requirements when executing a test
         //   (instead of excluding them upfront). Refactor test runner to follow
         //   that approach.
         // @see https://www.drupal.org/node/1273478
         if (!empty($info['requires']['module'])) {
             if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
                 continue;
             }
         }
         $list[$info['group']][$classname] = $info;
     }
     // Sort the groups and tests within the groups by name.
     uksort($list, 'strnatcasecmp');
     foreach ($list as &$tests) {
         uksort($tests, 'strnatcasecmp');
     }
     // Allow modules extending core tests to disable originals.
     \Drupal::moduleHandler()->alter('simpletest', $list);
     if (!isset($extension)) {
         if ($this->cacheBackend) {
             $this->cacheBackend->set('simpletest:discovery:classes', $list);
         }
     }
     return $list;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:83,代码来源:TestDiscovery.php

示例5: getTestClasses

 /**
  * Discovers all available tests in all extensions.
  *
  * @param string $extension
  *   (optional) The name of an extension to limit discovery to; e.g., 'node'.
  *
  * @return array
  *   An array of tests keyed by the first @group specified in each test's
  *   PHPDoc comment block, and then keyed by class names. For example:
  *   @code
  *     $groups['block'] => array(
  *       'Drupal\block\Tests\BlockTest' => array(
  *         'name' => 'Drupal\block\Tests\BlockTest',
  *         'description' => 'Tests block UI CRUD functionality.',
  *         'group' => 'block',
  *       ),
  *     );
  *   @endcode
  *
  * @throws \ReflectionException
  *   If a discovered test class does not match the expected class name.
  *
  * @todo Remove singular grouping; retain list of groups in 'group' key.
  * @see https://www.drupal.org/node/2296615
  * @todo Add base class groups 'Kernel' + 'Web', complementing 'PHPUnit'.
  */
 public function getTestClasses($extension = NULL)
 {
     $reader = new SimpleAnnotationReader();
     $reader->addNamespace('Drupal\\simpletest\\Annotation');
     if (!isset($extension)) {
         if ($this->cacheBackend && ($cache = $this->cacheBackend->get('simpletest:discovery:classes'))) {
             return $cache->data;
         }
     }
     $list = array();
     $classmap = $this->findAllClassFiles($extension);
     // Prevent expensive class loader lookups for each reflected test class by
     // registering the complete classmap of test classes to the class loader.
     // This also ensures that test classes are loaded from the discovered
     // pathnames; a namespace/classname mismatch will throw an exception.
     $this->classLoader->addClassMap($classmap);
     foreach ($classmap as $classname => $pathname) {
         $finder = MockFileFinder::create($pathname);
         $parser = new StaticReflectionParser($classname, $finder, TRUE);
         try {
             $info = static::getTestInfo($classname, $parser->getDocComment());
         } catch (MissingGroupException $e) {
             // If the class name ends in Test and is not a migrate table dump.
             if (preg_match('/Test$/', $classname) && strpos($classname, 'migrate_drupal\\Tests\\Table') === FALSE) {
                 throw $e;
             }
             // If the class is @group annotation just skip it. Most likely it is an
             // abstract class, trait or test fixture.
             continue;
         }
         // Skip this test class if it requires unavailable modules.
         // @todo PHPUnit skips tests with unmet requirements when executing a test
         //   (instead of excluding them upfront). Refactor test runner to follow
         //   that approach.
         // @see https://www.drupal.org/node/1273478
         if (!empty($info['requires']['module'])) {
             if (array_diff($info['requires']['module'], $this->availableExtensions['module'])) {
                 continue;
             }
         }
         $list[$info['group']][$classname] = $info;
     }
     // Sort the groups and tests within the groups by name.
     uksort($list, 'strnatcasecmp');
     foreach ($list as &$tests) {
         uksort($tests, 'strnatcasecmp');
     }
     // Allow modules extending core tests to disable originals.
     \Drupal::moduleHandler()->alter('simpletest', $list);
     if (!isset($extension)) {
         if ($this->cacheBackend) {
             $this->cacheBackend->set('simpletest:discovery:classes', $list);
         }
     }
     return $list;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:82,代码来源:TestDiscovery.php

示例6: registerClassMaps

 public function registerClassMaps($classMap)
 {
     if (!$classMap) {
         return;
     }
     if (!is_array($classMap)) {
         $classMap = [$classMap];
     }
     $loader = new ClassLoader();
     $loader->addClassMap($classMap);
     $loader->register(true);
 }
开发者ID:pckg,项目名称:framework,代码行数:12,代码来源:Registrator.php

示例7: validateComposerAutoLoadingClassMap

 /**
  * Check that the auto loading information is correct.
  *
  * @param array  $information The autoload information.
  *
  * @param string $baseDir     The base directory.
  *
  * @return bool
  */
 public function validateComposerAutoLoadingClassMap($information, $baseDir)
 {
     $result = true;
     // Scan all directories mentioned and validate the class map against the entries.
     foreach ($information as $path) {
         $subPath = str_replace('//', '/', $baseDir . '/' . $path);
         $classMap = $this->createClassMap($subPath);
         $this->loader->addClassMap($classMap);
         $this->classMap = array_merge($this->classMap, $classMap);
         if (!$this->validateComposerAutoLoadingClassMapClassMap($classMap, $subPath)) {
             $result = false;
         }
     }
     return $result;
 }
开发者ID:contao-community-alliance,项目名称:build-system-tool-autoloading-validation,代码行数:24,代码来源:CheckAutoloading.php

示例8: testFindFile

 /**
  * @covers ::findFile
  */
 public function testFindFile()
 {
     $finder = new ClassFinder();
     // The full path is returned therefore only tests with
     // assertStringEndsWith() so the test is portable.
     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
     $class = 'Not\\A\\Class';
     $this->assertNull($finder->findFile($class));
     // Register an autoloader that can find this class.
     $loader = new ClassLoader();
     $loader->addClassMap([$class => __FILE__]);
     $loader->register();
     $this->assertEquals(__FILE__, $finder->findFile($class));
     // This shouldn't prevent us from finding the original file.
     $this->assertStringEndsWith('core/tests/Drupal/Tests/UnitTestCase.php', $finder->findFile(UnitTestCase::class));
     // Clean up the additional autoloader after the test.
     $loader->unregister();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:21,代码来源:ClassFinderTest.php

示例9: addComposerFiles

 public static function addComposerFiles($dir)
 {
     if (file_exists($dir . '/vendor/composer/autoload_namespaces.php')) {
         $map = (require $dir . '/vendor/composer/autoload_namespaces.php');
         foreach ($map as $namespace => $path) {
             self::$classLoader->set($namespace, $path);
         }
     }
     if (file_exists($dir . '/vendor/composer/autoload_psr4.php')) {
         $map = (require $dir . '/vendor/composer/autoload_psr4.php');
         foreach ($map as $namespace => $path) {
             self::$classLoader->setPsr4($namespace, $path);
         }
     }
     if (file_exists($dir . '/vendor/composer/autoload_classmap.php')) {
         $classMap = (require $dir . '/vendor/composer/autoload_classmap.php');
         if ($classMap) {
             self::$classLoader->addClassMap($classMap);
         }
     }
 }
开发者ID:jigoshop,项目名称:Jigoshop2,代码行数:21,代码来源:Integration.php

示例10: microtime

 /**
  * Register core classes with autoloader
  * @param \Composer\Autoload\ClassLoader $loader
  */
 static function preload_core_with_composer($loader)
 {
     $timer = microtime(1);
     $classes = self::$_preload;
     foreach ($classes as $classname => &$file) {
         $file = self::get_public(self::DIR_MODULES . 'core/' . $file . self::DOT_PHP);
         if (!is_string($classname)) {
             require $file;
             unset($classes[$classname]);
         }
     }
     $loader->addClassMap($classes);
     self::dprint("autoload_core - done %.5f", array(microtime(1) - $timer));
 }
开发者ID:egregor-dev,项目名称:SatCMS,代码行数:18,代码来源:loader.php

示例11: addClassInFile

 public function addClassInFile(string $className, string $filePath)
 {
     $this->classLoader->addClassMap([$className => $filePath]);
 }
开发者ID:dkplus,项目名称:reflections,代码行数:4,代码来源:AutoloadingReflector.php

示例12: createLoader

 /**
  * 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);
         }
     }
     if (isset($autoloads['classmap'])) {
         foreach ($autoloads['classmap'] as $dir) {
             try {
                 $loader->addClassMap($this->generateClassMap($dir));
             } catch (\RuntimeException $e) {
                 $this->io->writeError('<warning>' . $e->getMessage() . '</warning>');
             }
         }
     }
     return $loader;
 }
开发者ID:neoFaster,项目名称:composer,代码行数:30,代码来源:AutoloadGenerator.php

示例13: getStaticFile

    protected function getStaticFile($suffix, $targetDir, $vendorPath, $basePath, &$staticPhpVersion)
    {
        $staticPhpVersion = 50600;
        $file = <<<HEADER
<?php

// autoload_static.php @generated by Composer

namespace Composer\\Autoload;

class ComposerStaticInit{$suffix}
{

HEADER;
        $loader = new ClassLoader();
        $map = (require $targetDir . '/autoload_namespaces.php');
        foreach ($map as $namespace => $path) {
            $loader->set($namespace, $path);
        }
        $map = (require $targetDir . '/autoload_psr4.php');
        foreach ($map as $namespace => $path) {
            $loader->setPsr4($namespace, $path);
        }
        $classMap = (require $targetDir . '/autoload_classmap.php');
        if ($classMap) {
            $loader->addClassMap($classMap);
        }
        $filesystem = new Filesystem();
        $vendorPathCode = ' ' . $filesystem->findShortestPathCode(realpath($targetDir), $vendorPath, true, true) . " . '/";
        $appBaseDirCode = ' ' . $filesystem->findShortestPathCode(realpath($targetDir), $basePath, true, true) . " . '/";
        $absoluteVendorPathCode = ' ' . substr(var_export(rtrim($vendorDir, '\\/') . '/', true), 0, -1);
        $absoluteAppBaseDirCode = ' ' . substr(var_export(rtrim($baseDir, '\\/') . '/', true), 0, -1);
        $initializer = '';
        $prefix = "Composer\\Autoload\\ClassLoader";
        $prefixLen = strlen($prefix);
        if (file_exists($targetDir . '/autoload_files.php')) {
            $maps = array('files' => require $targetDir . '/autoload_files.php');
        } else {
            $maps = array();
        }
        foreach ((array) $loader as $prop => $value) {
            if ($value && 0 === strpos($prop, $prefix)) {
                $maps[substr($prop, $prefixLen)] = $value;
            }
        }
        foreach ($maps as $prop => $value) {
            if (count($value) > 32767) {
                // Static arrays are limited to 32767 values on PHP 5.6
                // See https://bugs.php.net/68057
                $staticPhpVersion = 70000;
            }
            $value = var_export($value, true);
            $value = str_replace($absoluteVendorPathCode, $vendorPathCode, $value);
            $value = str_replace($absoluteAppBaseDirCode, $appBaseDirCode, $value);
            $value = ltrim(preg_replace('/^ */m', '    $0$0', $value));
            $file .= sprintf("    public static \$%s = %s;\n\n", $prop, $value);
            if ('files' !== $prop) {
                $initializer .= "            \$loader->{$prop} = ComposerStaticInit{$suffix}::\${$prop};\n";
            }
        }
        return $file . <<<INITIALIZER
    public static function getInitializer(ClassLoader \$loader)
    {
        return \\Closure::bind(function () use (\$loader) {
{$initializer}
        }, null, ClassLoader::class);
    }
}

INITIALIZER;
    }
开发者ID:dazzle-libraries,项目名称:composer,代码行数:71,代码来源:AutoloadGenerator.php

示例14: prepareComposerFallbackLoader

 /**
  * Prepare the composer fallback loader.
  *
  * @param EnumeratingClassLoader $enumLoader The enum loader to add to.
  *
  * @param string                 $baseDir    The base dir where the composer.json resides.
  *
  * @param array                  $composer   The contents of the composer.json.
  *
  * @return void
  */
 private function prepareComposerFallbackLoader(EnumeratingClassLoader $enumLoader, $baseDir, $composer)
 {
     $vendorDir = $baseDir . DIRECTORY_SEPARATOR . 'vendor';
     if (isset($composer['extra']['vendor-dir'])) {
         $vendorDir = $baseDir . DIRECTORY_SEPARATOR . $composer['extra']['vendor-dir'];
     }
     if (!is_dir($vendorDir)) {
         return;
     }
     $loader = new ClassLoader();
     if ($map = $this->includeIfExists($vendorDir . '/composer/autoload_namespaces.php')) {
         foreach ($map as $namespace => $path) {
             $loader->set($namespace, $path);
         }
     }
     if ($map = $this->includeIfExists($vendorDir . '/composer/autoload_psr4.php')) {
         foreach ($map as $namespace => $path) {
             $loader->setPsr4($namespace, $path);
         }
     }
     if ($classMap = $this->includeIfExists($vendorDir . '/composer/autoload_classmap.php')) {
         $loader->addClassMap($classMap);
     }
     $enumLoader->add(array($loader, 'loadClass'), 'composer.fallback');
 }
开发者ID:phpcq,项目名称:autoload-validation,代码行数:36,代码来源:CheckAutoloading.php

示例15: getLoader

 /**
  * {@inheritDoc}
  */
 public function getLoader()
 {
     $loader = new ClassLoader();
     $loader->addClassMap(iterator_to_array($this->getClassMap()));
     return array($loader, 'loadClass');
 }
开发者ID:phpcq,项目名称:autoload-validation,代码行数:9,代码来源:ClassMapValidator.php


注:本文中的Composer\Autoload\ClassLoader::addClassMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。