annot_reader = $annot_reader; $this->menu_gen = $menu_gen; $this->twig = $twig; } public function onKernelController(ControllerEvent $event) { if (!$event->isMasterRequest()) return; // get controller $event_controller = $event->getController(); if (!is_array($event_controller)) return; list($controller, $method_name) = $event_controller; // get reflection class try { $ref_controller = new ReflectionClass($controller); } catch (ReflectionException $e) { throw new RuntimeException('Cannot read menu annotation.'); } // get method annotations $ref_method = $ref_controller->getMethod($method_name); $annotation = $this->annot_reader->getMethodAnnotation($ref_method, MenuAnnotation::class); // check if we get anything if ($annotation == null) return; $this->selectMenu($annotation->group, $annotation->selected); } protected function selectMenu($group_id, $selected) { $this->menu_gen->setSelected($group_id, $selected); /* // get menu $menu = $this->menu_gen->getMenu($group_id); // set menu selected $sel = $menu['index']->get($selected); if ($sel != null) $sel->setSelected(); */ } }