Yii2 服务定位器
2019-08-25 22:23:08 3 举报
AI智能生成
为你推荐
查看更多
Yii2 服务定位器
作者其他创作
大纲/内容
private $_components = [];
private $_definitions = [];
__get($name)
if ($this->has($name))
return $this->get($name);
else
return parent::__get($name);
__isset($name)
return true;
else
return parent::__isset($name);
return $checkInstance ? isset($this->_components[$id]) : isset($this->_definitions[$id]);
yii\\di\\ServiceLocator
setComponents($components)
foreach ($components as $id => $component)
if ($definition === null)
return;
unset($this->_components[$id]);
$this->_definitions[$id] = $definition;
elseif (is_array($definition))
if (isset($definition['class']))
if (isset($this->_components[$id]))
return $this->_components[$id];
if (isset($this->_definitions[$id]))
$definition = $this->_definitions[$id];
if (is_object($definition) && !$definition instanceof Closure)
return $this->_components[$id] = $definition;
return $this->_components[$id] = Yii::createObject($definition);
elseif ($throwException)
throw new InvalidConfigException(\"Unknown component ID: $id\");
return null;
clear($id)
getComponents($returnDefinitions = true)
return $returnDefinitions ? $this->_definitions : $this->_components;
0 条评论
回复 删除
下一页