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


PHP ClassLoader::getClassMap方法代码示例

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


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

示例1: testInitializerSkipsGenerationInProductionMode

 public function testInitializerSkipsGenerationInProductionMode()
 {
     $this->maam->init($this->loader);
     $classMap = $this->loader->getClassMap();
     $this->assertArrayHasKey('someclass', $classMap);
     $this->assertSame('somefile', $classMap['someclass']);
 }
开发者ID:michaelmoussa,项目名称:maam,代码行数:7,代码来源:MaamTest.php

示例2: __construct

 /**
  * Construct
  *
  * @param ClassLoader $loader Loader
  *
  * @throws Exception
  */
 public function __construct(ClassLoader $loader)
 {
     if (empty($loader->getClassMap())) {
         throw new Exception('You are required to run: composer dump-autoload -o', Http::STATUS_CODE_404);
     }
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
     $this->directoryClassLoader($loader, self::getAppDir() . DS . 'modules');
     $this->setModules(Loader::load($loader));
     $this->directoryClassLoader($loader, self::getAppDir() . DS . 'libraries');
     $routing = array();
     foreach ($this->getModules() as $mod) {
         // Get routing from menus
         if (method_exists($mod, 'menus')) {
             $menus = array();
             foreach ($mod->menus() as $name => $menu) {
                 foreach ($menu as $key => $value) {
                     $routing['GET'] = array_merge_recursive($value->getRoutesRecursive(), $routing);
                     if ($value instanceof Menu) {
                         $menus[$name][$key] = $value->toArray();
                     }
                 }
             }
             $this->menus = array_replace_recursive($menus, $this->menus);
         }
         // Get additional routing
         if (method_exists($mod, 'routes')) {
             foreach ($mod->routes() as $method => $route) {
                 foreach ($route as $key => $value) {
                     if (key_exists(strtoupper($method), $routing) && key_exists($value, $routing[strtoupper($method)])) {
                         $routing[strtoupper($method)][$value] = array_merge_recursive($routing[strtoupper($method)][$value], array($key));
                     } else {
                         $routing[strtoupper($method)][$value] = array($key);
                     }
                 }
             }
         }
         self::callGlobalEvent($mod, 'bootstrap');
     }
     // Add extra routes to module routing
     foreach ($routing as $method => $routes) {
         foreach ($routes as $action => $route) {
             if (!empty($route)) {
                 foreach ($this->getModules() as $module) {
                     foreach ($module->getRoutes() as &$urls) {
                         if ($urls->getRequestMethod() === $method) {
                             if (in_array($action, $urls->getUrls())) {
                                 $urls->setUrls(array_merge($urls->getUrls(), $route));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:phpforge,项目名称:application,代码行数:64,代码来源:Application.php

示例3: load

 /**
  * Loader
  *
  * @param ClassLoader $loader Loader
  *
  * @return array
  */
 public static function load(ClassLoader $loader)
 {
     $modules = array();
     $classmap = $loader->getClassMap();
     foreach ($classmap as $class => $file) {
         // The following is required as class_exists, is_subclass_of and ReflectionClass will throw a fatal error if class extends a non-existent class
         // @todo allow custom namespaces
         if (!preg_match('/^main|phpforge|module/i', $class) && !preg_match('/^' . str_replace('/', '\\/', self::getModDir()) . '/i', $file)) {
             continue;
         }
         if (class_exists($class)) {
             if (is_subclass_of($class, 'Forge\\Application\\Module')) {
                 $ref = new \ReflectionClass($class);
                 if ($ref->IsInstantiable()) {
                     $mod = $ref->newInstanceWithoutConstructor();
                     $acls = array();
                     if (method_exists($mod, 'acl')) {
                         $acls = $mod->acl();
                     }
                     $routemap = array();
                     $methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC);
                     foreach ($methods as $method) {
                         if (preg_match('/Post|Get|Put|Delete$/', $method->name)) {
                             $methodName = preg_replace('/Post|Get|Put|Delete$/', '', $method->name);
                             $methodType = strtoupper(preg_replace('/.*(Post|Get|Put|Delete)$/', '$1', $method->name));
                             $urls = array();
                             if (strtolower($methodName) == strtolower($ref->getShortName())) {
                                 if (strtolower($method->class) == strtolower(self::$defaultModule) && $methodType == 'GET') {
                                     $urls[] = '/';
                                 }
                                 $urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class));
                             } else {
                                 $urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class) . '/' . $methodName);
                             }
                             $route = new Route();
                             $route->setClass($class)->setMethod($method->name)->setRequestMethod($methodType)->setUrls($urls);
                             if (key_exists($method->name, $acls)) {
                                 $route->setAcls($acls[$method->name]);
                             }
                             $routemap[] = $route;
                         }
                     }
                     $mod->setRoutes($routemap);
                     $modules[] = $mod;
                 }
             }
         }
     }
     return $modules;
 }
开发者ID:phpforge,项目名称:application,代码行数:57,代码来源:Loader.php


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