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


PHP ClassLoader::add方法代码示例

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


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

示例1: createAppKernel

 /**
  * Creates RAD app kernel, which you can use to manage your app.
  *
  * Loads intl, swift and then requires/initializes/returns custom
  * app kernel.
  *
  * @param ClassLoader $loader      Composer class loader
  * @param string      $environment Environment name
  * @param Boolean     $debug       Debug mode?
  *
  * @return RadAppKernel
  */
 public static function createAppKernel(ClassLoader $loader, $environment, $debug)
 {
     require_once __DIR__ . '/RadAppKernel.php';
     if (null === self::$projectRootDir) {
         self::$projectRootDir = realpath(__DIR__ . '/../../../../../../..');
     }
     $autoloadIntl = function ($rootDir) use($loader) {
         if (!function_exists('intl_get_error_code')) {
             require_once $rootDir . '/vendor/symfony/symfony/src/' . 'Symfony/Component/Locale/Resources/stubs/functions.php';
             $loader->add(null, $rootDir . '/vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
         }
     };
     $autoloadSwift = function ($rootDir) use($loader) {
         require_once $rootDir . '/vendor/swiftmailer/swiftmailer/lib/classes/Swift.php';
         \Swift::registerAutoload($rootDir . '/vendor/swiftmailer/swiftmailer/lib/swift_init.php');
     };
     $loader->add(null, self::$projectRootDir . '/src');
     if (file_exists($custom = self::$projectRootDir . '/config/autoload.php')) {
         require $custom;
     } else {
         $autoloadIntl(self::$projectRootDir);
         $autoloadSwift(self::$projectRootDir);
     }
     return new \RadAppKernel($environment, $debug);
 }
开发者ID:ruian,项目名称:KnpRadBundle,代码行数:37,代码来源:RadKernel.php

示例2: 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}'");
 }
开发者ID:Rudloff,项目名称:composer,代码行数:16,代码来源:ClassLoaderTest.php

示例3: registerModuleLoaders

 protected function registerModuleLoaders()
 {
     foreach ($this->parameters['modules'] as $items) {
         if (isset($items['autoload']['psr-0'])) {
             foreach ($items['autoload']['psr-0'] as $key => $val) {
                 $this->classLoader->add($key, $items['path'] . '/' . $val);
             }
         }
         if (isset($items['autoload']['files'])) {
             foreach ($items['autoload']['files'] as $file) {
                 include_once $items['path'] . '/' . $file;
             }
         }
     }
 }
开发者ID:svobodni,项目名称:web,代码行数:15,代码来源:Configurator.php

示例4: 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.
  * @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);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:25,代码来源:ClassLoaderTest.php

示例5: registerCustomAutoloaders

 /**
  * 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);
         }
     }
 }
开发者ID:lslab,项目名称:n98-magerun,代码行数:11,代码来源:Application.php

示例6: getLoader

 /**
  * {@inheritDoc}
  */
 public function getLoader()
 {
     $loader = new ClassLoader();
     foreach ($this->information as $prefix => $paths) {
         $loader->add($prefix, array_map(array($this, 'prependPathWithBaseDir'), (array) $paths));
     }
     return array($loader, 'loadClass');
 }
开发者ID:phpcq,项目名称:autoload-validation,代码行数:11,代码来源:Psr0Validator.php

示例7: registerNamespace

 /**
  * @param string $ns Namespace's description
  * @param string $path Namespace's path
  * @throws Exception
  */
 public static function registerNamespace($ns, $path)
 {
     switch (true) {
         case self::$loader instanceof \Composer\Autoload\ClassLoader:
             self::$loader->add($ns, $path);
             break;
         case self::$loader instanceof \Zend\Loader\SplAutoloader:
             self::$loader->registerPrefix($ns, $path . '/' . $ns);
             break;
             // @TODO: This hasn't been tested nor confirmed. Must test & check if OK.
         // @TODO: This hasn't been tested nor confirmed. Must test & check if OK.
         case self::$loader instanceof \Symfony\Component\ClassLoader\UniversalClassLoader:
             self::$loader->registerNamespace($ns, $path);
             break;
         default:
             throw new \Exception('No Loader detected!');
     }
 }
开发者ID:athemcms,项目名称:netis,代码行数:23,代码来源:LoaderFactory.php

示例8: load

 /**
  * 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;
     }
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:28,代码来源:AddonLoader.php

示例9: validateComposerAutoLoadingPsr0

 /**
  * Check that the auto loading information is correct.
  *
  * @param array  $information The autoload information.
  *
  * @param string $baseDir     The base directory.
  *
  * @return bool
  */
 public function validateComposerAutoLoadingPsr0($information, $baseDir)
 {
     $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->add($namespace, $subPath);
         if (!$this->validateComposerAutoLoadingPsr0ClassMap($classMap, $subPath, $namespace)) {
             $result = false;
         }
     }
     return $result;
 }
开发者ID:contao-community-alliance,项目名称:build-system-tool-autoloading-validation,代码行数:23,代码来源:CheckAutoloading.php

示例10: registerCustomAutoloaders

 /**
  * 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);
         }
     }
     if (isset($this->config['autoload_files']) && is_array($this->config['autoload_files'])) {
         foreach ($this->config['autoload_files'] as $file) {
             require $file;
         }
     }
 }
开发者ID:nola-radar,项目名称:n98-magerun,代码行数:21,代码来源:Application.php

示例11: register

 public function register()
 {
     $app = $this->app;
     foreach ($app['contenttypes'] as $contentType) {
         $key = $contentType->getKey();
         $model = $this->getModel($contentType);
         $repository = $this->getRepository($contentType);
         $package = $this->getPackage();
         $vendor = $package->getVendor();
         $lowerVendor = strtolower($vendor);
         $name = $package->getName();
         $lowerName = strtolower($name);
         $loader = new ClassLoader();
         $loader->add($vendor . '\\' . $name . '\\', $app['paths']['base'] . '/vendor/' . $lowerVendor . '/' . $lowerName . '/src');
         $loader->register();
         $this->registerModel($key, $model);
         $this->registerRepository($key, $repository);
     }
 }
开发者ID:vespakoen,项目名称:bolt-core,代码行数:19,代码来源:CodyLaravelCompiler.php

示例12: registerNamespace

 /**
  * Class Prefix (Namespace) Register
  *
  * @param string $prefix
  * @param string $path
  * @throws \Exception
  */
 public function registerNamespace($prefix, $path)
 {
     switch (true) {
         // Zend Loader
         case self::$loader instanceof \Zend\Loader\SplAutoloader:
             self::$loader->registerPrefix($prefix, $path . '/' . str_replace('\\', '/', $prefix));
             break;
             // Composer Loader
         // Composer Loader
         case self::$loader instanceof \Composer\Autoload\ClassLoader:
             self::$loader->add($prefix, $path);
             break;
             // Symphony Loader
             // @TODO: Wonder if we should implement this as well or not
             // Throw exception for not finding a suported loader
         // Symphony Loader
         // @TODO: Wonder if we should implement this as well or not
         // Throw exception for not finding a suported loader
         default:
             throw new Exception\UndefinedClassLoaderException(sprintf('Unexpected ClassLoader type: \'%s\'', get_class(self::$loader)));
     }
     return $this;
 }
开发者ID:athemcms,项目名称:netis,代码行数:30,代码来源:Application.php

示例13: Routing

<?php

/**
 * Created by PhpStorm.
 * User: info_000
 * Date: 28.08.2015
 * Time: 0:00
 */
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Composer\Autoload\ClassLoader;
use Core\Libs\Route;
//$loader = new \Composer\Autoload\ClassLoader();
$loader = new ClassLoader();
$loader->add('Core\\Libs\\Route', $_SERVER['DOCUMENT_ROOT'] . '');
$loader->register();
$route = new Route();
/*
print_r(__NAMESPACE__);

new Routing();

echo '1';



use \Core\Libs\Routing;
use \Core\Libs\Controller;


function spl_autoload($class){
开发者ID:ronikpvl,项目名称:wgtest,代码行数:31,代码来源:initialization.php

示例14: registerCustomAutoloaders

 /**
  * Adds autoloader prefixes from user's config
  *
  * @param ClassLoader $autoloader
  */
 public function registerCustomAutoloaders(ClassLoader $autoloader)
 {
     $mask = '<debug>Registered %s autoloader </debug> <info>%s</info> -> <comment>%s</comment>';
     foreach ($this->getArray('autoloaders') as $prefix => $paths) {
         $paths = (array) $paths;
         $this->debugWriteln(sprintf($mask, self::PSR_0, OutputFormatter::escape($prefix), implode(",", $paths)));
         $autoloader->add($prefix, $paths);
     }
     foreach ($this->getArray('autoloaders_psr4') as $prefix => $paths) {
         $paths = (array) $paths;
         $this->debugWriteln(sprintf($mask, self::PSR_4, OutputFormatter::escape($prefix), implode(",", $paths)));
         $autoloader->addPsr4($prefix, $paths);
     }
 }
开发者ID:netz98,项目名称:n98-magerun,代码行数:19,代码来源:Config.php

示例15: add

 public static function add($namespace, $dir)
 {
     if (!in_array($namespace, self::$autoloader->getPrefixes())) {
         self::$autoloader->add($namespace, dirname($dir));
     }
 }
开发者ID:rtznprmpftl,项目名称:Zikulacore,代码行数:6,代码来源:ZikulaAutoload.php


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