Exemplo n.º 1
0
 /**
  * Tries to match a request with a set of routes.
  *
  * If the matcher can not find information, it must throw one of the exceptions documented
  * below.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request The request to match
  *
  * @return array An array of parameters
  *
  * @throws \Symfony\Component\Routing\Exception\ResourceNotFoundException If no matching resource could be found
  */
 public function matchRequest(Request $request)
 {
     $requestedPath = rawurldecode($request->attributes->get('semanticPathinfo', $request->getPathInfo()));
     $pathPrefix = $this->generator->getPathPrefix();
     if (mb_stripos($requestedPath, $pathPrefix) !== 0) {
         throw new ResourceNotFoundException();
     }
     $requestedPath = $this->removePathPrefix($requestedPath, $pathPrefix);
     $requestedPath = trim($requestedPath, '/');
     if (empty($requestedPath)) {
         throw new ResourceNotFoundException();
     }
     $tag = $this->tagsService->loadTagByUrl($requestedPath, $this->configResolver->getParameter('languages'));
     $params = array('_route' => self::TAG_URL_ROUTE_NAME, '_controller' => static::TAG_VIEW_CONTROLLER, 'tagId' => $tag->id);
     $request->attributes->set('tagId', $tag->id);
     if ($this->logger !== null) {
         $this->logger->info("TagRouter matched tag #{$tag->id}. Forwarding to tag view controller");
     }
     return $params;
 }
Exemplo n.º 2
0
 /**
  * Loads a tag object from its URL.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user is not allowed to read tags
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the specified tag is not found
  *
  * @param string $url
  * @param string[] $languages
  *
  * @return \Netgen\TagsBundle\API\Repository\Values\Tags\Tag
  */
 public function loadTagByUrl($url, array $languages)
 {
     return $this->service->loadTagByUrl($url, $languages);
 }
Exemplo n.º 3
0
 /**
  * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
  *
  * @covers \Netgen\TagsBundle\Core\Repository\TagsService::loadTagByUrl
  */
 public function testLoadTagByUrlThrowsUnauthorizedException()
 {
     $this->repository->setCurrentUser($this->getStubbedUser(10));
     $this->tagsService->loadTagByUrl('ez publish/extensions/eztags', array('eng-GB'));
 }