/** * @depends testConstruct * @dataProvider matchProvider */ public function testMatch(SimplifiedRequest $request, $siteAccess, Router $router) { $sa = $router->match($request); $this->assertInstanceOf('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess', $sa); $this->assertSame($siteAccess, $sa->name); $router->setSiteAccess(); }
/** * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); // We have a serialized siteaccess object from a fragment (sub-request), we need to get it back. if ($request->attributes->has('serialized_siteaccess')) { $request->attributes->set('siteaccess', unserialize($request->attributes->get('serialized_siteaccess'))); $request->attributes->remove('serialized_siteaccess'); } else { if (!$request->attributes->has('siteaccess')) { $request->attributes->set('siteaccess', $this->siteAccessRouter->match(new SimplifiedRequest(array('scheme' => $request->getScheme(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'pathinfo' => $request->getPathInfo(), 'queryParams' => $request->query->all(), 'languages' => $request->getLanguages(), 'headers' => $request->headers->all())))); } } $siteaccess = $request->attributes->get('siteaccess'); if ($siteaccess instanceof SiteAccess) { $siteAccessEvent = new PostSiteAccessMatchEvent($siteaccess, $request, $event->getRequestType()); $this->eventDispatcher->dispatch(MVCEvents::SITEACCESS, $siteAccessEvent); } }
public function testMatchByNameNoVersatileMatcher() { $matcherBuilder = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\MatcherBuilderInterface'); $logger = $this->getMock('Psr\\Log\\LoggerInterface'); $matcherClass = 'Map\\Host'; $matchedSiteAccess = 'foo'; $matcherConfig = array('phoenix-rises.fm' => $matchedSiteAccess, 'ez.no' => 'default_sa'); $config = array($matcherClass => $matcherConfig); $router = new Router($matcherBuilder, $logger, 'default_sa', $config, array($matchedSiteAccess, 'default_sa')); $router->setSiteAccess(new SiteAccess('test', 'test')); $request = $router->getRequest(); $matcherBuilder->expects($this->once())->method('buildMatcher')->with($matcherClass, $matcherConfig, $request)->will($this->returnValue($this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\SiteAccess\\Matcher'))); $logger->expects($this->once())->method('notice'); $this->assertNull($router->matchByName($matchedSiteAccess)); }
/** * @param Request $request * * @return SiteAccess */ private function getSiteAccessFromRequest(Request $request) { return $this->siteAccessRouter->match(new SimplifiedRequest(array('scheme' => $request->getScheme(), 'host' => $request->getHost(), 'port' => $request->getPort(), 'pathinfo' => $request->getPathInfo(), 'queryParams' => $request->query->all(), 'languages' => $request->getLanguages(), 'headers' => $request->headers->all()))); }