/** * This listener is run when the KernelEvents::REQUEST event is triggered * * This is responsible for setting up the routing information * * @param GetResponseEvent $event * @throws \BadMethodCallException * @return null */ public function on_kernel_request(GetResponseEvent $event) { $request = $event->getRequest(); $context = new RequestContext(); $context->fromRequest($request); $matcher = src_get_url_matcher($this->manager, $context, $this->root_path, $this->php_ext); $router_listener = new RouterListener($matcher, $context); $router_listener->onKernelRequest($event); }
public function testRequestMatcher() { $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $request = Request::create('http://localhost/'); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $context = new RequestContext(); $requestMatcher = $this->getMock('Symfony\\Component\\Routing\\Matcher\\RequestMatcherInterface'); $requestMatcher->expects($this->any())->method('getContext')->will($this->returnValue($context)); $requestMatcher->expects($this->once())->method('matchRequest')->with($this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Request'))->will($this->returnValue(array())); $listener = new RouterListener($requestMatcher); $listener->onKernelRequest($event); }
/** * @dataProvider getPortData */ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort) { $urlMatcher = $this->getMockBuilder('Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface')->disableOriginalConstructor()->getMock(); $context = new RequestContext(); $context->setHttpPort($defaultHttpPort); $context->setHttpsPort($defaultHttpsPort); $urlMatcher->expects($this->any())->method('getContext')->will($this->returnValue($context)); $listener = new RouterListener($urlMatcher); $event = $this->createGetResponseEventForUri($uri); $listener->onKernelRequest($event); $this->assertEquals($expectedHttpPort, $context->getHttpPort()); $this->assertEquals($expectedHttpsPort, $context->getHttpsPort()); $this->assertEquals(0 === strpos($uri, 'https') ? 'https' : 'http', $context->getScheme()); }
public function onKernelRequest(GetResponseEvent $event) { $this->stopwatch->start('routeListener'); $return = parent::onKernelRequest($event); $this->stopwatch->stop('routeListener'); return $return; }
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); try { parent::onKernelRequest($event); } catch (NotFoundHttpException $e) { } }
public function testSubRequestWithDifferentMethod() { $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $request = Request::create('http://localhost/', 'post'); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $requestMatcher = $this->getMock('Symfony\\Component\\Routing\\Matcher\\RequestMatcherInterface'); $requestMatcher->expects($this->any())->method('matchRequest')->with($this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Request'))->will($this->returnValue(array())); $context = new RequestContext(); $requestMatcher->expects($this->any())->method('getContext')->will($this->returnValue($context)); $listener = new RouterListener($requestMatcher, new RequestContext()); $listener->onKernelRequest($event); // sub-request with another HTTP method $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $request = Request::create('http://localhost/', 'get'); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); $listener->onKernelRequest($event); $this->assertEquals('GET', $context->getMethod()); }
public function onKernelRequest(GetResponseEvent $event) { if (false === $this->routesLoaded) { $this->loadRoutes($event->getRequest()); $this->routesLoaded = true; } try { parent::onKernelRequest($event); } catch (NotFoundHttpException $e) { } }
/** * @dataProvider getLoggingParameterData */ public function testLoggingParameter($parameter, $log, $parameters) { $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); $requestMatcher->expects($this->once()) ->method('matchRequest') ->will($this->returnValue($parameter)); $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); $logger->expects($this->once()) ->method('info') ->with($this->equalTo($log), $this->equalTo($parameters)); $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); $request = Request::create('http://localhost/'); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger); $listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); }
/** * Simply pass the event to the route listener, because we have nothing to add here. * * @param FinishRequestEvent $event */ public function onKernelFinishRequest(FinishRequestEvent $event) { $this->baseRouteListener->onKernelFinishRequest($event); }
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { //we need to reset all routes. They will anyway replaced by FrontendRouter::loadRoutes, //but to prevent caching conflicts, when a user removes a plugin for example //from a page, we need to know that without using actual caching. $this->routes = new RouteCollection(); $this->urlMatcher->__construct($this->routes, $this->requestContext); //prepare for new master request: clear the PageResponse object $this->pageStack->setCurrentPage(null); $this->pageStack->setCurrentDomain(null); $this->pageStack->setPageResponse($this->pageResponseFactory->create()); $this->frontendRouter->setRequest($request); $editorNodeId = (int) $this->pageStack->getRequest()->get('_jarves_editor_node'); $editorDomainId = (int) $this->pageStack->getRequest()->get('_jarves_editor_domain'); $domain = null; if ($editorDomainId) { $domain = $this->pageStack->getDomain($editorDomainId); if (!$domain) { //we haven't found any domain that is responsible for this request return; } $this->pageStack->setCurrentDomain($domain); } if ($editorNodeId) { //handle jarves content editor stuff //access is later checked if (!$editorNodeId && $domain) { $editorNodeId = $domain->getStartnodeId(); } $page = $this->pageStack->getPage($editorNodeId); if (!$page || !$page->isRenderable()) { //we haven't found any page that is responsible for this request return; } if (!$domain) { $domain = $this->pageStack->getDomain($page->getDomainId()); } $this->pageStack->setCurrentPage($page); $this->pageStack->setCurrentDomain($domain); $request->attributes->set('_controller', 'jarves.page_controller:handleAction'); } else { //regular frontend route search //search domain if (!$domain) { $domain = $this->frontendRouter->searchDomain(); if (!$domain) { //we haven't found any domain that is responsible for this request return; } $this->pageStack->setCurrentDomain($domain); } //search page $page = $this->frontendRouter->searchPage(); if (!$page || !$page->isRenderable()) { //we haven't found any page that is responsible for this request return; } $this->pageStack->setCurrentPage($page); if ($response = $this->frontendRouter->loadRoutes($this->routes, $page)) { //loadRoutes return in case of redirects and permissions a redirect or 404 response. $event->setResponse($response); return; } try { //check routes in $this->route parent::onKernelRequest($event); } catch (MethodNotAllowedException $e) { } catch (NotFoundHttpException $e) { } } } }