Yii2 类自动加载机制
2019-08-24 14:08:07 9 举报
AI智能生成
Yii2 类自动加载机制
作者其他创作
大纲/内容
Yii2 类自动加载机制
Yii::$classMap
'yii\\base\\Application' => YII2_PATH . '/base/Application.php'
'yii\\base\\Behavior' => YII2_PATH . '/base/Behavior.php'
'yii\\base\\Event' => YII2_PATH . '/base/Event.php'
'yii\\base\\Object' => YII2_PATH . '/base/Object.php'
...
yii\\web\\Application
yii\\base\\Application
vendor/yiisoft/extensions.php
$vendorDir = dirname(__DIR__);
'@yii/bootstrap' => $vendorDir . '/yiisoft/yii2-bootstrap'
'@yii/gii' => $vendorDir . '/yiisoft/yii2-gii'
'@yii/faker' => $vendorDir . '/yiisoft/yii2-faker'
'@yii/swiftmailer' => $vendorDir . '/yiisoft/yii2-swiftmailer'
'@callmez/wechat/sdk' => $vendorDir . '/callmez/yii2-wechat-sdk'
'@yii/debug' => $vendorDir . '/yiisoft/yii2-debug'
common/config/bootstrap.php
index.php
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
vendor/yiisoft/yii2/Yii.php
require(__DIR__ . '/BaseYii.php');
class Yii extends \\yii\\BaseYii{}
Yii::$classMap = require(__DIR__ . '/classes.php');
Yii::$container = new yii\\di\\Container();
yii\\BaseYii
其他define
public static $classMap = [];
public static $app;
public static $aliases = ['@yii' => __DIR__];
public static $container;
public static function getVersion()
public static function autoload($className)
if (isset(static::$classMap[$className]))
$classFile = static::$classMap[$className]
if ($classFile[0] === '@')
$classFile = static::getAlias($classFile);
include($classFile);
public static function getRootAlias($alias)
if (is_string($type))
elseif (is_array($type) && isset($type['class']))
$class = $type['class']
foreach ($properties as $name => $value)
$object->$name = $value
其他方法
public static function getLogger()
public static function setLogger($logger)
public static function powered()
public static function getObjectVars($object)
return get_object_vars($object);
vendor/autoload.php
Composer/PSR4支持
require_once __DIR__ . '/composer/autoload_real.php'
private static $loader;
public static function loadClassLoader($class)
require __DIR__ . '/ClassLoader.php';
public static function getLoader()
self::$loader = $loader = new \\Composer\\Autoload\\ClassLoader();
::getLoader()
0 条评论
回复 删除
下一页