src/helpers/EventHelper.php
public static function getActiveHandlersList()
    {
        $cacheKey = 'DevGroup/EventsSystem:activeHandlersList';
        $handlers = Yii::$app->cache->get($cacheKey);
        if ($handlers === false) {
            $eventEventHandlers = EventEventHandler::find()
                ->where(['is_active' => 1])
                ->orderBy(['sort_order' => SORT_ASC])
                ->asArray(true)
                ->all();
            $events = Event::find()
                ->where(['id' => array_column($eventEventHandlers, 'event_id', 'event_id')])
                ->indexBy('id')
                ->asArray(true)
                ->all();
            $eventGroups = EventGroup::find()
                ->where(['id' => array_column($events, 'event_group_id', 'event_group_id')])
                ->indexBy('id')
                ->asArray(true)
                ->all();
            $eventHandlers = EventHandler::find()
                ->where(['id' => array_column($eventEventHandlers, 'event_handler_id', 'event_handler_id')])
                ->indexBy('id')
                ->asArray(true)
                ->all();
            $handlers = [];
            foreach ($eventEventHandlers as $eventEventHandler) {
                if (isset(
                        $eventHandlers[$eventEventHandler['event_handler_id']],
                        $events[$eventEventHandler['event_id']],
                        $eventGroups[$events[$eventEventHandler['event_id']]['event_group_id']]
                    ) === false
                ) {
                    continue;
                }
                try {
                    $data = Json::decode($eventEventHandler['packed_json_params']);
                } catch (\Exception $e) {
                    $data = [];
                }
                $handlers[] = [
                    'class' => $eventGroups[$events[$eventEventHandler['event_id']]['event_group_id']]['owner_class_name'],
                    'name' => $events[$eventEventHandler['event_id']]['execution_point'],
                    'callable' => [
                        $eventHandlers[$eventEventHandler['event_handler_id']]['class_name'],
                        $eventEventHandler['method'],
                    ],
                    'data' => $data,
                ];
            }
            Yii::$app->cache->set(
                $cacheKey,
                $handlers,
                86400,
                new TagDependency(
                    [
                        'tags' => [
                            NamingHelper::getCommonTag(EventGroup::className()),
                            NamingHelper::getCommonTag(Event::className()),
                            NamingHelper::getCommonTag(EventHandler::className()),
                            NamingHelper::getCommonTag(EventEventHandler::className()),
                        ],
                    ]
                )
            );
        }
        return $handlers;
    }
public static function getActiveHandlersList()
    {
        $cacheKey = 'DevGroup/EventsSystem:activeHandlersList';
        $handlers = Yii::$app->cache->get($cacheKey);
        if ($handlers === false) {
            $eventEventHandlers = EventEventHandler::find()
                ->where(['is_active' => 1])
                ->orderBy(['sort_order' => SORT_ASC])
                ->asArray(true)
                ->all();
            $events = Event::find()
                ->where(['id' => array_column($eventEventHandlers, 'event_id', 'event_id')])
                ->indexBy('id')
                ->asArray(true)
                ->all();
            $eventGroups = EventGroup::find()
                ->where(['id' => array_column($events, 'event_group_id', 'event_group_id')])
                ->indexBy('id')
                ->asArray(true)
                ->all();
            $eventHandlers = EventHandler::find()
                ->where(['id' => array_column($eventEventHandlers, 'event_handler_id', 'event_handler_id')])
                ->indexBy('id')
                ->asArray(true)
                ->all();
            $handlers = [];
            foreach ($eventEventHandlers as $eventEventHandler) {
                if (isset(
                        $eventHandlers[$eventEventHandler['event_handler_id']],
                        $events[$eventEventHandler['event_id']],
                        $eventGroups[$events[$eventEventHandler['event_id']]['event_group_id']]
                    ) === false
                ) {
                    continue;
                }
                try {
                    $data = Json::decode($eventEventHandler['packed_json_params']);
                } catch (\Exception $e) {
                    $data = [];
                }
                $handlers[] = [
                    'class' => $eventGroups[$events[$eventEventHandler['event_id']]['event_group_id']]['owner_class_name'],
                    'name' => $events[$eventEventHandler['event_id']]['execution_point'],
                    'callable' => [
                        $eventHandlers[$eventEventHandler['event_handler_id']]['class_name'],
                        $eventEventHandler['method'],
                    ],
                    'data' => $data,
                ];
            }
            Yii::$app->cache->set(
                $cacheKey,
                $handlers,
                86400,
                new TagDependency(
                    [
                        'tags' => [
                            NamingHelper::getCommonTag(EventGroup::className()),
                            NamingHelper::getCommonTag(Event::className()),
                            NamingHelper::getCommonTag(EventHandler::className()),
                            NamingHelper::getCommonTag(EventEventHandler::className()),
                        ],
                    ]
                )
            );
        }
        return $handlers;
    }
public static function getActiveHandlersList ( ) { $ cacheKey = 'DevGroup/EventsSystem:activeHandlersList' ; $ handlers = Yii :: $ app -> cache -> get ( $ cacheKey ) ; if ( $ handlers === false ) { $ eventEventHandlers = EventEventHandler :: find ( ) -> where ( [ 'is_active' => 1 ] ) -> orderBy ( [ 'sort_order' => SORT_ASC ] ) -> asArray ( true ) -> all ( ) ; $ events = Event :: find ( ) -> where ( [ 'id' => array_column ( $ eventEventHandlers , 'event_id' , 'event_id' ) ] ) -> indexBy ( 'id' ) -> asArray ( true ) -> all ( ) ; $ eventGroups = EventGroup :: find ( ) -> where ( [ 'id' => array_column ( $ events , 'event_group_id' , 'event_group_id' ) ] ) -> indexBy ( 'id' ) -> asArray ( true ) -> all ( ) ; $ eventHandlers = EventHandler :: find ( ) -> where ( [ 'id' => array_column ( $ eventEventHandlers , 'event_handler_id' , 'event_handler_id' ) ] ) -> indexBy ( 'id' ) -> asArray ( true ) -> all ( ) ; $ handlers = [ ] ; foreach ( $ eventEventHandlers as $ eventEventHandler ) { if ( isset ( $ eventHandlers [ $ eventEventHandler [ 'event_handler_id' ] ] , $ events [ $ eventEventHandler [ 'event_id' ] ] , $ eventGroups [ $ events [ $ eventEventHandler [ 'event_id' ] ] [ 'event_group_id' ] ] ) === false ) { continue ; } try { $ data = Json :: decode ( $ eventEventHandler [ 'packed_json_params' ] ) ; } catch ( \ Exception $ e ) { $ data = [ ] ; } $ handlers [ ] = [ 'class' => $ eventGroups [ $ events [ $ eventEventHandler [ 'event_id' ] ] [ 'event_group_id' ] ] [ 'owner_class_name' ] , 'name' => $ events [ $ eventEventHandler [ 'event_id' ] ] [ 'execution_point' ] , 'callable' => [ $ eventHandlers [ $ eventEventHandler [ 'event_handler_id' ] ] [ 'class_name' ] , $ eventEventHandler [ 'method' ] , ] , 'data' => $ data , ] ; } Yii :: $ app -> cache -> set ( $ cacheKey , $ handlers , 86400 , new TagDependency ( [ 'tags' => [ NamingHelper :: getCommonTag ( EventGroup :: className ( ) ) , NamingHelper :: getCommonTag ( Event :: className ( ) ) , NamingHelper :: getCommonTag ( EventHandler :: className ( ) ) , NamingHelper :: getCommonTag ( EventEventHandler :: className ( ) ) , ] , ] ) ) ; } return $ handlers ; }
Gat all active handlers.
@return array of handlers
Gat all active handlers .