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


PHP MvcEvent::getRouter方法代码示例

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


在下文中一共展示了MvcEvent::getRouter方法的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: preDispatch

 /**
  * preDispatch Event Handler
  * Handle authentication process
  * Decide where user should be redirected to when logged in or not
  * 
  * 
  * @access public
  * @uses AuthenticationService
  * @uses Response
  * 
  * @param \Zend\Mvc\MvcEvent $event
  * @throws \Exception
  */
 public function preDispatch(MvcEvent $event)
 {
     // ACL dispatcher is used only in HTTP requests not console requests
     if (!$event->getRequest() instanceof HttpRequest) {
         return;
     }
     $userAuth = new AuthenticationService();
     $user = array();
     $signInController = 'DefaultModule\\Controller\\Sign';
     if ($userAuth->hasIdentity()) {
         $user = $userAuth->getIdentity();
     }
     $routeMatch = $event->getRouteMatch();
     $controller = $routeMatch->getParam('controller');
     $action = $routeMatch->getParam('action');
     if ($userAuth->hasIdentity() && isset($user['status']) && $user['status'] == 2) {
         $userAuth->clearIdentity();
         // redirect to sign/out
         $url = $event->getRouter()->assemble(array('action' => 'out'), array('name' => 'defaultSign'));
     } else {
         if ($userAuth->hasIdentity() && $controller == $signInController && $action == 'in') {
             // redirect to index
             $url = $event->getRouter()->assemble(array('action' => 'index'), array('name' => 'home'));
         }
     }
     if (isset($url)) {
         $event->setResponse(new Response());
         $this->redirect()->getController()->setEvent($event);
         $response = $this->redirect()->toUrl($url);
         return $response;
     }
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:45,代码来源:AuthenticationEvent.php

示例3: onRoute

 public function onRoute(MvcEvent $e)
 {
     $serviceManager = $e->getApplication()->getServiceManager();
     $routeMatchName = $e->getRouteMatch()->getMatchedRouteName();
     if (strpos($routeMatchName, '.rest.') !== false || strpos($routeMatchName, '.rpc.') !== false) {
         return;
     }
     $config = $serviceManager->get('Config');
     $identityGuards = $config['zource_guard']['identity'];
     $needsIdentity = null;
     foreach ($identityGuards as $guard => $needed) {
         if (fnmatch($guard, $routeMatchName)) {
             $needsIdentity = $needed;
             break;
         }
     }
     if ($needsIdentity === null) {
         throw new RuntimeException(sprintf('The identity guard "%s" has not been configured.', $routeMatchName));
     }
     if (!$needsIdentity) {
         return;
     }
     $authenticationService = $serviceManager->get('Zend\\Authentication\\AuthenticationService');
     if ($authenticationService->hasIdentity()) {
         return;
     }
     $returnUrl = $e->getRouter()->assemble([], ['name' => $routeMatchName, 'force_canonical' => true, 'query' => $e->getRequest()->getUri()->getQuery()]);
     $url = $e->getRouter()->assemble([], ['name' => 'login', 'query' => ['redir' => $returnUrl]]);
     $response = new Response();
     $response->setStatusCode(Response::STATUS_CODE_302);
     $response->getHeaders()->addHeaderLine('Location: ' . $url);
     return $response;
 }
开发者ID:zource,项目名称:zource,代码行数:33,代码来源:IdentityGuard.php

示例4: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $app = $e->getApplication();
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $sm = $app->getServiceManager();
     $list = $this->whitelist;
     $auth = $sm->get('AuthService');
     $e->getViewModel()->setVariable('hasIdentity', $auth->hasIdentity());
     if ($auth->hasIdentity()) {
         $e->getViewModel()->setVariable('currentUserId', $auth->getStorage()->read()->id);
     } else {
         $e->getViewModel()->setVariable('currentUserId', -1);
     }
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) use($list, $auth) {
         $match = $e->getRouteMatch();
         // No route match, this is a 404
         if (!$match instanceof RouteMatch) {
             return;
         } else {
             // Route is whitelisted
             $name = $match->getMatchedRouteName();
             if (in_array($name, $list)) {
                 if ($auth->hasIdentity() && $name != 'login/process') {
                     $router = $e->getRouter();
                     $url = $router->assemble(array(), array('name' => 'home'));
                     $response = $e->getResponse();
                     $response->getHeaders()->addHeaderLine('Location', $url);
                     $response->setStatusCode(302);
                     return $response;
                 } else {
                     return;
                 }
             } else {
                 // User is authenticated
                 if ($auth->hasIdentity() && $name != 'auth/logout') {
                     // $id = $this->UserAuthentication()->getIdentity()->getId();
                     // var_dump(($auth->getIdentity()));
                     // exit;
                     // var_dump($name);exit;
                     return;
                 } else {
                     // Redirect to the user login page, as an example
                     $router = $e->getRouter();
                     $url = $router->assemble(array(), array('name' => 'login'));
                     $response = $e->getResponse();
                     $response->getHeaders()->addHeaderLine('Location', $url);
                     $response->setStatusCode(302);
                     return $response;
                 }
             }
         }
     }, -100);
 }
开发者ID:benjaminchazelle,项目名称:csZendApplication,代码行数:55,代码来源:Module.php

示例5: dispatchEvent

 private function dispatchEvent(MvcEvent $e)
 {
     // TARGET & SERVICEMANAGER
     $target = $e->getTarget();
     $serviceManager = $e->getApplication()->getServiceManager();
     // CONFIG
     $config = $e->getApplication()->getServiceManager()->get('config');
     // TRANSLATOR
     /** @var Translator $translator */
     $translator = $serviceManager->get('MvcTranslator');
     // LANG CONFIG
     $languages = $config['languages']['available'];
     $fallbackLocale = $config['languages']['fallback'];
     // ROUTER PARAM LOCALE
     $routeMatch = $e->getRouteMatch();
     if ($routeMatch) {
         $urlLocale = $routeMatch->getParam('locale');
     } else {
         /**
          * @todo
          * evtl hier noch aus der request url versuchen die locale zu lesen
          */
         $urlLocale = $fallbackLocale;
     }
     if (strstr($_SERVER['SERVER_NAME'], '.de')) {
         $urlLocale = 'de';
     } else {
         $urlLocale = 'en';
     }
     // ROUTER
     /** @var \Zend\Mvc\Router\Http\TreeRouteStack $router */
     $router = $e->getRouter();
     // check if language is present
     $usedLocale = isset($languages[$urlLocale]) ? $languages[$urlLocale] : false;
     $usedLocaleShort = isset($languages[$urlLocale]) ? $urlLocale : false;
     // language not found redirect to fallback lang
     if (!$usedLocale && !$usedLocaleShort) {
         // wrong locale request
         $e->getRouteMatch()->setParam('locale', $fallbackLocale);
         $url = $e->getRouter()->assemble($e->getRouteMatch()->getParams(), array('name' => $e->getRouteMatch()->getMatchedRouteName()));
         $response = $e->getResponse();
         $response->getHeaders()->addHeaderLine('Location', $url);
         $response->setStatusCode(302);
         $response->sendHeaders();
         return $response;
     }
     // add current locale as default router param
     $router->setDefaultParam('locale', $usedLocaleShort);
     $translator->setLocale($usedLocale);
     $translator->setFallbackLocale($usedLocale);
     $translator->addTranslationFile('phpArray', 'vendor/zendframework/zendframework/resources/languages/' . $usedLocaleShort . '/Zend_Validate.php', 'default', $usedLocale);
     \Locale::setDefault($usedLocale);
     AbstractValidator::setDefaultTranslator($translator);
 }
开发者ID:GlitchedMan,项目名称:armasquads,代码行数:54,代码来源:Module.php

示例6: preDispatch

 /**
  * @param MvcEvent $e
  * @throws \Exception
  * @throws \ServiceLocatorFactory\NullServiceLocatorException
  */
 public function preDispatch(MvcEvent $e)
 {
     $application = $e->getApplication();
     $sm = $application->getServiceManager();
     $router = $sm->get('router');
     $request = $sm->get('request');
     $matchedRoute = $router->match($request);
     $params = $matchedRoute->getParams();
     $controller = $params['controller'];
     if (!isset($controller)) {
         return false;
     }
     $currentControllerNamespace = explode('\\', $controller);
     if ($currentControllerNamespace[0] == 'Admin') {
         $sl = ServiceLocatorFactory::getInstance();
         $session = new SessionContainer();
         $userDetails = $session->offsetGet('userDetails');
         /* Check Admin Area login */
         if (!$sl->get('AuthService')->hasIdentity() or $userDetails->sitename != $this->recoverSitename($sl)) {
             $url = $e->getRouter()->assemble(array('action' => 'index'), array('name' => 'login'));
             $response = $e->getResponse();
             $response->getHeaders()->addHeaderLine('Location', $url);
             $response->setStatusCode(302);
             $response->sendHeaders();
             exit;
         }
         // Check ACL
         $roles = (include __DIR__ . '/config/module.acl.roles.php');
         foreach ($roles as $key => $value) {
             if ($key == $matchedRoute->getMatchedRouteName()) {
                 if (isset($value['resources'])) {
                     $allowed = 0;
                     foreach ($value['resources'] as $resource) {
                         if ($userDetails->acl->hasResource($resource)) {
                             $allowed = 1;
                         }
                     }
                     /* No permissions, redirect... */
                     if ($allowed == 0) {
                         $url = $e->getRouter()->assemble(array('lang' => 'it'), array('name' => 'admin/not-authorized'));
                         $response = $e->getResponse();
                         $response->getHeaders()->addHeaderLine('Location', $url);
                         $response->setStatusCode(401);
                         $response->sendHeaders();
                         exit;
                     }
                 }
             }
         }
     }
 }
开发者ID:usban,项目名称:entilocali,代码行数:56,代码来源:Module.php

示例7: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $serviceManager = $e->getApplication()->getServiceManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $serviceManager->get('LocaleManager')->setLocale('es_ES');
     if ($serviceManager->has('Translator') && $e->getRouter() instanceof TranslatorAwareInterface) {
         $translator = $serviceManager->get('Translator');
         if ($translator instanceof TranslatorInterface) {
             $e->getRouter()->setTranslator($translator);
             $e->getRouter()->setTranslatorTextDomain('Zend\\Mvc\\Router');
         }
     }
 }
开发者ID:zend-modules,项目名称:ZendSkeletonApplication,代码行数:15,代码来源:Module.php

示例8: onBootstrap

 public function onBootstrap(MvcEvent $e)
 {
     $this->initSession();
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $list = array();
     $auth = $e->getApplication()->getServiceManager()->get("Zend\\Authentication\\AuthenticationService");
     $eventManager->attach(MvcEvent::EVENT_ROUTE, function ($e) use($list, $auth) {
         $match = $e->getRouteMatch();
         // No route match, this is a 404
         if (!$match instanceof RouteMatch) {
             return;
         }
         // Route is whitelisted
         $route = $match->getMatchedRouteName();
         $params = $match->getParams();
         $module = explode('/', $route);
         /*
                     if($_SERVER['REMOTE_ADDR'] != '127.0.0.1' && $_SERVER['SERVER_PORT'] != '443') {
                         $url = 'Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                         header(str_replace( 'www.', '' , $url));
                         exit();
                     }*/
         if (@$module[0] == 'login') {
             if ($auth->hasIdentity()) {
                 $router = $e->getRouter();
                 $url = $router->assemble(array(), array('name' => 'messages'));
                 $response = $e->getResponse();
                 $response->getHeaders()->addHeaderLine('Location', $url);
                 $response->setStatusCode(302);
                 return $response;
             } else {
                 return;
             }
         }
         if ($auth->hasIdentity()) {
             return;
         } else {
             $router = $e->getRouter();
             $url = $router->assemble(array(), array('name' => 'login'));
             $response = $e->getResponse();
             $response->getHeaders()->addHeaderLine('Location', $url);
             $response->setStatusCode(302);
             return $response;
         }
     }, -100);
 }
开发者ID:dFenille,项目名称:whatsApi,代码行数:48,代码来源:Module.php

示例9: onError

 /**
  * @private
  * @param  MvcEvent $event
  * @return void
  */
 public function onError(MvcEvent $event)
 {
     // Do nothing if no error or if response is not HTTP response
     if (!$event->getParam('exception') instanceof UnauthorizedExceptionInterface || $event->getResult() instanceof HttpResponse || !$event->getResponse() instanceof HttpResponse) {
         return;
     }
     $router = $event->getRouter();
     if ($this->authenticationService->hasIdentity()) {
         if (!$this->options->getRedirectWhenConnected()) {
             return;
         }
         $redirectRoute = $this->options->getRedirectToRouteConnected();
     } else {
         $redirectRoute = $this->options->getRedirectToRouteDisconnected();
     }
     $uri = $router->assemble([], ['name' => $redirectRoute]);
     if ($this->options->getAppendPreviousUri()) {
         $redirectKey = $this->options->getPreviousUriQueryKey();
         $previousUri = $event->getRequest()->getUriString();
         $uri = $router->assemble([], ['name' => $redirectRoute, 'query' => [$redirectKey => $previousUri]]);
     }
     $response = $event->getResponse() ?: new HttpResponse();
     $response->getHeaders()->addHeaderLine('Location', $uri);
     $response->setStatusCode(302);
     $event->setResponse($response);
     $event->setResult($response);
 }
开发者ID:adamh114,项目名称:zfc-rbac,代码行数:32,代码来源:RedirectStrategy.php

示例10: __invoke

 public function __invoke(MvcEvent $event)
 {
     if ($event->getViewModel()->terminate()) {
         /*
          * No need for navigation when it is not rendered anyway.
          */
         return;
     }
     $services = $event->getApplication()->getServiceManager();
     $navigation = $services->get('Core/Navigation');
     $settingsMenu = $navigation->findOneBy('route', 'lang/settings');
     if ($settingsMenu->hasChildren()) {
         /*
          * We already have the subnavigation.
          */
         return;
     }
     $moduleManager = $services->get('ModuleManager');
     $configPlugin = $services->get('ControllerPluginManager')->get('config');
     $modules = $moduleManager->getLoadedModules();
     $modulesWithSettings = $configPlugin("settings", array_keys($modules));
     $routeMatch = $event->getRouteMatch();
     $router = $event->getRouter();
     $activeModule = $event->getParam('__settings_active_module', false);
     $settingsMenu->setActive((bool) $activeModule);
     foreach ($modulesWithSettings as $key => $param) {
         $page = array('label' => isset($param['navigation_label']) ? $param['navigation_label'] : ucfirst($key), 'order' => isset($param['navigation_order']) ? $param['navigation_order'] : '10', 'class' => isset($param['navigation_class']) ? $param['navigation_class'] : null, 'resource' => 'route/lang/settings', 'route' => 'lang/settings', 'router' => $router, 'action' => 'index', 'controller' => 'index', 'params' => array('lang' => 'de', 'module' => $key), 'active' => $key == $activeModule);
         if ($routeMatch instanceof RouteMatch) {
             $page['routeMatch'] = $routeMatch;
         }
         $settingsMenu->addPage($page);
     }
 }
开发者ID:vfulco,项目名称:YAWIK,代码行数:33,代码来源:InjectSubNavigationListener.php

示例11: checkAuth

 public function checkAuth(MvcEvent $e)
 {
     $sm = $e->getApplication()->getServiceManager();
     $auth = $sm->get('AuthService');
     $match = $e->getRouteMatch();
     if (!$match instanceof RouteMatch) {
         return;
     }
     $name = $match->getMatchedRouteName();
     if (in_array($name, $this->publicRoutes)) {
         return;
     }
     //Check identity
     if ($auth->hasIdentity()) {
         $viewModel = $e->getViewModel();
         $viewModel->current_user = $auth->getIdentity();
         return;
     }
     $router = $e->getRouter();
     $url = $router->assemble(array(), array('name' => 'auth'));
     $response = $e->getResponse();
     $response->getHeaders()->addHeaderLine('Location', $url);
     $response->setStatusCode(302);
     return $response;
 }
开发者ID:khinmyatkyi,项目名称:Office_Management,代码行数:25,代码来源:Module.php

示例12: preDispatch

 /**
  * preDispatch Event Handler
  *
  * @param \Zend\Mvc\MvcEvent $event
  * @throws \Exception
  */
 public function preDispatch(MvcEvent $event)
 {
     //@todo - Should we really use here and Controller Plugin?
     $userAuth = $this->getUserAuthenticationPlugin();
     $acl = $this->getAclClass();
     $role = AclClass::DEFAULT_ROLE;
     if ($userAuth->hasIdentity()) {
         $user = $userAuth->getIdentity();
         $role = 'member';
         //@todo - Get role from user!
     }
     $routeMatch = $event->getRouteMatch();
     $controller = $routeMatch->getParam('controller');
     $action = $routeMatch->getParam('action');
     if (!$acl->hasResource($controller)) {
         throw new \Exception('Resource ' . $controller . ' not defined');
     }
     if (!$acl->isAllowed($role, $controller, $action)) {
         $url = $event->getRouter()->assemble(array(), array('name' => 'login'));
         $response = $event->getResponse();
         $response->headers()->addHeaderLine('Location', $url);
         $response->setStatusCode(302);
         $response->sendHeaders();
         exit;
     }
 }
开发者ID:madran,项目名称:budzet_domowy,代码行数:32,代码来源:Authentication.php

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

示例14: handleError

 /**
  * @param MvcEvent $e
  */
 protected function handleError(MvcEvent $e)
 {
     $router = $e->getRouter();
     if ($this->authenticationService->hasIdentity()) {
         if (!$this->options->getRedirectWhenConnected()) {
             return;
         }
         $redirectRoute = $this->options->getRedirectToRouteConnected();
     } else {
         $redirectRoute = $this->options->getRedirectToRouteDisconnected();
     }
     $params = array();
     $options = array('name' => $redirectRoute);
     if ($this->options->getAppendPreviousUri()) {
         $redirectKey = $this->options->getPreviousUriRouteKey();
         $previousUri = $e->getRequest()->getUriString();
         $params = array($redirectKey => $previousUri);
     }
     $uri = $router->assemble($params, $options);
     $response = $e->getResponse() ?: new HttpResponse();
     $response->getHeaders()->addHeaderLine('Location', $uri);
     $response->setStatusCode(302);
     $e->setResponse($response);
     $e->setResult($response);
 }
开发者ID:mhilker,项目名称:usermanager,代码行数:28,代码来源:RedirectStrategy.php

示例15: restrictAccess

 public function restrictAccess(MvcEvent $e, array $whiteListed = array(), $loginRouteName = 'admin/login')
 {
     // $loginRouteName is whitelisted from the redirection
     // The redirection is to the $loginRouteName
     // additional routes can be whitelisted
     if (!$e->getApplication()->getServiceManager()->get('Zend\\Authentication\\AuthenticationService')->hasIdentity()) {
         $whiteListed[] = $loginRouteName;
         $match = $e->getRouteMatch();
         // No route match, this is a 404
         if (!$match instanceof RouteMatch) {
             return;
         }
         // Login route is whitelisted
         if (in_array($match->getMatchedRouteName(), $whiteListed)) {
             return;
         }
         // login url from login route
         $url = $e->getRouter()->assemble(array(), array('name' => $loginRouteName));
         // redirect response
         $response = $e->getResponse();
         $response->getHeaders()->addHeaderLine('Location', $url);
         $response->setStatusCode(302);
         $response->sendHeaders();
         exit;
     }
 }
开发者ID:BPurified,项目名称:ZendCMS,代码行数:26,代码来源:Module.php


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