public function testGetPathPrefixByRootLocationId() { $rootLocationId = 123; $rootLocation = new Location(array('id' => $rootLocationId)); $pathPrefix = '/foo/bar'; $rootUrlAlias = new URLAlias(array('path' => $pathPrefix)); $this->locationService->expects($this->once())->method('loadLocation')->with($rootLocationId)->will($this->returnValue($rootLocation)); $this->urlAliasService->expects($this->once())->method('reverseLookup')->with($rootLocation)->will($this->returnValue($rootUrlAlias)); $this->assertSame($pathPrefix, $this->urlAliasGenerator->getPathPrefixByRootLocationId($rootLocationId)); }
private function getMultiSiteSettings() { $rootLocationId = $this->configResolver->getParameter('content.tree_root.location_id'); $defaultPage = $this->configResolver->getParameter('default_page'); if ($rootLocationId === null) { return array(); } $pathPrefix = trim($this->urlAliasGenerator->getPathPrefixByRootLocationId($rootLocationId), '/'); $pathPrefixExcludeItems = array_map(function ($value) { return trim($value, '/'); }, $this->configResolver->getParameter('content.tree_root.excluded_uri_prefixes')); return array('site.ini/SiteAccessSettings/PathPrefix' => $pathPrefix, 'site.ini/SiteAccessSettings/PathPrefixExclude' => $pathPrefixExcludeItems, 'logfile.ini/AccessLogFileSettings/PathPrefix' => $pathPrefix, 'site.ini/SiteSettings/IndexPage' => "/content/view/full/{$rootLocationId}/", 'site.ini/SiteSettings/DefaultPage' => $defaultPage !== null ? $defaultPage : "/content/view/full/{$rootLocationId}/", 'content.ini/NodeSettings/RootNode' => $rootLocationId); }
private function getMultiSiteSettings() { $rootLocationId = $this->configResolver->getParameter( 'content.tree_root.location_id' ); $indexPage = $this->configResolver->getParameter( 'index_page' ); $defaultPage = $this->configResolver->getParameter( 'default_page' ); if ( $rootLocationId === null ) { // return SiteSettings if there is no MultiSite (rootLocation is not defined) $result = array(); if ( $indexPage !== null ) { $result['site.ini/SiteSettings/IndexPage'] = $indexPage; } if ( $defaultPage !== null ) { $result['site.ini/SiteSettings/DefaultPage'] = $defaultPage; } return $result; } $pathPrefix = trim( $this->urlAliasGenerator->getPathPrefixByRootLocationId( $rootLocationId ), '/' ); $pathPrefixExcludeItems = array_map( function ( $value ) { return trim( $value, '/' ); }, $this->configResolver->getParameter( 'content.tree_root.excluded_uri_prefixes' ) ); return array( 'site.ini/SiteAccessSettings/PathPrefix' => $pathPrefix, 'site.ini/SiteAccessSettings/PathPrefixExclude' => $pathPrefixExcludeItems, 'logfile.ini/AccessLogFileSettings/PathPrefix' => $pathPrefix, 'site.ini/SiteSettings/IndexPage' => $indexPage !== null ? $indexPage : "/content/view/full/$rootLocationId/", 'site.ini/SiteSettings/DefaultPage' => $defaultPage !== null ? $defaultPage : "/content/view/full/$rootLocationId/", ); }
/** * 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 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) { try { $requestedPath = $request->attributes->get('semanticPathinfo', $request->getPathInfo()); $urlAlias = $this->getUrlAlias($requestedPath); if ($this->rootLocationId === null) { $pathPrefix = '/'; } else { $pathPrefix = $this->generator->getPathPrefixByRootLocationId($this->rootLocationId); } $params = array('_route' => self::URL_ALIAS_ROUTE_NAME); switch ($urlAlias->type) { case URLAlias::LOCATION: $location = $this->generator->loadLocation($urlAlias->destination); $params += array('_controller' => static::VIEW_ACTION, 'contentId' => $location->contentId, 'locationId' => $urlAlias->destination, 'viewType' => ViewManager::VIEW_TYPE_FULL, 'layout' => true); $request->attributes->set('locationId', $urlAlias->destination); // For Location alias setup 301 redirect to Location's current URL when: // 1. alias is history // 2. alias is custom with forward flag true // 3. requested URL is not case-sensitive equal with the one loaded if ($urlAlias->isHistory === true || $urlAlias->isCustom === true && $urlAlias->forward === true) { $request->attributes->set('semanticPathinfo', $this->generate($location)); $request->attributes->set('needsRedirect', true); // Specify not to prepend siteaccess while redirecting when applicable since it would be already present (see UrlAliasGenerator::doGenerate()) $request->attributes->set('prependSiteaccessOnRedirect', false); } elseif ($this->needsCaseRedirect($urlAlias, $requestedPath, $pathPrefix)) { $request->attributes->set('semanticPathinfo', $this->removePathPrefix($urlAlias->path, $pathPrefix)); $request->attributes->set('needsRedirect', true); } if (isset($this->logger)) { $this->logger->info("UrlAlias matched location #{$urlAlias->destination}. Forwarding to ViewController"); } break; case URLAlias::RESOURCE: // In URLAlias terms, "forward" means "redirect". if ($urlAlias->forward) { $request->attributes->set('semanticPathinfo', '/' . trim($urlAlias->destination, '/')); $request->attributes->set('needsRedirect', true); } elseif ($this->needsCaseRedirect($urlAlias, $requestedPath, $pathPrefix)) { // Handle case-correction redirect $request->attributes->set('semanticPathinfo', $this->removePathPrefix($urlAlias->path, $pathPrefix)); $request->attributes->set('needsRedirect', true); } else { $request->attributes->set('semanticPathinfo', '/' . trim($urlAlias->destination, '/')); $request->attributes->set('needsForward', true); } break; case URLAlias::VIRTUAL: // Handle case-correction redirect if ($this->needsCaseRedirect($urlAlias, $requestedPath, $pathPrefix)) { $request->attributes->set('semanticPathinfo', $this->removePathPrefix($urlAlias->path, $pathPrefix)); $request->attributes->set('needsRedirect', true); } else { // Virtual aliases should load the Content at homepage URL $request->attributes->set('semanticPathinfo', '/'); $request->attributes->set('needsForward', true); } break; } return $params; } catch (NotFoundException $e) { throw new ResourceNotFoundException($e->getMessage(), $e->getCode(), $e); } }