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


PHP MvcEvent::getRouteMatch方法代码示例

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


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

示例1: __invoke

 public function __invoke(MvcEvent $event)
 {
     if ($event->getRouteMatch()->getMatchedRouteName() === 'oauth/authorize' || $event->getRouteMatch()->getMatchedRouteName() === 'oauth/code') {
         $auth = $this->authentication;
         if (!$auth->hasIdentity()) {
             //redirect to login form before granting permissions - exception would be client_credentials grant type
             $url = $event->getRouter()->assemble([], array('name' => 'dotuser/login'));
             $host = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'on' ? 'https://' : 'http://';
             $host .= $_SERVER['HTTP_HOST'];
             $url = $host . $url . '?redirect=' . urlencode($event->getRequest()->getUriString());
             $response = $event->getResponse();
             $response->getHeaders()->addHeaderLine('Location', $url);
             $response->setStatusCode(302);
             $response->sendHeaders();
             exit;
         } else {
             $identity = $auth->getIdentity();
             $request = $event->getRequest();
             $client_id = $request->getQuery('client_id');
             //check to see if user already ganted permissions and is not revoked to skip the step and redirecting directly
             if ($event->getRouteMatch()->getMatchedRouteName() === 'oauth/authorize') {
                 if ($this->userRevokeStorage->isAuthorized($client_id, $identity->getUsername())) {
                     $newRequest = new \ZF\ContentNegotiation\Request();
                     $newRequest->setMethod(\Zend\Http\Request::METHOD_POST);
                     $newRequest->getPost()->set('authorized', 'yes');
                     $event->setRequest($newRequest);
                 }
             }
         }
     }
 }
开发者ID:n3vrax,项目名称:dotkernel,代码行数:31,代码来源:OauthRouteGuard.php

示例2: runControllerAction

 /**
  * @param $controllerName
  * @param $action
  * @param array $params
  * @return string|\Zend\Stdlib\ResponseInterface
  * @throws \Exception
  */
 public function runControllerAction($controllerName, $action, $params = array())
 {
     $this->event->getRouteMatch()->setParam('controller', $controllerName)->setParam('action', $action);
     foreach ($params as $key => $value) {
         $this->event->getRouteMatch()->setParam($key, $value);
     }
     $serviceManager = $this->event->getApplication()->getServiceManager();
     $controllerManager = $serviceManager->get('ControllerLoader');
     /** @var AbstractActionController $controller */
     $controller = $controllerManager->get($controllerName);
     $controller->setEvent($this->event);
     $result = $controller->dispatch($this->event->getRequest());
     if ($result instanceof Response) {
         return $result;
     }
     /** @var ViewManager $viewManager */
     $viewManager = $serviceManager->get('ViewManager');
     $renderingStrategy = $viewManager->getMvcRenderingStrategy();
     $this->event->setViewModel($result);
     /** @var ViewModel $result */
     if (!$result->terminate()) {
         $layout = new ViewModel();
         $layoutTemplate = $renderingStrategy->getLayoutTemplate();
         $layout->setTemplate($layoutTemplate);
         $layout->addChild($result);
         $this->event->setViewModel($layout);
     }
     $response = $renderingStrategy->render($this->event);
     return $response;
 }
开发者ID:steffendietz,项目名称:MaglLegacyApplication,代码行数:37,代码来源:ControllerService.php

示例3: boforeDispatch

 function boforeDispatch(MvcEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $target = $event->getTarget();
     /* Offline pages not needed authentication */
     $whiteList = array('Auth\\Controller\\Auth-login', 'Auth\\Controller\\Auth-logout', 'Auth\\Controller\\Auth-signup');
     $requestUri = $request->getRequestUri();
     $controller = $event->getRouteMatch()->getParam('controller');
     $action = $event->getRouteMatch()->getParam('action');
     $requestedResourse = $controller . "-" . $action;
     $session = new Container('User');
     if ($session->offsetExists('email')) {
         if (in_array($requestedResourse, $whiteList)) {
             $url = '/TPWeb/public/produit';
             $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
             $response->setStatusCode(302);
         }
     } else {
         if (!in_array($requestedResourse, $whiteList)) {
             $url = '/TPWeb/public/auth';
             $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
             $response->setStatusCode(302);
         }
         $response->sendHeaders();
     }
     //print "Called before any controller action called. Do any operation.";
 }
开发者ID:GemiWagner,项目名称:my_panel,代码行数:28,代码来源:Module.php

示例4: __invoke

 public function __invoke(MvcEvent $e)
 {
     $response = $e->getResponse();
     $this->rateLimitService->consume($e->getRouteMatch(), $e->getRequest());
     //var_dump($this->rateLimitService->getTopMeters('daily_limits'));exit;
     $status = $this->rateLimitService->getLimitStatus($e->getRouteMatch(), $e->getRequest(), 'daily_limits');
     if (!empty($status)) {
         //add info headers
         $headers = $response->getHeaders();
         $headers->addHeaderLine('X-RateLimit-Limit', $status['limit']);
         $headers->addHeaderLine('X-RateLimit-Remaining', $status['remaining']);
         $headers->addHeaderLine('X-RateLimit-Reset', $status['reset']);
         $response->setHeaders($headers);
     }
     if ($this->rateLimitService->isLimitExceeded()) {
         //trigger the ratelimit exceeded event
         $mvcLimitEvent = $this->mvcLimitEvent;
         $response = $this->eventManager->trigger(MvcLimitEvent::EVENT_RATELIMIT_EXCEEDED, $mvcLimitEvent, function ($r) {
             return $r instanceof Response;
         });
         $response = $response->last();
         return $response;
     } elseif ($this->rateLimitService->isLimitWarning()) {
         //trigger the ratelimit warning event
         $mvcLimitEvent = $this->mvcLimitEvent;
         $response = $this->eventManager->trigger(MvcLimitEvent::EVENT_RATELIMIT_WARN, $mvcLimitEvent, function ($r) {
             return $r instanceof Response;
         });
         $response = $response->last();
         $e->setResponse($response);
     }
 }
开发者ID:n3vrax,项目名称:dotkernel,代码行数:32,代码来源:RouteListener.php

示例5: checkAcl

 public function checkAcl(MvcEvent $e)
 {
     $userRole = 'guest';
     $app = $e->getTarget();
     $serviceManager = $app->getServiceManager();
     $authService = $serviceManager->get('AuthService');
     if ($authService->hasIdentity()) {
         $user = $authService->getStorage()->read();
         $userRole = $user->role;
     }
     $controller = $e->getRouteMatch()->getMatchedRouteName('controller');
     $action = $e->getRouteMatch()->getParam('action');
     $route = $controller . '/' . $action;
     $allAccess = false;
     if ($e->getViewModel()->acl->hasResource($controller . '/all')) {
         if ($e->getViewModel()->acl->isAllowed($userRole, $controller . '/all')) {
             $allAccess = true;
         }
     }
     if (!$allAccess) {
         if ($e->getViewModel()->acl->hasResource($route)) {
             if (!$e->getViewModel()->acl->isAllowed($userRole, $route)) {
                 $e->getRouteMatch()->setParam('controller', 'Frontend\\Controller\\Index')->setParam('action', 'index');
             }
         } else {
             $e->getRouteMatch()->setParam('controller', 'Frontend\\Controller\\Index')->setParam('action', 'index');
         }
     }
 }
开发者ID:Patinger,项目名称:Browsergame,代码行数:29,代码来源:Module.php

示例6: getActionName

 public function getActionName(MvcEvent $event)
 {
     if (!$event->getRouteMatch()) {
         return '[unknownAction]';
     }
     return $event->getRouteMatch()->getParam('action');
 }
开发者ID:godentarek,项目名称:whathood,代码行数:7,代码来源:TimerListener.php

示例7: fromRoute

 /**
  * @param mixed $param
  * @param mixed $default
  * @return array|mixed|null
  */
 public function fromRoute($param = null, $default = null)
 {
     if ($param === null) {
         return $this->event->getRouteMatch()->getParams();
     }
     return $this->event->getRouteMatch()->getParam($param, $default);
 }
开发者ID:usban,项目名称:entilocali,代码行数:12,代码来源:Params.php

示例8: dispatchHandle

 /**
  * 路由分发后才能获取controller和action名称
  * @param MvcEvent $e
  */
 public function dispatchHandle(MvcEvent $e)
 {
     //$serviceManager = $e->getApplication()->getServiceManager();
     $viewModel = $e->getApplication()->getMvcEvent()->getViewModel();
     $viewModel->controller = $e->getRouteMatch()->getParam("__CONTROLLER__");
     $viewModel->action = $e->getRouteMatch()->getParam('action');
 }
开发者ID:phox,项目名称:xsale,代码行数:11,代码来源:Module.php

示例9: 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

示例10: boforeDispatch

 /**
  * Before Dispatch Function
  *
  * @param MvcEvent $event            
  */
 function boforeDispatch(MvcEvent $event)
 {
     $sm = $event->getApplication()->getServiceManager();
     $config = $sm->get('Config');
     $list = $config['whitelist'];
     $name = $sm->get('request')->getUri()->getPath();
     $controller = $event->getRouteMatch()->getParam('controller');
     $action = $event->getRouteMatch()->getParam('action');
     $session = new Container('User');
     $controller = $event->getRouteMatch()->getParam('controller');
     $action = $event->getRouteMatch()->getParam('action');
     if (!(strpos($name, 'reset-password') || in_array($name, $list)) && $session->offsetExists('userId')) {
         $serviceManager = $event->getApplication()->getServiceManager();
         $roleTable = $serviceManager->get('RoleTable');
         $userRoleTable = $serviceManager->get('UserRoleTable');
         $roleID = $userRoleTable->getUserRoles('user_id = ' . $session->offsetGet('userId'), array('role_id'));
         $roleName = $roleTable->getUserRoles('rid = ' . $roleID[0]['role_id'], array('role_name'));
         $userRole = $roleName[0]['role_name'];
         $acl = $serviceManager->get('Acl');
         $acl->initAcl();
         $status = $acl->isAccessAllowed($userRole, $controller, $action);
         if (!$status) {
             die('Permission denied');
         }
     }
 }
开发者ID:tsens,项目名称:UsersACL,代码行数:31,代码来源:Module.php

示例11: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $routeCallback = function ($e) {
         $availableLanguages = array('en-US', 'zh-CN');
         $defaultLanguage = 'en-US';
         $language = "";
         $fromRoute = false;
         //see if language could be find in url
         if ($e->getRouteMatch()->getParam('lang')) {
             $language = $e->getRouteMatch()->getParam('lang');
             $fromRoute = true;
             //or use language from http accept
         } else {
             $headers = $e->getApplication()->getRequest()->getHeaders();
             if ($headers->has('Accept-Language')) {
                 $headerLocale = $headers->get('Accept-Language')->getPrioritized();
                 $language = substr($headerLocale[0]->getLanguage(), 0, 2);
             }
         }
         if (!in_array($language, $availableLanguages)) {
             $language = $defaultLanguage;
         }
         $e->getApplication()->getServiceManager()->get('translator')->setLocale($language);
     };
     $eventManager->getSharedManager()->attach(__NAMESPACE__, 'dispatch', function ($e) {
         $e->getTarget()->layout('layout/admin');
     });
     $eventManager->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, $routeCallback);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
 }
开发者ID:papertask,项目名称:papertask,代码行数:32,代码来源:Module.php

示例12: injectXmlTemplate

 public function injectXmlTemplate(MvcEvent $e)
 {
     $format = $e->getRouteMatch()->getParam('format', "html");
     $channel = $e->getRouteMatch()->getParam('channel', "default");
     if ('xml' == $format) {
         $viewModel = $e->getResult();
         if ($viewModel instanceof JsonModel) {
             return;
         }
         $resolver = $e->getApplication()->getServiceManager()->get('ViewResolver');
         $templateDefault = $viewModel->getTemplate() . '.xml.phtml';
         $templateChannel = $viewModel->getTemplate() . '.' . $channel . '.xml.phtml';
         if ($channel != 'default' && $resolver->resolve($templateChannel)) {
             $viewModel->setTemplate($templateChannel);
         } elseif ($resolver->resolve($templateDefault)) {
             $viewModel->setTemplate($templateDefault);
         } else {
         }
         /*
          * Disable layout. This works because InjectViewModelListener is executed after us.
          */
         $viewModel->setTerminal(true);
         /* @var Response $response */
         $response = $e->getResponse();
         $response->getHeaders()->addHeaderLine('Content-Type', 'application/xml');
     }
 }
开发者ID:cross-solution,项目名称:yawik,代码行数:27,代码来源:XmlRenderListener.php

示例13: boforeDispatch

 function boforeDispatch(MvcEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $target = $event->getTarget();
     $whiteList = array('Auth\\Controller\\Index-index', 'Auth\\Controller\\Index-logout');
     $requestUri = $request->getRequestUri();
     $controller = $event->getRouteMatch()->getParam('controller');
     $action = $event->getRouteMatch()->getParam('action');
     $requestedResourse = $controller . "-" . $action;
     $session = new Container('User');
     if ($session->offsetExists('email')) {
         if ($requestedResourse == 'Auth\\Controller\\Index-index' || in_array($requestedResourse, $whiteList)) {
             $url = '/';
             $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
             $response->setStatusCode(302);
         } else {
             $serviceManager = $event->getApplication()->getServiceManager();
             $userRole = $session->offsetGet('roleName');
             $acl = $serviceManager->get('Acl');
             $acl->initAcl();
             $status = $acl->isAccessAllowed($userRole, $controller, $action);
             if (!$status) {
                 die('Permission denied');
             }
         }
     } else {
         if ($requestedResourse != 'Auth\\Controller\\Index-index' && !in_array($requestedResourse, $whiteList)) {
             $url = '/login';
             $response->setHeaders($response->getHeaders()->addHeaderLine('Location', $url));
             $response->setStatusCode(302);
         }
         $response->sendHeaders();
     }
 }
开发者ID:ChristianKolling,项目名称:projeto-frotas,代码行数:35,代码来源:Module.php

示例14: getSerializationGroups

 /**
  * @param MvcEvent $evt
  * @return string[]
  */
 private function getSerializationGroups(MvcEvent $evt)
 {
     /** @var ZendRest $zendRestOptions */
     $zendRestOptions = $evt->getApplication()->getServiceManager()->get('Aeris\\ZendRestModule\\Options\\ZendRest');
     $controllerName = $evt->getRouteMatch()->getParam('controller');
     $actionName = $evt->getRouteMatch()->getParam('action');
     return $zendRestOptions->getController($controllerName)->getSerializationGroup($actionName);
 }
开发者ID:Kipperlenny,项目名称:ZendRestModule,代码行数:12,代码来源:SerializedJsonModelListener.php

示例15: __invoke

 /**
  * Download link.
  *
  * @param string $compress        'zip' | 'bz2' | other to make option
  * @param string $moduleNamespace
  *
  * @return string
  */
 public function __invoke($compress = 'zip', $moduleNamespace = '')
 {
     if ($moduleNamespace === '') {
         $controller = $this->mvcEvent->getRouteMatch()->getParam('controller');
         $moduleNamespace = substr($controller, 0, strpos($controller, '\\'));
     }
     return $this->view->url('download', ['module' => $moduleNamespace, 'compress' => $compress]);
 }
开发者ID:sitrunlab,项目名称:learnzf2,代码行数:16,代码来源:DownloadButtonLink.php


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