/** * Retrieve the version from the route match. * * The route prototype sets "version", while the Content-Type listener sets * "zf_ver_version"; check both to obtain the version, giving priority to the * route prototype result. * * @param RouteMatch|V2RouteMatch $routeMatches * @return int|false */ protected function getVersionFromRouteMatch($routeMatches) { $version = $routeMatches->getParam('zf_ver_version', false); if ($version) { return $version; } return $routeMatches->getParam('version', false); }
/** * Retrieve the identifier, if any * * Attempts to see if an identifier was passed in either the URI or the * query string, returning it if found. Otherwise, returns a boolean false. * * @param \Zend\Router\RouteMatch $routeMatch * @param Request $request * @return false|mixed */ protected function getIdentifier($routeMatch, $request) { $identifier = $this->getIdentifierName(); $id = $routeMatch->getParam($identifier, false); if ($id !== false) { return $id; } $id = $request->getQuery()->get($identifier, false); if ($id !== false) { return $id; } return false; }
/** * Does the request represent a collection? * * @param string $serviceName * @param array $data * @param RouteMatch|V2RouteMatch $matches * @param HttpRequest $request * @return bool */ protected function isCollection($serviceName, $data, $matches, HttpRequest $request) { if (!array_key_exists($serviceName, $this->restControllers)) { return false; } if ($request->isPost() && (empty($data) || ArrayUtils::isHashTable($data))) { return false; } $identifierName = $this->restControllers[$serviceName]; if ($matches->getParam($identifierName) !== null) { return false; } return null === $request->getQuery($identifierName, null); }
/** * 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); }
/** * Attempt to retrieve the identifier for a given request * * Checks first if the $identifierName is in the route matches, and then * as a query string parameter. * * @param string $identifierName * @param RouteMatch|V2RouteMatch $routeMatch Validated by calling method. * @param \Zend\Stdlib\RequestInterface $request * @return false|mixed */ protected function getIdentifier($identifierName, $routeMatch, $request) { $id = $routeMatch->getParam($identifierName, false); if ($id !== false) { return $id; } if (!$request instanceof Request) { return false; } return $request->getQuery($identifierName, false); }