Beispiel #1
0
 /**
  * Returns whether page should be considered active or not
  *
  * This method will compare the page properties against the route matches
  * composed in the object.
  *
  * @param  bool $recursive  [optional] whether page should be considered
  *                          active if any child pages are active. Default is
  *                          false.
  * @return bool             whether page should be considered active or not
  */
 public function isActive($recursive = false)
 {
     if (!$this->active) {
         $reqParams = [];
         if ($this->routeMatch instanceof RouteMatch || $this->routeMatch instanceof MvcRouter\RouteMatch) {
             $reqParams = $this->routeMatch->getParams();
             if (isset($reqParams[self::ORIGINAL_CONTROLLER])) {
                 $reqParams['controller'] = $reqParams[self::ORIGINAL_CONTROLLER];
             }
             $pageParams = $this->params;
             if (null !== $this->controller) {
                 $pageParams['controller'] = $this->controller;
             }
             if (null !== $this->action) {
                 $pageParams['action'] = $this->action;
             }
             if (null !== $this->getRoute()) {
                 if ($this->routeMatch->getMatchedRouteName() === $this->getRoute() && count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) {
                     $this->active = true;
                     return $this->active;
                 } else {
                     return parent::isActive($recursive);
                 }
             }
         }
         $pageParams = $this->params;
         if (null !== $this->controller) {
             $pageParams['controller'] = $this->controller;
         } else {
             /**
              * @todo In ZF1, this was configurable and pulled from the front controller
              */
             $pageParams['controller'] = 'index';
         }
         if (null !== $this->action) {
             $pageParams['action'] = $this->action;
         } else {
             /**
              * @todo In ZF1, this was configurable and pulled from the front controller
              */
             $pageParams['action'] = 'index';
         }
         if (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)) {
             $this->active = true;
             return true;
         }
     }
     return parent::isActive($recursive);
 }
 /**
  * Valid route but with no login with no login
  */
 public function it_dispatches_unauthorized(MvcEvent $event, RouteMatch $match, EventManagerInterface $eventManager, Application $application, $accessService)
 {
     $application->getEventManager()->willReturn($eventManager);
     $accessService->requiresAuthentication(self::CONTROLLER_ADMIN, 'index')->willReturn(true);
     $accessService->hasUser()->willReturn(false);
     $event->getTarget()->willReturn($application);
     $match->getParam('controller')->willReturn(self::CONTROLLER_ADMIN);
     $match->getParam('action')->willReturn('index');
     $match->getMatchedRouteName()->willReturn('admin');
     $event->getRouteMatch()->willReturn($match);
     $accessService->getRoles()->willReturn([]);
     $eventManager->triggerEvent($event)->shouldBeCalled();
     $event->setError(AccessService::ACCESS_UNAUTHORIZED)->shouldBeCalled();
     $event->setParam('route', 'admin')->shouldBeCalled();
     $event->setParam('controller', self::CONTROLLER_ADMIN)->shouldBeCalled();
     $event->setParam('action', 'index')->shouldBeCalled();
     $event->setParam('roles', 'none')->shouldBeCalled();
     $event->setName(MvcEvent::EVENT_DISPATCH_ERROR)->shouldBeCalled();
     $this->verifyAccess($event);
 }
 /**
  * Create a successful RouteResult from the given RouteMatch.
  *
  * @param RouteMatch $match
  * @return RouteResult
  */
 private function marshalSuccessResultFromRouteMatch(RouteMatch $match)
 {
     $params = $match->getParams();
     if (array_key_exists(self::METHOD_NOT_ALLOWED_ROUTE, $params)) {
         return RouteResult::fromRouteFailure($this->allowedMethodsByPath[$params[self::METHOD_NOT_ALLOWED_ROUTE]]);
     }
     return RouteResult::fromRouteMatch($this->getMatchedRouteName($match->getMatchedRouteName()), $params['middleware'], $params);
 }