public function testRouteAllowsSpecifyingOptions() { $options = ['foo' => 'bar']; $route = new Route('/foo', $this->noopMiddleware); $route->setOptions($options); $this->assertSame($options, $route->getOptions()); }
public function testCanSpecifyRouteOptions() { $route = new Route('/foo/:id', 'foo', ['GET']); $route->setOptions(['constraints' => ['id' => '\\d+'], 'defaults' => ['bar' => 'baz']]); $this->zf2Router->addRoute('/foo/:id', ['type' => 'segment', 'options' => ['route' => '/foo/:id', 'constraints' => ['id' => '\\d+'], 'defaults' => ['bar' => 'baz', 'middleware' => 'foo']]])->shouldBeCalled(); $router = $this->getRouter(); $router->addRoute($route); }
public function testCanSpecifyRouteOptions() { $route = new Route('/foo/:id', 'foo', ['GET']); $route->setOptions(['constraints' => ['id' => '\\d+'], 'defaults' => ['bar' => 'baz']]); $this->zf2Router->addRoute('/foo/:id^GET', ['type' => 'segment', 'options' => ['route' => '/foo/:id', 'constraints' => ['id' => '\\d+'], 'defaults' => ['bar' => 'baz']], 'may_terminate' => false, 'child_routes' => ['GET' => ['type' => 'method', 'options' => ['verb' => 'GET', 'defaults' => ['middleware' => 'foo']]], Zf2Router::METHOD_NOT_ALLOWED_ROUTE => ['type' => 'regex', 'priority' => -1, 'options' => ['regex' => '/*$', 'defaults' => [Zf2Router::METHOD_NOT_ALLOWED_ROUTE => '/foo/:id'], 'spec' => '']]]])->shouldBeCalled(); $router = $this->getRouter(); $router->addRoute($route); }
public function testAddRouteWithOptions() { $route = new Route('/foo/:bar', 'Home', ['GET', 'POST'], 'home'); $route->setOptions(['conditions' => ['bar' => 'es|en'], 'defaults' => ['bar' => 'en']]); $this->router->addRoute($route); $this->assertCount(1, $this->slimRouter->getMatchedRoutes('GET', '/foo/es')); $this->assertCount(0, $this->slimRouter->getMatchedRoutes('GET', '/foo/baz', true)); }
public function testCanSpecifyAuraRouteValuesViaRouteOptions() { $route = new Route('/foo', 'foo', ['GET']); $route->setOptions(['values' => ['foo' => 'bar']]); $this->auraRoute->setServer(['REQUEST_METHOD' => 'GET'])->shouldBeCalled(); $this->auraRoute->addValues($route->getOptions()['values'])->shouldBeCalled(); $this->auraRouter->add('/foo^GET', '/foo', 'foo')->willReturn($this->auraRoute->reveal()); $router = $this->getRouter(); $router->addRoute($route); }
/** * Inject routes from configuration, if any. * * @param Application $app * @param ContainerInterface $container */ private function injectRoutes(Application $app, ContainerInterface $container) { $config = $container->has('config') ? $container->get('config') : []; if (!isset($config['routes'])) { $app->pipeRoutingMiddleware(); return; } foreach ($config['routes'] as $spec) { if (!isset($spec['path']) || !isset($spec['middleware'])) { continue; } $methods = isset($spec['allowed_methods']) && is_array($spec['allowed_methods']) ? $spec['allowed_methods'] : null; $name = isset($spec['name']) ? $spec['name'] : null; $methods = null === $methods ? Route::HTTP_METHOD_ANY : $methods; $route = new Route($spec['path'], $spec['middleware'], $methods, $name); if (isset($spec['options']) && is_array($spec['options'])) { $route->setOptions($spec['options']); } $app->route($route); } }
/** * Inject routes from configuration, if any. * * @param array $routes Route definitions * @param Application $app */ private function injectRoutes(array $routes, Application $app) { foreach ($routes as $spec) { if (!isset($spec['path']) || !isset($spec['middleware'])) { continue; } if (isset($spec['allowed_methods'])) { $methods = $spec['allowed_methods']; if (!is_array($methods)) { throw new ContainerInvalidArgumentException(sprintf('Allowed HTTP methods for a route must be in form of an array; received "%s"', gettype($methods))); } } else { $methods = Route::HTTP_METHOD_ANY; } $name = isset($spec['name']) ? $spec['name'] : null; $route = new Route($spec['path'], $spec['middleware'], $methods, $name); if (isset($spec['options'])) { $options = $spec['options']; if (!is_array($options)) { throw new ContainerInvalidArgumentException(sprintf('Route options must be an array; received "%s"', gettype($options))); } $route->setOptions($options); } $app->route($route); } }
/** * Inject routes from configuration, if any. * * @param Application $app * @param ContainerInterface $container */ private function injectRoutes(Application $app, ContainerInterface $container) { $config = $container->has('config') ? $container->get('config') : []; if (!isset($config['routes'])) { $app->pipeRoutingMiddleware(); return; } foreach ($config['routes'] as $spec) { if (!isset($spec['path']) || !isset($spec['middleware'])) { continue; } if (isset($spec['allowed_methods'])) { $methods = $spec['allowed_methods']; if (!is_array($methods)) { throw new ContainerInvalidArgumentException(sprintf('Allowed HTTP methods for a route must be in form of an array; received "%s"', gettype($methods))); } } else { $methods = Route::HTTP_METHOD_ANY; } $name = isset($spec['name']) ? $spec['name'] : null; $route = new Route($spec['path'], $spec['middleware'], $methods, $name); if (isset($spec['options'])) { $options = $spec['options']; if (!is_array($options)) { throw new ContainerInvalidArgumentException(sprintf('Route options must be an array; received "%s"', gettype($options))); } $route->setOptions($options); } $app->route($route); } }