Yii2 配置项
2019-08-24 19:18:16 6 举报
AI智能生成
Yii2 配置项
作者其他创作
大纲/内容
Yii2 配置项
index.php
$application = new yii\\web\\Application($config);
$application->run();
Yii
yii\\BaseYii
public static $app;
if (is_string($type))
elseif (is_array($type) && isset($type['class']))
$class = $type['class']
foreach ($properties as $name => $value)
$object->$name = $value
yii\\web\\Application
public function coreComponents()
yii\\base\\Module
private $_basePath;
public static function setInstance($instance)
if ($instance === null)
unset(Yii::$app->loadedModules[get_called_class()]);
else
Yii::$app->loadedModules[get_class($instance)] = $instance;
public function setBasePath($path)
$path = Yii::getAlias($path);
$this->_basePath = $p;
public function getBasePath()
yii\\di\\ServiceLocator
$checkInstance ? isset($this->_components[$id]) : isset($this->_definitions[$id]);
yii\\base\\Component
public function __get($name)
yii\\base\\Object
public function __construct($config = [])
$this->init();
yii\\base\\ErrorHandler
public function register()
private $_memoryReserve;
if (defined('HHVM_VERSION'))
if ($this->memoryReserveSize > 0)
yii\\base\\Application
public $extensions;
public $bootstrap = [];
config配置
public $state;
public $loadedModules = [];
Yii::$app = $this;
static::setInstance($this);
$this->state = self::STATE_BEGIN;
$this->preInit($config);
$this->registerErrorHandler($config);
Component::__construct($config);
public function preInit(&$config)
$this->setBasePath($config['basePath']);
$this->setVendorPath($config['vendorPath']);
$this->setRuntimePath($config['runtimePath']);
$this->setTimeZone($config['timeZone']);
$this->setContainer($config['container']);
foreach ($this->coreComponents() as $id => $component)
if (!isset($config['components'][$id]))
$config['components'][$id] = $component;
elseif (is_array($config['components'][$id]) && !isset($config['components'][$id]['class']))
$config['components'][$id]['class'] = $component['class'];
parent::setBasePath($path);
public function setVendorPath($path)
$this->_vendorPath = Yii::getAlias($path);
public function setRuntimePath($path)
$this->_runtimePath = Yii::getAlias($path);
public function setTimeZone($value)
date_default_timezone_set($value);
public function setContainer($config)
protected function registerErrorHandler(&$config)
unset($config['components']['errorHandler']);
$this->getErrorHandler()->register();
public function getErrorHandler()
$this->get('errorHandler')
public function init()
$this->state = self::STATE_INIT;
$this->bootstrap();
protected function bootstrap()
$file = Yii::getAlias('@vendor/yiisoft/extensions.php');
$this->extensions = is_file($file) ? include($file) : [];
foreach ($this->extensions as $extension)
foreach ($extension['alias'] as $name => $path)
$component = Yii::createObject($extension['bootstrap']);
if ($component instanceof BootstrapInterface)
$component->bootstrap($this);
foreach ($this->bootstrap as $class)
$component = null;
if (is_string($class))
if ($this->has($class))
$component = $this->get($class);
elseif ($this->hasModule($class))
$component = $this->getModule($class);
if (!isset($component))
$component = Yii::createObject($class);
$component->bootstrap($this);
0 条评论
回复 删除
下一页