public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); /** * Register event listeners */ $eventsMajesticExternalContacts = $e->getApplication()->getServiceManager()->get("MajesticExternalContacts\\Events\\MajesticExternalContactsEvents"); $eventsMajesticExternalContacts->registerEvents(); // set layout for forms being displayed /** * Set layout */ $sharedEvents = $eventManager->getSharedManager(); $sharedEvents->attach(__NAMESPACE__, 'dispatch', function ($e) { // fired when an ActionController under the namespace is dispatched. $controller = $e->getTarget(); $controller->layout('layout/external/contacts'); }, 100); /** * Deal with flash messages that needs to be passed to the layout view */ $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function ($e) { $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger(); if ($flashMessenger->hasMessages()) { $e->getViewModel()->setVariable('flashMessages', $flashMessenger->getMessages()); } //end if if ($flashMessenger->hasErrorMessages()) { $e->getViewModel()->setVariable('flashMessages_errors', $flashMessenger->getErrorMessages()); } //end if if ($flashMessenger->hasInfoMessages()) { $e->getViewModel()->setVariable('flashMessages_info', $flashMessenger->getInfoMessages()); } //end if if ($flashMessenger->hasSuccessMessages()) { $e->getViewModel()->setVariable('flashMessages_success', $flashMessenger->getSuccessMessages()); } //end if }); }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); //preload the Service Manager instance to the Service Manager Factory FrontCoreServiceProviderFactory::setInstance($e->getApplication()->getServiceManager()); /** * Register event listeners */ $eventsFrontCore = $e->getApplication()->getServiceManager()->get("FrontCore\\Events\\FrontCoreEvents"); $eventsFrontCore->registerEvents(); $eventsSystemForms = $e->getApplication()->getServiceManager()->get("FrontCore\\Events\\FrontCoreSystemFormEvents"); $eventsSystemForms->registerEvents(); //append app config to layout //load config $arr_config = $e->getApplication()->getServiceManager()->get("config"); $e->getViewModel()->setVariable("app_config", $arr_config); $e->getViewModel()->setVariable("cdn_url", $arr_config["cdn_config"]["url"]); /** * Check if user is logged in */ $sharedEvents = $eventManager->getSharedManager(); $sharedEvents->attach("*", 'dispatch', function ($e) { // fired when an ActionController under the namespace is dispatched. $controller = $e->getTarget(); //first check if user needs to be logged in if ($e->getRouteMatch()->getParam("user-bypass-login") === TRUE) { return; } //end if $arr_exclude_controllers = array("FrontUserLogin\\Controller\\IndexController"); //check for cli requests if (get_class($controller) == "FrontCLI\\Controller\\IndexController") { //check if module is activated $objModuleManager = $e->getApplication()->getServiceManager()->get('ModuleManager'); $arr_modules = $objModuleManager->getLoadedModules(); if (array_key_exists("FrontCLI", $arr_modules)) { return; } //end if } //end if if (strtolower(substr(get_class($controller), 0, 5)) == "front" && !in_array(get_class($controller), $arr_exclude_controllers) || strtolower($e->getRouteMatch()->getMatchedRouteName()) == "home") { //check if user is logged in if (!FrontUserSession::isLoggedIn()) { //redirect to login screen and set message $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger(); $flashMessenger->addInfoMessage("Please login to continue"); //redirect back to login page $target = $e->getTarget(); if (strtolower($e->getRouteMatch()->getMatchedRouteName()) == "home") { //home page, access service manager differently from event $serviceLocator = $target->getServiceManager(); } else { $serviceLocator = $target->getServiceLocator(); } //end if $url = $e->getRouter()->assemble(array("controller" => "FrontUserLogin\\Controller\\IndexController"), array('name' => 'front-user-login')); $response = $e->getResponse(); $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url)); $response->setStatusCode(302); $response->sendHeaders(); exit; } //end if } //end if }, 110); /** * Deal with flash messages that needs to be passed to the layout view */ $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER, function ($e) { $flashMessenger = new \Zend\Mvc\Controller\Plugin\FlashMessenger(); if ($flashMessenger->hasMessages()) { $e->getViewModel()->setVariable('flashMessages', $flashMessenger->getMessages()); } //end if if ($flashMessenger->hasErrorMessages()) { $e->getViewModel()->setVariable('flashMessages_errors', $flashMessenger->getErrorMessages()); } //end if if ($flashMessenger->hasInfoMessages()) { $e->getViewModel()->setVariable('flashMessages_info', $flashMessenger->getInfoMessages()); } //end if if ($flashMessenger->hasSuccessMessages()) { $e->getViewModel()->setVariable('flashMessages_success', $flashMessenger->getSuccessMessages()); } //end if }); /** * Log api calls */ if (isset($_GET["debug_display_errors"]) && $_GET["debug_display_errors"] == 1 || isset($_GET["debug_display_queries"]) && $_GET["debug_display_queries"] == 1) { //get shared event manager $sem = $e->getApplication()->getEventManager()->getSharedManager(); $sem->attach("*", "apiCallExecuted", function ($event) use($e) { $objApiData = $event->getParam("objApiData"); $objResponse = $event->getParam("objResponse"); $objApiData->rawResponse = $objResponse->getBody(); if (isset($_GET["debug_display_errors"]) && $_GET["debug_display_errors"] == 1) { $url = $objApiData->url; $response = $objApiData->rawResponse; $arr = $e->getViewModel()->getVariable("api_logs"); $arr[] = $objApiData; $arr[] = $response; $e->getViewModel()->setVariable("api_logs", $arr); } //end if }); } //end if /** * Start session */ session_start(); //load icon packs $this->setIconPacks(); }