當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。