本文整理汇总了PHP中yii\base\Application::setComponents方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::setComponents方法的具体用法?PHP Application::setComponents怎么用?PHP Application::setComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Application
的用法示例。
在下文中一共展示了Application::setComponents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEventManager
/**
* finds and creates app event manager from its settings
* @param Application $app yii app
* @return EventManager app event manager component
* @throws Exception Define event manager
*/
public static function getEventManager($app)
{
if (self::$_eventManager) {
return self::$_eventManager;
}
foreach ($app->components as $name => $config) {
$class = is_string($config) ? $config : @$config['class'];
if ($class == str_replace('Bootstrap', 'Manager', get_called_class())) {
return self::$_eventManager = $app->{$name};
}
}
$eventFile = \Yii::getAlias('@app/config/_events.php');
$app->setComponents(['eventManager' => ['class' => 'bariew\\eventManager\\EventManager', 'events' => file_exists($eventFile) && is_file($eventFile) ? include $eventFile : []]]);
return self::$_eventManager = $app->eventManager;
}
示例2: getEventManager
/**
* finds and creates app event manager from its settings
* @param Application $app yii app
* @return EventManager app event manager component
* @throws Exception Define event manager
*/
public static function getEventManager($app)
{
if (self::$_eventManager) {
return self::$_eventManager;
}
foreach ($app->components as $name => $config) {
$class = is_string($config) ? $config : @$config['class'];
// if eventManager component in config
if ($class == str_replace('Bootstrap', 'Manager', get_called_class())) {
self::$_eventManager = $app->{$name}->events;
}
// this class. set $appId from config
if ($class == str_replace('Manager', 'Bootstrap', get_called_class())) {
if ($app->{$name}->appId) {
self::$appId = $app->{$name}->appId;
}
}
}
$events = ModelEvent::eventList(self::$appId);
// merge config events with plugins
self::$_eventManager = array_merge_recursive($events, self::$_eventManager);
$app->setComponents(['eventManager' => ['class' => 'esoftslimited\\plugins\\components\\EventManager', 'events' => self::$_eventManager]]);
return self::$_eventManager = $app->eventManager;
}