本文整理匯總了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;
}