Exemplo n.º 1
0
 public function testWithPr7RouterPackageAuraV3()
 {
     $routerContainer = new \Aura\Router\RouterContainer();
     $map = $routerContainer->getMap();
     $matcher = $routerContainer->getMatcher();
     $request = $this->newRequest('/');
     $response = $this->response;
     $response->bar = 'Hello';
     $expectedResponse = 'Hello World';
     // response + middlewareOne decoration <= objects are passed by reference
     $middlewareOne = function ($request, $response) {
         // / Decorate the bar property
         $response->bar = $response->bar . ' World';
     };
     $routeIndexAction = function ($request, $response) {
         // Awesome sauce
         return $response->bar;
     };
     // Add middleware
     $this->middleware->add($middlewareOne);
     // Add route as last one
     $this->middleware->add($routeIndexAction);
     $map->get('index.read', '/', $this->middleware);
     // <-- middleware becomes the handler
     // We have a matching route
     $route = $matcher->match($request);
     $h = $route->handler;
     $responseResult = $h($request, $response);
     $this->assertEquals($expectedResponse, $responseResult);
 }
Exemplo n.º 2
0
     */
    $cache = $config->getSys('basedir') . '/cache/' . $config->get('cache.routes', 'routes.cache');
    if (file_exists($cache)) {
        // Routes are cached, use those
        $routes = unserialize(file_get_contents($cache));
        $map->setRoutes($routes);
    } else {
        // Routes are not cached, have the kernel build them
        $kernel->setRoutes($map);
        // And now cache them for the next request
        $routes = $map->getRoutes();
        file_put_contents($cache, serialize($routes));
    }
});
// Now grab the finished map and matcher objects
$map = $routerContainer->getMap();
$matcher = $routerContainer->getMatcher();
// And add those to the services container
$services->set('route.map', $map);
$services->set('route.matcher', $matcher);
/*
 * Autoloader: check
 * Kernel: check
 * Config: check
 * DI Container: check
 * Services Container: check
 * Routes Map: check
 * Routes Matcher: check
 *
 * Alright, let's actually hand everything off to the Application object now
 */