当前位置: 首页>>代码示例>>PHP>>正文


PHP Mvc\MvcEvent类代码示例

本文整理汇总了PHP中Zend\Mvc\MvcEvent的典型用法代码示例。如果您正苦于以下问题:PHP MvcEvent类的具体用法?PHP MvcEvent怎么用?PHP MvcEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MvcEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isOpenRequest

 public function isOpenRequest(MvcEvent $e)
 {
     if ($e->getRouteMatch()->getParam('controller') == 'SanAuthWithDbSaveHandler\\Controller\\AuthController') {
         return true;
     }
     return false;
 }
开发者ID:yassine-be,项目名称:SanAuthWithDbSaveHandler,代码行数:7,代码来源:Module.php

示例2: onBootstrap

 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);
 }
开发者ID:im286er,项目名称:ent,代码行数:31,代码来源:Module.php

示例3: initLocale

 public function initLocale(MvcEvent $e)
 {
     //Получаем объект translator'a
     $translator = $e->getApplication()->getServiceManager()->get('translator');
     $translator->setLocale('ru_RU');
     // ru_RU, en_US, etc...
 }
开发者ID:OnlineBidder,项目名称:onlineBidder,代码行数:7,代码来源:Module.php

示例4: boforeDispatch

 function boforeDispatch(MvcEvent $event)
 {
     include 'config/constant.php';
     $response = $event->getResponse();
     $controller = $event->getRouteMatch()->getParam('controller');
     $module_array = explode("\\", $controller);
     if ($module_array[0] == 'Admin') {
         $action = $event->getRouteMatch()->getParam('action');
         $requestedResourse = $controller . "\\" . $action;
         $session = new Container('User');
         if ($session->offsetExists('user')) {
             if (in_array($requestedResourse, $GLOBALS['PAGE_BEFORE_LOGIN'])) {
                 $url = $GLOBALS['SITE_ADMIN_URL'] . 'dashboard/add';
                 $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
                 $response->setStatusCode(302);
             }
         } else {
             if ($requestedResourse != 'Admin\\Controller\\Index\\index' && !in_array($requestedResourse, $GLOBALS['PAGE_BEFORE_LOGIN'])) {
                 $url = $GLOBALS['SITE_ADMIN_URL'] . 'index/login';
                 $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
                 $response->setStatusCode(302);
             }
             $response->sendHeaders();
         }
     }
 }
开发者ID:schoolMsoftware,项目名称:schoolm,代码行数:26,代码来源:Module.php

示例5: renderRequest

 /**
  * @param MvcEvent $event
  */
 public function renderRequest(MvcEvent $event)
 {
     /** @var Response $zendResponse */
     $zendResponse = $event->getResponse();
     $zendResponse->send();
     $event->stopPropagation();
 }
开发者ID:ftdebugger,项目名称:react-zf2,代码行数:10,代码来源:Application.php

示例6: onError

 /**
  * Handles redirects in case of dispatch errors caused by unauthorized access
  *
  * @param MvcEvent $event
  * @return void
  */
 public function onError(MvcEvent $event)
 {
     if (!$event->getRequest() instanceof HttpRequest || !($routeMatch = $event->getRouteMatch())) {
         return;
     }
     if (null === $this->redirectUri) {
         if (null === $this->redirectRoute) {
             if ($this->authenticationService->hasIdentity()) {
                 $this->setRedirectRoute($this->options->getAuthenticatedIdentityRedirectRoute());
             } else {
                 $this->setRedirectRoute($this->options->getUnauthenticatedIdentityRedirectRoute());
             }
         }
         if (!($this->redirectRoute && $this->redirectRoute !== $routeMatch->getMatchedRouteName())) {
             return parent::onError($event);
         }
         $params = ['name' => $this->redirectRoute];
         if ($this->options->getUseRedirectParameter()) {
             $redirectKey = $this->options->getRedirectKey();
             $params['query'][$redirectKey] = $event->getRequest()->getUriString();
         }
         $this->setRedirectUri($event->getRouter()->assemble([], $params));
     }
     $response = $event->getResponse() ?: new HttpResponse();
     $response->getHeaders()->addHeaderLine('Location', $this->redirectUri);
     $response->setStatusCode(302);
     $event->setResponse($response);
 }
开发者ID:coolms,项目名称:authorization,代码行数:34,代码来源:RedirectStrategy.php

示例7: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $events = $app->getEventManager();
     $services = $app->getServiceManager();
     $events->attach($services->get('ZF\\ContentValidation\\ContentValidationListener'));
 }
开发者ID:nastron,项目名称:zf-content-validation,代码行数:7,代码来源:Module.php

示例8: onDispatch

 public function onDispatch(MvcEvent $e)
 {
     /** @var ConsoleRequest $request */
     $request = $this->getRequest();
     $queueName = $request->getParam('queueName');
     $messageId = $request->getParam('messageId');
     if (!isset($this->config[$queueName])) {
         echo "Bad queue name: " . $queueName;
         return;
     }
     $this->queueConfig = $this->config[$queueName];
     $this->debug("Queue name: " . $queueName);
     $this->debug("Message Id: " . $messageId);
     /** @var QueueMessage $message */
     $message = $this->messageRepository->findById($messageId);
     /** @var WorkerInterface $handler */
     $handler = $this->getServiceLocator()->get($this->queueConfig['handler']);
     $message->setProcessed();
     $this->messageRepository->add($message);
     try {
         $handler->handle($message->getMessage());
     } catch (\Exception $e) {
         $message->setFailed($e->getMessage());
         $this->messageRepository->add($message);
     }
     $message->setCompleted();
     $this->messageRepository->add($message);
     $this->debug("done");
 }
开发者ID:t4web,项目名称:queue,代码行数:29,代码来源:Worker.php

示例9: testOnRenderErrorCreatesAnApiProblemResponse

 public function testOnRenderErrorCreatesAnApiProblemResponse()
 {
     $response = new Response();
     $request = new Request();
     $request->getHeaders()->addHeaderLine('Accept', 'application/json');
     $event = new MvcEvent();
     $event->setError(Application::ERROR_EXCEPTION);
     $event->setRequest($request);
     $event->setResponse($response);
     $this->listener->onRenderError($event);
     $this->assertTrue($event->propagationIsStopped());
     $this->assertSame($response, $event->getResponse());
     $this->assertEquals(406, $response->getStatusCode());
     $headers = $response->getHeaders();
     $this->assertTrue($headers->has('Content-Type'));
     $this->assertEquals('application/problem+json', $headers->get('content-type')->getFieldValue());
     $content = json_decode($response->getContent(), true);
     $this->assertArrayHasKey('status', $content);
     $this->assertArrayHasKey('title', $content);
     $this->assertArrayHasKey('describedBy', $content);
     $this->assertArrayHasKey('detail', $content);
     $this->assertEquals(406, $content['status']);
     $this->assertEquals('Not Acceptable', $content['title']);
     $this->assertContains('www.w3.org', $content['describedBy']);
     $this->assertContains('accept', $content['detail']);
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:26,代码来源:RenderErrorListenerTest.php

示例10: bootstrapSession

 /**
  * Bootstrap session
  *
  * @param MvcEvent $event
  */
 private function bootstrapSession(MvcEvent $event)
 {
     $session = $event->getApplication()->getServiceManager()->get('Zend\\Session\\SessionManager');
     $session->start();
     $container = new Container('initialized');
     if (!isset($container->init)) {
         $serviceManager = $event->getApplication()->getServiceManager();
         $request = $event->getRequest();
         $session->regenerateId();
         $container->init = 1;
         $container->remoteAddr = $request->getServer()->get('REMOTE_ADDR');
         $container->httpUserAgent = $request->getServer()->get('HTTP_USER_AGENT');
         $config = $serviceManager->get('Config');
         if (!isset($config['session'])) {
             return;
         }
         $sessionConfig = $config['session'];
         if (isset($sessionConfig['validators'])) {
             $chain = $session->getValidatorChain();
             foreach ($sessionConfig['validators'] as $validator) {
                 switch ($validator) {
                     case 'Zend\\Session\\Validator\\HttpUserAgent':
                         $validator = new $validator($container->httpUserAgent);
                         break;
                     case 'Zend\\Session\\Validator\\RemoteAddr':
                         $validator = new $validator($container->remoteAddr);
                         break;
                     default:
                         $validator = new $validator();
                 }
                 $chain->attach('session.validate', array($validator, 'isValid'));
             }
         }
     }
 }
开发者ID:jolicht,项目名称:apigility-authentication-frontend,代码行数:40,代码来源:Module.php

示例11: setTitleAndTranslation

 /**
  * Handle layout titles onDispatch.
  *
  * @param MvcEvent $event
  */
 public function setTitleAndTranslation(MvcEvent $event)
 {
     $route = $event->getRouteMatch();
     $title = $this->service->get('ControllerPluginManager')->get('systemsettings');
     $viewHelper = $this->service->get('ViewHelperManager');
     $lang = new Container('translations');
     $translator = $this->service->get('translator');
     /*
      * Load translations.
      */
     $renderer = $this->service->get('ViewManager')->getRenderer();
     $renderer->plugin('formRow')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formCollection')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formLabel')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formSelect')->setTranslator($translator, 'SD_Translations');
     $renderer->plugin('formSubmit')->setTranslator($translator, 'SD_Translations');
     AbstractValidator::setDefaultTranslator($translator, 'formandtitle');
     $translator->setLocale($lang->offsetGet('languageName'))->setFallbackLocale('en');
     $viewModel = $event->getViewModel();
     $viewModel->setVariable('lang', $translator->getLocale());
     /*
      * Custom flash messenger.
      */
     $msg = $lang->offsetGet('flashMessages');
     $viewModel->setVariable('flashMessages', $msg);
     /*
      * Load page title
      */
     $action = $route->getParam('post') ? ' - ' . $route->getParam('post') : ucfirst($route->getParam('__CONTROLLER__'));
     $headTitleHelper = $viewHelper->get('headTitle');
     $headTitleHelper->append($title->__invoke('general', 'site_name') . ' ' . $action);
 }
开发者ID:samsonasik,项目名称:unnamed,代码行数:37,代码来源:Module.php

示例12: setTemplate

 public function setTemplate(MvcEvent $e)
 {
     $result = $e->getResult();
     $router = $e->getRouteMatch();
     $params = $router->getParams();
     if (isset($params['__NAMESPACE__']) && isset($params['__CONTROLLER__']) && isset($params['action'])) {
         $controllerClass = $params['__NAMESPACE__'];
         $moduleNamespace = substr($controllerClass, strpos($controllerClass, '\\'));
         $moduleNamespace = substr($moduleNamespace, 1);
         $moduleNamespace = substr($moduleNamespace, 0, strpos($moduleNamespace, '\\Controller'));
         $templatePath = __DIR__;
         $config = $e->getApplication()->getServiceManager()->get('config');
         if (isset($config['view_manager']['template_map'])) {
             $moduleNamespace = strtolower($moduleNamespace . '/' . $params['__CONTROLLER__']);
             $templatePath = $templatePath . '/view/' . $moduleNamespace . '/' . $params['action'] . '.phtml';
             $moduleNamespace = str_replace('\\', '/', $moduleNamespace);
             $template = $moduleNamespace . '/' . $params['action'];
             $config['view_manager']['template_map'][$template] = $templatePath;
             $result->setTemplate($template);
         }
         //set Title;
         if (isset($config['view_manager']['siteName'])) {
             $siteName = $config['view_manager']['siteName'];
         } else {
             $siteName = $moduleNamespace;
         }
         $viewHelperManager = $e->getApplication()->getServiceManager()->get('viewHelperManager');
         $headTitle = $viewHelperManager->get('headTitle');
         $headTitle->setSeparator(' - ');
         $headTitle->append($params['action']);
         $headTitle->append($siteName);
     }
 }
开发者ID:ruby-project,项目名称:ruby-admin,代码行数:33,代码来源:Module.php

示例13: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $eventManager->getSharedManager()->attach('Applications', 'application.detail.actionbuttons', function ($event) {
         return 'pdf/application/details/button';
     });
 }
开发者ID:utrenkner,项目名称:YAWIK,代码行数:7,代码来源:Module.php

示例14: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $e->getApplication()->getServiceManager()->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }
开发者ID:patkings,项目名称:ejemploZF2,代码行数:7,代码来源:Module.php

示例15: onRoute

 /**
  * Listen to the "route" event and determine if the module namespace should
  * be prepended to the controller name.
  *
  * If the route match contains a parameter key matching the MODULE_NAMESPACE
  * constant, that value will be prepended, with a namespace separator, to
  * the matched controller parameter.
  *
  * @param  MvcEvent $e
  * @return null
  */
 public function onRoute($e)
 {
     $matches = $e->getRouteMatch();
     if (!$matches instanceof Router\RouteMatch) {
         // Can't do anything without a route match
         return;
     }
     $module = $matches->getParam(self::MODULE_NAMESPACE, false);
     if (!$module) {
         // No module namespace found; nothing to do
         return;
     }
     $controller = $matches->getParam('controller', false);
     if (!$controller) {
         // no controller matched, nothing to do
         return;
     }
     // Ensure the module namespace has not already been applied
     if (0 === strpos($controller, $module)) {
         return;
     }
     // Keep the originally matched controller name around
     $matches->setParam(self::ORIGINAL_CONTROLLER, $controller);
     // Prepend the controllername with the module, and replace it in the
     // matches
     $controller = $module . '\\' . $controller;
     $matches->setParam('controller', $controller);
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:39,代码来源:ModuleRouteListener.php


注:本文中的Zend\Mvc\MvcEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。