Esempio 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);
 }
Esempio n. 2
0
$envs = ['default', 'local', 'dev', 'qa', 'stage', 'prod'];
$config = new \Samsara\Eden\Kernel\Config($envs);
$config->setSys('basedir', $basedir);
$config->setSys('cfg.format', 'json');
// Supply the env that this bootstrapper executes
$kernel = new \Samsara\Eden\Kernel\Kernel('dev');
$kernel->setConfig($config);
$builder = new \Samsara\Eden\Kernel\AuraExtend\ContainerBuilder();
$services = $builder->newServices();
$container = $builder->newDI();
// Allow the kernel to set the services in the service container
$kernel->setServices($services);
// Allow the kernel to set the Dependency Injection params
$kernel->setDI($container, $services);
// Now it's time for routing. Grab the container.
$routerContainer = new \Aura\Router\RouterContainer();
// Use the map builder so that we can cache the routes.
$routerContainer->setMapBuilder(function ($map) use($config, $kernel) {
    /**
     * @var $map \Aura\Router\Map
     */
    $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();