public function setMatcherBuilder(MatcherBuilderInterface $matcherBuilder) { $this->matcherBuilder = $matcherBuilder; foreach ($this->config as $i => $rule) { foreach ($rule['matchers'] as $matcherClass => $matchingConfig) { $this->matchersMap[$i][$matcherClass] = $matcherBuilder->buildMatcher($matcherClass, $matchingConfig, $this->request); } } }
/** * Matches a SiteAccess by name. * Returns corresponding SiteAccess object, according to configuration, with corresponding matcher. * Returns null if no matcher can be found (e.g. non versatile). * * @param string $siteAccessName * * @throws \InvalidArgumentException If $siteAccessName is invalid (i.e. not present in configured list). * * @return \eZ\Publish\Core\MVC\Symfony\SiteAccess|null */ public function matchByName($siteAccessName) { if (!isset($this->siteAccessList[$siteAccessName])) { throw new InvalidArgumentException("Invalid SiteAccess name provided for reverse matching: {$siteAccessName}"); } $request = clone $this->request; // Be sure to have a clean pathinfo, without SiteAccess part in it. if ($this->siteAccess->matcher instanceof URILexer) { $request->setPathinfo($this->siteAccess->matcher->analyseURI($request->pathinfo)); } foreach ($this->siteAccessesConfiguration as $matchingClass => $matchingConfiguration) { $matcher = $this->matcherBuilder->buildMatcher($matchingClass, $matchingConfiguration, $request); if (!$matcher instanceof VersatileMatcher) { continue; } if ($matcher instanceof CompoundInterface) { $matcher->setMatcherBuilder($this->matcherBuilder); } $reverseMatcher = $matcher->reverseMatch($siteAccessName); if (!$reverseMatcher instanceof Matcher) { continue; } $siteAccessClass = $this->siteAccessClass; /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess $siteAccess */ $siteAccess = new $siteAccessClass(); $siteAccess->name = $siteAccessName; $siteAccess->matcher = $reverseMatcher; $siteAccess->matchingType = $reverseMatcher->getName(); return $siteAccess; } // No VersatileMatcher configured for $siteAccessName. $this->logger->notice("Siteaccess '{$siteAccessName}' could not be reverse-matched against configuration. No VersatileMatcher found."); return null; }