php Zend-Mvc-ModuleRouteListener类(方法)实例源码

下面列出了php Zend-Mvc-ModuleRouteListener 类(方法)源码代码实例,从而了解它的用法。

作者:vrkansagar    项目:zf-we   
public function onBootstrap($e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'rotateXPoweredByHeader'));
 }

作者:highestgoodlikewate    项目:php-kanba   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $this->setPhpSettings($e);
 }

作者:agerecompan    项目:zfc-bloc   
public function onBootstrap($e)
 {
     $e->getApplication()->getServiceManager()->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }

作者:whoopl    项目:magento2-testin   
/**
  * {@inheritdoc}
  */
 public function onBootstrap(EventInterface $e)
 {
     /** @var \Zend\Mvc\MvcEvent $e */
     /** @var \Zend\Mvc\Application $application */
     $application = $e->getApplication();
     /** @var \Zend\EventManager\EventManager $events */
     $events = $application->getEventManager();
     /** @var \Zend\EventManager\SharedEventManager $sharedEvents */
     $sharedEvents = $events->getSharedManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($events);
     // Override Zend\Mvc\View\Http\InjectTemplateListener
     // to process templates by Vendor/Module
     $injectTemplateListener = new InjectTemplateListener();
     $sharedEvents->attach('Zend\\Stdlib\\DispatchableInterface', MvcEvent::EVENT_DISPATCH, [$injectTemplateListener, 'injectTemplate'], -89);
     $response = $e->getResponse();
     if ($response instanceof \Zend\Http\Response) {
         $headers = $response->getHeaders();
         if ($headers) {
             $headers->addHeaderLine('Cache-Control', 'no-cache, no-store, must-revalidate');
             $headers->addHeaderLine('Pragma', 'no-cache');
             $headers->addHeaderLine('Expires', '1970-01-01');
         }
     }
 }

作者:ricer    项目:MvitInvoic   
public function onBootstrap(MvcEvent $e)
 {
     $e->getApplication()->getServiceManager()->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // Add translation
     $translator = $e->getApplication()->getServiceManager()->get('translator');
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $setLang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
     } else {
         $setLang = '';
     }
     $translator->setLocale(\Locale::acceptFromHttp($setLang))->setFallbackLocale('en_US');
     // Add ACL information to the Navigation view helper
     $sm = $e->getApplication()->getServiceManager();
     $authorize = $sm->get('BjyAuthorize\\Service\\Authorize');
     $acl = $authorize->getAcl();
     $role = $authorize->getIdentity();
     \Zend\View\Helper\Navigation::setDefaultAcl($acl);
     \Zend\View\Helper\Navigation::setDefaultRole($role);
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Application', 'dispatch.error', function ($e) use($sm) {
         if ($e->getParam('exception')) {
             $sm->get('Zend\\Log\\Logger')->crit($e->getParam('exception'));
         }
     });
 }

作者:ledsincloud    项目:RestServerDem   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // Listeners to ensure that we always send back JSON.
     // If we set a 404 in the ViewModel, then the RouteNotFoundStrategy will add it's own
     // fields to the ViewModel, so detect a 404 first and respond to it
     $eventManager->getSharedManager()->attach('Zend\\Stdlib\\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($this, 'detect404'), -89);
     // Ensure we always render JSON
     $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'ensureJsonModel'), 999);
     // Turn errors into JSON
     // $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'renderError'));
     //*********Session
     $sm = $e->getApplication()->getServiceManager();
     $config = $sm->get('session_config');
     $storage = null;
     if ($sm->has('session_storage', false)) {
         $storage = $sm->get('session_storage');
     }
     $saveHandler = null;
     if ($sm->has('session_save_handler', false)) {
         $saveHandler = $sm->get('session_save_handler');
     }
     $sessionManager = new SessionManager($config, $storage, $saveHandler);
     Container::setDefaultManager($sessionManager);
     //$sessionManager->start();
 }

作者:im286e    项目:en   
public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $eventManager = $app->getEventManager();
     $locator = $app->getServiceManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $this->initFirePHP();
     $this->initAuthentication();
     // 微软这个流氓,低于IE10版本一下的IE浏览器都需要使用text/html格式的Response,否则json在浏览器中会提示下载
     $eventManager->attach(MvcEvent::EVENT_RENDER, function ($event) {
         $objResponse = $event->getResponse();
         if (method_exists($objResponse, 'getHeaders')) {
             $objHeaders = $objResponse->getHeaders();
             $contentType = $objHeaders->get('Content-Type');
             if ($contentType) {
                 $contentType = $contentType->getFieldValue();
                 if (strpos($contentType, 'application/json') !== false) {
                     $objHeaders->addHeaderLine('Content-Type', 'text/html;charset=utf-8');
                 }
             } else {
                 $objHeaders->addHeaderLine('Content-Type', 'text/html;charset=utf-8');
             }
         }
     }, -10000);
     // 错误提示的时候,执行特殊的layout
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) {
         $viewModel = $event->getViewModel();
         $viewModel->setTemplate('layout/error');
     }, -200);
 }

作者:khusamo    项目:leadin   
public function onBootstrap($e)
 {
     \Zend\Validator\AbstractValidator::setDefaultTranslator($e->getApplication()->getServiceManager()->get('translator'));
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }

作者:arb    项目:MyCod   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $eventManager->attach(MvcEvent::EVENT_ROUTE, [$this, 'onViewHelper']);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $routeMatch = $e->getRouteMatch();
         $apartmentId = $routeMatch->getParam('apartment_id', 0);
         // get the apartment ID
         if (method_exists($controller, 'setApartmentID')) {
             $serviceManager = $e->getApplication()->getServiceManager();
             $dbAdapter = $serviceManager->get('Zend\\Db\\Adapter\\Adapter');
             $apartmentExistValidator = new RecordExists(['adapter' => $dbAdapter, 'table' => DbTables::TBL_APARTMENTS, 'field' => 'id']);
             if (!$apartmentExistValidator->isValid($apartmentId) && $apartmentId != 0) {
                 $url = $e->getRouter()->assemble(array('controller' => 'apartment', 'action' => 'search'), ['name' => 'apartments']);
                 $response = $e->getResponse();
                 $response->getHeaders()->addHeaderLine('Location', $url);
                 $response->setStatusCode(302);
                 $response->sendHeaders();
                 return $response;
             }
             $controller->setApartmentID($apartmentId);
         }
     }, 100);
 }

作者:bmatmente    项目:zf2-prope   
public function onBootstrap($e)
 {
     $session = $e->getApplication()->getServiceManager()->get('session');
     if (isset($session->lang)) {
         $translator = $e->getApplication()->getServiceManager()->get('translator');
         $translator->setLocale($session->lang);
         $viewModel = $e->getViewModel();
         $viewModel->lang = str_replace('_', '-', $session->lang);
     }
     $eventManager = $e->getApplication()->getEventManager();
     $eventManager->attach('route', function ($e) {
         $lang = $e->getRouteMatch()->getParam('lang');
         // If there is no lang parameter in the route, nothing to do
         if (empty($lang)) {
             return;
         }
         $services = $e->getApplication()->getServiceManager();
         // If the session language is the same, nothing to do
         $session = $services->get('session');
         if (isset($session->lang) && $session->lang == $lang) {
             return;
         }
         $viewModel = $e->getViewModel();
         $translator = $services->get('translator');
         $viewModel->lang = $lang;
         $lang = str_replace('-', '_', $lang);
         $translator->setLocale($lang);
         $session->lang = $lang;
     }, -10);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }

作者:BreyndotEchs    项目:mtg-bo   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     AnnotationRegistry::registerAutoloadNamespace('TgBotApi\\Model\\Annotation');
 }

作者:tine    项目:webapoyopublicitari   
public function onBootstrap($e)
 {
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $config = $e->getApplication()->getServiceManager()->get('config');
         if (isset($config['module_layouts'][$moduleNamespace])) {
             $controller->layout($config['module_layouts'][$moduleNamespace]);
         }
     }, 100);
     $session = new Container('base');
     if (!$session->offsetExists('language')) {
         if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "es") {
             $session->offsetSet('language', "es_ES");
         } elseif (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == "en") {
             $session->offsetSet('language', "en_US");
         }
     }
     $e->getApplication()->getServiceManager()->get('translator')->setLocale($session->offsetGet('language'));
     $e->getApplication()->getServiceManager()->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }

作者:aiolo    项目:halte   
public function onBootstrap(MvcEvent $event)
 {
     Json::$useBuiltinEncoderDecoder = true;
     $eventManager = $event->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }

作者:middleou    项目:doplio-zf   
/**
  * @param MvcEvent $event
  */
 public function onBootstrap(MvcEvent $event)
 {
     $eventManager = $event->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $app = $event->getApplication();
     $serviceManager = $app->getServiceManager();
     // Set the Query Profiler
     $profiler = new DoplioFirePhpProfiler();
     $capsule = new Capsule();
     $config = $serviceManager->get('config')['database'];
     foreach ($config as $connName => $dbConfig) {
         $capsule->addConnection($dbConfig, $connName);
         if (isset($dbConfig['profiler']) && $dbConfig['profiler'] === TRUE) {
             $profiler->enable();
         }
     }
     //        $capsule->setCacheManager();
     $capsule->bootEloquent();
     $serviceManager->setService('Doplio', $capsule);
     $serviceManager->setService('DoplioFirePhpProfiler', $profiler);
     $eventManager->attach(MvcEvent::EVENT_FINISH, function () use($capsule, $config, $profiler) {
         if ($profiler->isDisabled()) {
             return;
         }
         foreach ($config as $connectionName => $notUsed) {
             $connection = $capsule->getConnection($connectionName);
             foreach ($connection->getQueryLog() as $query) {
                 $profiler->addQuery($query, $connectionName);
             }
         }
         $profiler->showTables();
     });
 }

作者:bladehr    项目:bowhunter201   
public function onBootstrap(MvcEvent $e)
 {
     /*
             $eventManager        = $e->getApplication()->getEventManager();
             $moduleRouteListener = new ModuleRouteListener();
             $moduleRouteListener->attach($eventManager);
     
     $this->initSession(array(
     'remember_me_seconds' => 180,
     'use_cookies' => true,
     'cookie_httponly' => true,
     ));
     */
     $eventManager = $e->getApplication()->getEventManager();
     $eventManager->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $config = $e->getApplication()->getServiceManager()->get('config');
         //echo '<pre>'; print_r($config);exit;
         if (isset($config['module_layouts'][$moduleNamespace])) {
             $controller->layout($config['module_layouts'][$moduleNamespace]);
         }
     }, 100);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $this->initSession(array('remember_me_seconds' => 180, 'use_cookies' => true, 'cookie_httponly' => true));
 }

作者:klaid8    项目:m   
public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $eventManager = $app->getEventManager();
     $serviceLocator = $app->getServiceManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $serviceManager = $e->getApplication()->getServiceManager();
     $eventManager->attachAggregate($serviceLocator->get('Listener.ExceptionStrategy'));
     $eventManager->attach(MvcEvent::EVENT_DISPATCH_ERROR, function (MvcEvent $event) use($serviceManager) {
         $exception = $event->getParam('exception');
         if ($exception) {
             do {
                 $serviceManager->get('Logger')->crit(sprintf("%s:%d %s (%d) [%s]\n", $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getCode(), get_class($exception)));
             } while ($ex = $exception->getPrevious());
             $response = $event->getResponse();
             //				$response->setHeaders(
             //					$response->getHeaders()->addHeaderLine('Location', "/error-page")
             //				);
             $response->setStatusCode(302);
             $response->sendHeaders();
             return $response;
         }
     });
 }

作者:old-town-la    项目:cr   
/**
  * @param EventInterface $e
  *
  * @return array|void
  *
  * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
  */
 public function onBootstrap(EventInterface $e)
 {
     /** @var MvcEvent $e */
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }

作者:zourc    项目:zourc   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $serviceManager = $e->getApplication()->getServiceManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     if (!Console::isConsole()) {
         $viewHelperManager = $serviceManager->get('ViewHelperManager');
         $formElementErrors = $viewHelperManager->get('formElementErrors');
         $formElementErrors->setMessageOpenFormat('<div class="zui-error">');
         $formElementErrors->setMessageSeparatorString('</div><div class="zui-error">');
         $formElementErrors->setMessageCloseString('</div>');
         $flashMessenger = $viewHelperManager->get('flashMessenger');
         $flashMessenger->setMessageOpenFormat('<div class="zui-alert zui-alert-%s"><p>');
         $flashMessenger->setMessageSeparatorString('</p><p>');
         $flashMessenger->setMessageCloseString('</p><span class="zui-icon zui-icon-x" role="button" tabindex="0"></span></div>');
         /** @var ManagerInterface $sessionManager */
         $sessionManager = $serviceManager->get(ManagerInterface::class);
         $sessionManager->start();
     }
     $helpers = $serviceManager->get('ViewHelperManager');
     $hal = $helpers->get('Hal');
     $hal->getEventManager()->attach('renderCollection.post', [$this, 'onRenderCollection']);
     $hal->getEventManager()->attach('renderEntity.post', [$this, 'onRenderEntity']);
 }

作者:parnust    项目:lisbacken   
/**
  * 
  * @param MvcEvent $e
  */
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach('render', [$this, 'registerJsonStrategy'], 100);
 }

作者:OnlineBidde    项目:onlineBidde   
public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $eventManager->attach(MvcEvent::EVENT_ROUTE, array($this, 'initLocale'), 1);
 }


问题


面经


文章

微信
公众号

扫码关注公众号