Exemplo n.º 1
0
 /**
  * This method checks module name, loads mapping info from ModuleController
  * entity, and calls specified controller from custom ModuleBundle
  *
  * @param GetResponseEvent $event
  */
 public function onKernelController(GetResponseEvent $event)
 {
     if ($this->em) {
         $attributes = $event->getRequest()->attributes;
         if (in_array($attributes->get("_route"), array("module", "subsection"))) {
             // get available namespaces for this connection
             $namespace = $this->dataModel->getNamespaceForModule($attributes->get('key'), $attributes->get('module'));
             if ($namespace !== false) {
                 $record = $this->dataModel->getModuleControllers($attributes->get('module'), $namespace);
                 if ($record) {
                     // get all saved controllers from DB
                     $controllers = $record->getControllerActions();
                     /**
                      * @var ConnectionSession $conn
                      */
                     $conn = $this->dataModel->getConnectionSessionForKey($attributes->get('key'));
                     $activeController = $conn->getActiveControllersForNS($namespace);
                     // if we don't have any saved (preferred) controller, we will use first from DB
                     if (!$activeController) {
                         $activeController = $controllers[0];
                     }
                     $event->getRequest()->attributes->set("_controller", $activeController);
                 }
             }
         }
     }
 }