/** * 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; }
/** * 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; }