Esempio 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)
 {
     if ($this->configResolver->getParameter('routing.enable_tag_router', 'eztags') === false) {
         throw new ResourceNotFoundException('Config says to bypass TagRouter');
     }
     $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();
     }
     $languages = $this->configResolver->getParameter('languages');
     $tag = $this->tagsService->sudo(function (TagsService $tagsService) use($requestedPath, $languages) {
         return $tagsService->loadTagByUrl($requestedPath, $languages);
     });
     // We specifically pass tag ID so tag view builder will reload the tag and check for permissions
     // Unfortunately, since at this point user is still anonymous (why!?), this is the best we can do
     $params = array('_route' => self::TAG_URL_ROUTE_NAME, '_controller' => static::TAG_VIEW_ACTION_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;
 }
Esempio n. 2
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;
 }