本文整理汇总了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']);
}
示例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));
}
}
}
}
}
}
}
}
示例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;
}