/** * 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; }
/** * Allows tags API execution to be performed with full access sand-boxed. * * The closure sandbox will do a catch all on exceptions and rethrow after * re-setting the sudo flag. * * Example use: * $tag = $tagsService->sudo( * function ( TagsService $tagsService ) use ( $tagId ) * { * return $tagsService->loadTag( $tagId ); * } * ); * * @param \Closure $callback * * @throws \RuntimeException Thrown on recursive sudo() use. * @throws \Exception Re throws exceptions thrown inside $callback * * @return mixed */ public function sudo(Closure $callback) { return $this->service->sudo($callback, $this); }