public function register(Container $container) { $container['request'] = function ($c) { return Request::createFromGlobals(); }; $container['requestStack'] = function ($c) { $stack = new RequestStack(); $stack->push($c['request']); return $stack; }; $container['requestContext'] = function ($c) { $rc = new RequestContext(); $rc->fromRequest($c['request']); return $rc; }; $container['resolver'] = function ($c) { return new ControllerResolver(); }; $container['httpKernel'] = function ($c) { return new HttpKernel($c['dispatcher'], $c['resolver'], $c['requestStack']); }; $container['router'] = function ($c) { $router = new ChainRouter($c['logger']); $router->add($c['staticRouter']); $router->add($c['nodeRouter']); return $router; }; $container['staticRouter'] = function ($c) { return new StaticRouter($c['routeCollection'], ['cache_dir' => (bool) $c['config']['devMode'] ? null : ROADIZ_ROOT . '/cache/routing', 'debug' => (bool) $c['config']['devMode'], 'generator_cache_class' => 'StaticUrlGenerator', 'matcher_cache_class' => 'StaticUrlMatcher'], $c['requestContext'], $c['logger']); }; $container['nodeRouter'] = function ($c) { return new NodeRouter($c['em'], ['cache_dir' => (bool) $c['config']['devMode'] ? null : ROADIZ_ROOT . '/cache/routing', 'debug' => (bool) $c['config']['devMode'], 'generator_cache_class' => 'NodeUrlGenerator', 'matcher_cache_class' => 'NodeUrlMatcher'], $c['requestContext'], $c['logger'], $c['stopwatch']); }; $container['urlGenerator'] = function ($c) { return $c['staticRouter']->getGenerator(); }; $container['httpUtils'] = function ($c) { return new HttpUtils($c['router'], $c['router']); }; $container['routeListener'] = function ($c) { return new TimedRouteListener($c['router'], $c['requestContext'], null, $c['requestStack'], $c['stopwatch']); }; $container['routeCollection'] = function ($c) { if (isset($c['config']['install']) && true === $c['config']['install']) { /* * Get Install routes */ $installClassname = Kernel::INSTALL_CLASSNAME; $installClassname::setupDependencyInjection($c); return new InstallRouteCollection($installClassname); } else { /* * Get App routes */ $rCollection = new RoadizRouteCollection($c['backendClass'], $c['frontendThemes'], SettingsBag::get('static_domain_name'), $c['stopwatch']); return $rCollection; } }; return $container; }
/** * Constructor * * @param Google_Client $client * @param ConfigHelper $configHelper */ public function __construct(Google_Client $client, ChainRouter $router, $routeName) { $this->client = $client; try { $uri = $router->generate($routeName, array(), UrlGeneratorInterface::ABSOLUTE_URL); $this->client->setRedirectUri($uri); } catch (\Exception $e) { $this->client->setRedirectUri(''); } }
private function getHeadersFromResponse($name) { $routeProvider = $this->getContainer()->get('swp.provider.route'); $route = $routeProvider->getRouteByName($name); $this->assertNotNull($route); $this->assertEquals($route->getName(), $name); $client = static::createClient(); $client->request('GET', $this->router->generate($route)); $response = $client->getResponse(); self::assertEquals(200, $response->getStatusCode()); $headers = $response->headers; return $headers; }
/** * @return \Symfony\Cmf\Component\Routing\ChainRouter|\PHPUnit_Framework_MockObject_MockObject */ private function getRouterMock() { if (!isset($this->router)) { $this->router = $this->getMock('Symfony\\Cmf\\Component\\Routing\\ChainRouter'); $this->router->expects($this->any())->method('getContext')->will($this->returnValue(new RequestContext())); } return $this->router; }
/** * @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException */ public function testSupport() { $router = $this->getMock('Symfony\\Cmf\\Component\\Routing\\Tests\\Routing\\VersatileRouter'); $router->expects($this->once())->method('supports')->will($this->returnValue(false)); $router->expects($this->never())->method('generate')->will($this->returnValue(false)); $this->router->add($router); $this->router->generate('foobar'); }
/** * Ensure that methods are passed to the wrapped router. * * @covers ::__call */ public function testCall() { $mock_router = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $this->chainRouter = $this->getMockBuilder('Symfony\\Cmf\\Component\\Routing\\ChainRouter')->disableOriginalConstructor()->setMethods(['add'])->getMock(); $this->chainRouter->expects($this->once())->method('add')->with($mock_router)->willReturnSelf(); $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser); $this->router->add($mock_router); }
public function generate($name, $parameters = array(), $absolute = false) { if ($name instanceof RouteReference) { $parameters += $name->getParams(); $name = $name->getRoute(); } return parent::generate($name, $parameters, $absolute); }
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { if ($name instanceof RouteReference) { $parameters += $name->getParams(); $name = $name->getRoute(); } return parent::generate($name, $parameters, $referenceType); }
/** * @param Request $request * * @throws \Exception */ public function matchRequest(Request $request) { try { $parameters = parent::matchRequest($request); $this->matchedRouteRequest = $request; return $parameters; } catch (\Exception $e) { throw $e; } }
/** * {@inheritdoc} */ public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) { return $this->chainRouter->generate($name, $parameters, $referenceType); }
/** * @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException */ public function testGenerateNoMatchingFormat() { $route = $this->getDm()->find(null, self::ROUTE_ROOT . '/format'); $this->router->generate($route, array('id' => 37, '_format' => 'xyz')); }
public function generate($type, array $values = array()) { return $this->router->generate($type, $values); }
public function testGenerateWithParameters() { $route = self::$em->getRepository('Raindrop\\RoutingBundle\\Entity\\Route')->findOneByName('test_route'); $url = self::$router->generate('test', array('route' => $route, 'param' => 'someValue'), true); $this->assertEquals('http://localhost/test/route?param=someValue', $url); }