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


PHP MvcEvent::stopPropagation方法代码示例

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


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

示例1: handleRestApiError

 public function handleRestApiError(MvcEvent $e)
 {
     if (array_key_exists('exception', $e->getParams())) {
         $exception = $e->getParams()['exception'];
         if ($exception instanceof RestApiException) {
             $e->stopPropagation();
             $response = $e->getResponse();
             $response->setStatusCode('400');
             $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
             $adapter = new Json();
             $errorData = $exception->getErrorData();
             $original = $exception->getOriginal();
             $count = 0;
             while ($original instanceof \Exception) {
                 $errorData['previous-' . $count] = $original->getMessage() . '/' . $original->getFile() . '/' . $original->getLine();
                 $original = $original->getPrevious();
                 $count++;
             }
             $response->setContent($adapter->serialize($errorData));
             $response->sendHeaders();
             $response->sendContent();
             exit;
         }
     }
 }
开发者ID:dsi-agpt,项目名称:minibus,代码行数:25,代码来源:Module.php

示例2: onDispatchError

 /**
  * Get the exception and optionally set status code, reason message and additional errors
  *
  * @internal
  * @param  MvcEvent $event
  * @return void
  */
 public function onDispatchError(MvcEvent $event)
 {
     $exception = $event->getParam('exception');
     if (isset($this->exceptionMap[get_class($exception)])) {
         $exception = $this->createHttpException($exception);
     }
     // We just deal with our Http error codes here !
     if (!$exception instanceof HttpExceptionInterface || $event->getResult() instanceof HttpResponse) {
         return;
     }
     // We clear the response for security purpose
     $response = new HttpResponse();
     $response->getHeaders()->addHeaderLine('Content-Type', 'application/json');
     $exception->prepareResponse($response);
     // NOTE: I'd like to return a JsonModel instead, and let ZF handle the request, but I couldn't make
     // it work because for unknown reasons, the Response get replaced "somewhere" in the MVC workflow,
     // so the simplest is simply to do that
     $content = ['status_code' => $response->getStatusCode(), 'message' => $response->getReasonPhrase()];
     if ($errors = $exception->getErrors()) {
         $content['errors'] = $errors;
     }
     $response->setContent(json_encode($content));
     $event->setResponse($response);
     $event->setResult($response);
     $event->stopPropagation(true);
 }
开发者ID:omusico,项目名称:zfr-rest,代码行数:33,代码来源:HttpExceptionListener.php

示例3: checkDomain

 /**
  * Check the domain is a known domain for the CMS.  If not the primary, it will
  * redirect the user to the primary domain.  Useful for multiple domain sites.
  *
  * @param MvcEvent $event Zend MVC Event
  *
  * @return null|Response
  */
 public function checkDomain(MvcEvent $event)
 {
     if ($this->isConsoleRequest()) {
         return null;
     }
     $currentDomain = $this->siteService->getCurrentDomain();
     $site = $this->siteService->getCurrentSite($currentDomain);
     $redirectUrl = $this->domainRedirectService->getSiteNotAvailableRedirectUrl($site);
     if (!$site->isSiteAvailable() && empty($redirectUrl)) {
         $response = new Response();
         $response->setStatusCode(404);
         $event->stopPropagation(true);
         return $response;
     }
     if ($redirectUrl) {
         $response = new Response();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', '//' . $redirectUrl);
         $event->stopPropagation(true);
         return $response;
     }
     $redirectUrl = $this->domainRedirectService->getPrimaryRedirectUrl($site);
     if ($redirectUrl) {
         $response = new Response();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', '//' . $redirectUrl);
         $event->stopPropagation(true);
         return $response;
     }
     return null;
 }
开发者ID:reliv,项目名称:Rcm,代码行数:39,代码来源:RouteListener.php

示例4: postRoute

 public function postRoute(MvcEvent $event)
 {
     // we want to test only parsing of arguments and routing.
     // No real dispatching is needed here
     $event->stopPropagation(true);
     return $event->getResponse()->setContent("stopped");
 }
开发者ID:alexb-uk,项目名称:ZendServerSDK,代码行数:7,代码来源:ArgumentsControllerTest.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: checkAuthentication

 public function checkAuthentication(MvcEvent $event)
 {
     if ($event->getRequest() instanceof ConsoleResquest) {
         return;
     }
     $routename = $event->getRouteMatch()->getMatchedRouteName();
     // TODO mettre en conf
     if ($routename == 'zfcuser/login' || $routename == 'zfcuser/logout' || $routename == 'execution') {
         return;
     }
     $zfcUser = $this->getServiceLocator()->get('zfcuser_auth_service');
     $config = $this->getServiceLocator()->get('Config');
     $authorized = false;
     if ($zfcUser->hasIdentity()) {
         $authorized = $this->getFileAuthService()->checkAutorisation($zfcUser->getIdentity()->getUserName(), $routename);
     }
     if (!$zfcUser->hasIdentity() || true !== $authorized) {
         $url = $event->getRouter()->assemble(array(), array('name' => 'zfcuser/login'));
         $response = $event->getResponse();
         $response->getHeaders()->addHeaderLine('Location', $url);
         $response->setStatusCode(302);
         $response->sendHeaders();
         $stopCallBack = function ($event) use($response) {
             $event->stopPropagation();
             return $response;
         };
         $event->getApplication()->getEventManager()->attach(MvcEvent::EVENT_ROUTE, $stopCallBack, -10000);
         return $response;
     }
 }
开发者ID:dsi-agpt,项目名称:minibus,代码行数:30,代码来源:ZfcUserRedirectionListener.php

示例7: doAuthentication

 public function doAuthentication(MvcEvent $event)
 {
     if (!$event->getRequest() instanceof Request) {
         return;
     }
     $application = $event->getApplication();
     $sm = $application->getServiceManager();
     $match = $event->getRouteMatch();
     $controller = $match->getParam('controller');
     $action = $match->getParam('action');
     $plugin = $sm->get('ControllerPluginManager')->get('IsAllowed');
     $hasIdentity = $plugin->getIdentity();
     if (!$plugin->isAllowed($controller, $action)) {
         $router = $event->getRouter();
         $url = $router->assemble([], ['name' => 'guest' === $hasIdentity->getRoleId() ? 'user' : 'home']);
         $response = $event->getResponse();
         $response->setStatusCode(302);
         //redirect to login route...
         // change with header('location: '.$url); if code below not working
         $response->getHeaders()->addHeaderLine('Location', $url);
         $event->stopPropagation();
         return $response;
     }
     return;
 }
开发者ID:butkimtinh,项目名称:uthando-user,代码行数:25,代码来源:MvcListener.php

示例8: onRenderError

 /**
  * Handle rendering errors
  *
  * Rendering errors are usually due to trying to render a template in
  * the PhpRenderer, when we have no templates.
  *
  * As such, report as an unacceptable response.
  *
  * @param  MvcEvent $e
  */
 public function onRenderError(MvcEvent $e)
 {
     $response = $e->getResponse();
     $status = 406;
     $title = 'Not Acceptable';
     $describedBy = 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html';
     $detail = 'Your request could not be resolved to an acceptable representation.';
     $details = false;
     $exception = $e->getParam('exception');
     if ($exception instanceof \Exception && !$exception instanceof ViewExceptionInterface) {
         $code = $exception->getCode();
         if ($code >= 100 && $code <= 600) {
             $status = $code;
         } else {
             $status = 500;
         }
         $title = 'Unexpected error';
         $detail = $exception->getMessage();
         $details = ['code' => $exception->getCode(), 'message' => $exception->getMessage(), 'trace' => $exception->getTraceAsString()];
     }
     $payload = ['status' => $status, 'title' => $title, 'describedBy' => $describedBy, 'detail' => $detail];
     if ($details && $this->displayExceptions) {
         $payload['details'] = $details;
     }
     $response->getHeaders()->addHeaderLine('content-type', 'application/problem+json');
     $response->setStatusCode($status);
     $response->setContent(json_encode($payload));
     $e->stopPropagation();
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:39,代码来源:RenderErrorListener.php

示例9: onPreBootstrap

 public function onPreBootstrap(MvcEvent $e)
 {
     $application = $e->getApplication();
     $services = $application->getServiceManager();
     $events = $application->getEventManager();
     $config = $services->has('Config') ? $services->get('Config') : [];
     // Check Database connectivity
     if ($services->has('Zend\\Db\\Adapter\\Adapter')) {
         $adapter = $services->get('Zend\\Db\\Adapter\\Adapter');
         try {
             $adapter->getDriver()->getConnection()->connect();
         } catch (\Exception $ex) {
             $viewManagerConfig = $config['view_manager'] ? $config['view_manager'] : [];
             $response = $e->getResponse();
             $viewModel = $e->getViewModel();
             $template = isset($viewManagerConfig['service_unavailable_template']) ? $viewManagerConfig['service_unavailable_template'] : '503';
             $viewModel->setTemplate($template);
             if ($response instanceof HttpResponse) {
                 $response->setStatusCode(503);
             } elseif ($response instanceof ConsoleModel) {
                 $response->setErrorLevel(1);
             } else {
                 echo "Service Unavailable.";
                 exit(1);
             }
             $event = $e;
             $event->setResponse($response);
             $event->setTarget($application);
             $events->trigger(MvcEvent::EVENT_RENDER, $event);
             $events->trigger(MvcEvent::EVENT_FINISH, $event);
             $e->stopPropagation(true);
             exit(1);
         }
     }
     // Maintenance mode
     // Session Management
     if (!$services->has('Zend\\Session\\Config\\ConfigInterface')) {
         if (isset($config['session_config'])) {
             $services->setFactory('Zend\\Session\\ConfigInterface', 'Zend\\Session\\Service\\SessionConfigFactory');
         }
     }
     if (!$services->has('Zend\\Session\\Storage\\StorageInterface')) {
         if (isset($config['session_storage'])) {
             $services->setFactory('Zend\\Session\\StorageInterface', 'Zend\\Session\\Service\\StorageFactory');
         }
     }
     if (!$services->has('Zend\\Session\\SaveHandler\\SaveHandlerInterface')) {
         if ($services->has('Zend\\Db\\Adapter\\Adapter')) {
             $adapter = $services->get('Zend\\Db\\Adapter\\Adapter');
             $tableGateway = new TableGateway('sessions', $adapter);
             $options = new DbTableGatewayOptions();
             $sessionHandler = new DbTableGateway($tableGateway, $options);
             $services->setService('Zend\\Session\\SaveHandler\\SaveHandlerInterface', $sessionHandler);
         }
     }
     if (!$services->has('Zend\\Session\\ManagerInterface')) {
         $services->setFactory('Zend\\Session\\ManagerInterface', 'Zend\\Session\\Service\\SessionManagerFactory');
     }
 }
开发者ID:gambit-cms,项目名称:gambit-mvc,代码行数:59,代码来源:OnBootstrapListener.php

示例10: sendToUrl

 protected function sendToUrl(MvcEvent $e, $url)
 {
     $response = $e->getResponse();
     $response->getHeaders()->addHeaderLine('Location', $url);
     $response->setStatusCode($this->responseCode);
     $response->sendHeaders();
     return $e->stopPropagation();
 }
开发者ID:fousheezy,项目名称:auth,代码行数:8,代码来源:Base.php

示例11: terminateEvent

 protected function terminateEvent(MvcEvent $event, $error, \Exception $exception)
 {
     $eventManager = $event->getApplication()->getEventManager();
     $event->setError($error);
     $event->setParam('exception', $exception);
     $event->stopPropagation(true);
     $eventManager->trigger(MvcEvent::EVENT_DISPATCH_ERROR, $event);
 }
开发者ID:aerisweather,项目名称:ZfAuth,代码行数:8,代码来源:Module.php

示例12: handleLocale

 /**
  * Handle locale
  */
 public function handleLocale()
 {
     /** @var PhpRequest $request */
     $request = $this->mvcEvent->getRequest();
     $response = $this->mvcEvent->getResponse();
     $moduleOptions = $this->getModuleOptions();
     if (!$request instanceof PhpRequest || !$moduleOptions->isMultiLanguage()) {
         return null;
     }
     /** @var LocaleNameParserService $localeNameParserService */
     $localeNameParserService = $this->mvcEvent->getApplication()->getServiceManager()->get(LocaleNameParserService::class);
     try {
         $localeFromHost = $localeNameParserService->getLocaleFromHost();
         $this->setAppLocale($localeFromHost);
         if (!$moduleOptions->isMappedDomainRedirectable()) {
             return null;
         }
     } catch (LocaleNotFoundException $exception) {
         //no locale in host? Let's fond them somewhere else!
         $localeFromHost = null;
     }
     try {
         $localeFromPath = $localeNameParserService->getLocaleFromUriPath();
         $this->setAppLocale($localeFromPath);
         return null;
     } catch (LocaleNotFoundException $exception) {
         $localeFromPath = null;
     }
     if (is_null($localeFromPath) && !is_null($localeFromHost)) {
         return null;
     }
     //use browser locale
     try {
         $locale = $localeNameParserService->getLocaleFromBrowser();
     } catch (LocaleNotFoundException $exception) {
         $locale = $localeNameParserService->getDefaultLocale();
     }
     /** @var PhpResponse $response */
     $url = $localeNameParserService->getUrlForLocale($locale);
     $response->getHeaders()->addHeaderLine('Location', $url);
     $response->setStatusCode(PhpResponse::STATUS_CODE_302);
     $response->sendHeaders();
     $this->mvcEvent->stopPropagation(true);
     return $response;
 }
开发者ID:jakubigla,项目名称:zf-locale,代码行数:48,代码来源:LocaleListener.php

示例13: determineTtl

 /**
  * @inheritDoc
  */
 public function determineTtl(MvcEvent $e)
 {
     $viewModel = $e->getViewModel();
     $esiOptions = (array) $viewModel->getOption('esi', []);
     if (isset($esiOptions['ttl'])) {
         $this->setTtl($esiOptions['ttl']);
         $e->stopPropagation();
         return $this;
     }
 }
开发者ID:hummer2k,项目名称:convarnish,代码行数:13,代码来源:EsiStrategy.php

示例14: determineTtl

 /**
  * @inheritDoc
  */
 public function determineTtl(MvcEvent $e)
 {
     $policy = $this->varnishOptions->getPolicy();
     if ($policy === VarnishOptions::POLICY_ALLOW) {
         $this->setTtl($this->varnishOptions->getDefaultTtl());
     } else {
         $this->setTtl(0);
     }
     $e->stopPropagation();
     return $this;
 }
开发者ID:hummer2k,项目名称:convarnish,代码行数:14,代码来源:DefaultStrategy.php

示例15: determineTtl

 /**
  * @inheritDoc
  */
 public function determineTtl(MvcEvent $e)
 {
     $routeMatch = $e->getRouteMatch();
     $routeName = $routeMatch->getMatchedRouteName();
     $cacheableRoutes = $this->varnishOptions->getCacheableRoutes();
     $ttl = $this->getTtlFor($cacheableRoutes, $routeName);
     if (false !== $ttl) {
         $this->setTtl($ttl);
         $e->stopPropagation();
         return $this;
     }
 }
开发者ID:hummer2k,项目名称:convarnish,代码行数:15,代码来源:RouteStrategy.php


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