當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。