public function testIterable() { $map = ["homepage" => new Route('/home'), "hello" => new Route('/hello')]; $routes = new RouteCollection(); $routes->add("homepage", $map["homepage"]); $routes->add("hello", $map["hello"]); $routes_array = []; foreach ($routes as $name => $route) { $routes_array[$name] = $route; } $this->assertSame($map, $routes_array); }
private function parseRoute(RouteCollection $routes, \SimpleXMLElement $route) { if (empty($route['name'])) { throw new \RuntimeException('Each route must have a unique name.'); } $name = (string) $route['name']; if (empty($route['path'])) { throw new \RuntimeException(sprintf('Route %s must have a path.', $name)); } $methods = []; if (!empty($route['methods'])) { $methods = explode('|', $route['methods']); } $params = $this->parseRouteParams($route, $name); $routes->add($name, new Route((string) $route['path'], $params, $methods)); }
private function parseRoute(RouteCollection $routes, array $route) { if (empty($route['name'])) { throw new \RuntimeException('Each route must have a unique name.'); } $name = (string) $route['name']; if (empty($route['path'])) { throw new \RuntimeException(sprintf('Route %s must have a path.', $name)); } if (empty($route['methods'])) { throw new \RuntimeException(sprintf('Route %s must have a method.', $name)); } $params = $this->parseRouteParams($route, $name); $requirements = $this->parseRouteRequirements($route, $name); $routes->add($name, new Route((string) $route['path'], $params, $route['methods'], $requirements)); }
private function parseRoute(RouteCollection $routes, \stdClass $route) { if (empty($route->name)) { throw new \RuntimeException('Each route must have a unique name.'); } $name = (string) $route->name; if (empty($route->path)) { throw new \RuntimeException(sprintf('Route %s must have a path.', $name)); } $methods = []; if (!empty($route->methods)) { $methods = explode('|', $route->methods); } $params = $this->parseRouteParams($route, $name); $requirements = $this->parseRouteRequirements($route, $name); $routes->add($name, new Route((string) $route->path, $params, $methods, $requirements)); }
public function testFillRouteCollection() { $routes = new RouteCollection(); $routes->add('home', new Route('/home')); $routes->add('hello', new Route('/hello')); $routes->add('contact', new Route('/contact')); $this->assertSame(3, $routes->count()); $this->assertSame(3, count($routes)); $this->assertCount(3, $routes); }
<?php use Framework\Routing\RouteCollection; use Framework\Routing\Route; $routes = new RouteCollection(); $routes->add('home', new Route('/home', ['_controller' => 'Application\\Controller\\HomeAction'], ['GET'])); $routes->add('login', new Route('/login')); return $routes;
<?php use Framework\Routing\Route; use Framework\Routing\RouteCollection; $routes = new RouteCollection(); $routes->add('hello', new Route('/hello', ['_controller' => 'Application\\Controller\\HelloWorldAction'])); return $routes;
<?php use Framework\Routing\RouteCollection; use Framework\Routing\Route; $routes = new RouteCollection(); $routes->add('home', new Route('/home')); $routes->add('login', new Route('/login'));
<?php use Application\Controller\HelloWorldController; use Framework\Routing\Route; use Framework\Routing\RouteCollection; $routes = new RouteCollection(); $routes->add("hello", new Route('/hello', ['_controller' => HelloWorldController::class])); return $routes;