public function __construct($routes)
 {
     $routerContainer = new RouterContainer();
     $this->collection = $routerContainer->getMap();
     foreach ($routes as $identifier => $route) {
         $this->collection->get($identifier, $route[1]);
     }
     /** @var Matcher $matcher */
     $this->matcher = $routerContainer->getMatcher();
 }
 public function testAuraRouter()
 {
     //Create router
     $router = new RouterContainer();
     $map = $router->getMap();
     $map->get('index', '/user/{name}/{id}', function ($request, $response) {
         $this->assertEquals('oscarotero', $request->getAttribute('name'));
         $this->assertEquals('35', $request->getAttribute('id'));
         $response->getBody()->write('Ok');
         return $response;
     });
     //Test
     $response = $this->execute([Middleware::AuraRouter($router)], 'http://domain.com/user/oscarotero/35');
     $this->assertEquals('Ok', (string) $response->getBody());
 }
Example #3
0
 public function register(Fol $app)
 {
     $app['router'] = function ($app) {
         $router = new RouterContainer();
         $map = $router->getMap();
         $ns = 'Folk\\Controllers';
         $map->get('index', '/', "{$ns}\\Index");
         $map->get('search', '/{entity}', "{$ns}\\SearchEntity");
         $map->get('insert', '/{entity}/new', "{$ns}\\InsertEntity");
         $map->put('create', '/{entity}', "{$ns}\\CreateEntity");
         $map->get('read', '/{entity}/{id}', "{$ns}\\ReadEntity");
         $map->post('update', '/{entity}/{id}', "{$ns}\\UpdateEntity");
         $map->post('updateField', '/{entity}/{id}/{field}', "{$ns}\\UpdateEntityField");
         $map->delete('delete', '/{entity}/{id}', "{$ns}\\DeleteEntity");
         return $router;
     };
 }
Example #4
0
 private function addRoutes(array $routes)
 {
     $map = $this->routerContainer->getMap();
     $newRoutes = [];
     foreach ($routes as $path => $route) {
         if (!is_string($path)) {
             throw new \Exception('The routes array must be indexed by URI paths, got an integer instead');
         }
         if ($route instanceof RouteBuilder) {
             $subRoutes = $route->getRoutes();
             foreach ($subRoutes as $subRoute) {
                 $newRoutes[] = $this->prepareRoute($subRoute, $path);
             }
         } else {
             $controller = $route;
             $route = new Route();
             $route->handler($controller);
             $newRoutes[] = $this->prepareRoute($route, $path);
         }
     }
     $map->setRoutes($newRoutes);
 }
 /**
  * Registers entries with the container.
  * @param Container $app
  */
 public function register(Container $app)
 {
     $routerContainer = new RouterContainer();
     $app[Map::class] = $routerContainer->getMap();
     $app[RuleIterator::class] = $routerContainer->getRuleIterator();
 }
 public function add($name, $path, $data = null) : Route
 {
     return $this->routerContainer->getMap()->route($name, $path, $data);
 }
Example #7
0
<?php

use Aura\Di\Container;
use Aura\Router\RouterContainer;
return function (Container $app) {
    $app->set('router', function () {
        $router = new RouterContainer();
        $map = $router->getMap();
        $map->get('home', '/');
        $map->get('resume', '/resume');
        $map->get('portfolio', '/portfolio');
        $map->get('blog-list', '/blog');
        $map->get('blog-post', '/blog/{id}');
        return $router;
    });
};
Example #8
0
<?php

use Aura\Router\RouterContainer;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
chdir(dirname(__DIR__));
//require 'bootstrap/server.php';
/**
 * /authenticate/\<application_id>
 * /is-authentication-still-valid/\<application_id>/\<token>
 * /register-user/\<application_id>
 * /unregister-user/\<application_id>
 */
require 'vendor/autoload.php';
$container = new RouterContainer();
$map = $container->getMap();
$matcher = $container->getMatcher();
$route = $container->getRoute();
$map->get('route.authenticate.get', '/authenticate/{application_id}', function (RequestInterface $request, ResponseInterface $response) {
    echo $request->getUri() . PHP_EOL;
    $response->getBody()->write($request->getUri());
    return $response;
});
$matcher->match($request);
foreach ($route->attributes as $key => $val) {
    $request = $request->withAttribute($key, $val);
}