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);
 }
Exemplo n.º 2
0
 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));
 }
Exemplo n.º 3
0
 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));
 }
Exemplo n.º 4
0
 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));
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
<?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;
Exemplo n.º 7
0
<?php

use Framework\Routing\Route;
use Framework\Routing\RouteCollection;
$routes = new RouteCollection();
$routes->add('hello', new Route('/hello', ['_controller' => 'Application\\Controller\\HelloWorldAction']));
return $routes;
Exemplo n.º 8
0
<?php

use Framework\Routing\RouteCollection;
use Framework\Routing\Route;
$routes = new RouteCollection();
$routes->add('home', new Route('/home'));
$routes->add('login', new Route('/login'));
Exemplo n.º 9
0
<?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;