public function testSetCallableConvertsToRoute()
 {
     // Create our collection with NO data
     $routes = new RouteCollection();
     // Set our data
     $routes->set('first', function () {
     });
     $this->assertNotSame('value', $routes->get('first'));
     $this->assertTrue($routes->get('first') instanceof Route);
 }
Beispiel #2
0
 /**
  * Set the routes
  *
  * @param array $routes Array of routes configurations
  *
  * @throws \Exception
  */
 public function configureRoutes($routes)
 {
     $routeCollection = new RouteCollection();
     foreach ($routes as $route) {
         if ($this->debug) {
             Log::write('Configuring route "' . $route['path'] . '"');
         }
         $routeObject = $this->router->respond($route['httpMethod'], $route['path'], $route['callback']);
         $routeObject->setName($route['name']);
         $routeCollection->set($route['name'], $routeObject);
     }
     $this->router = new Klein($this->router->service(), $this->router->app(), $routeCollection);
     if ($this->debug) {
         // Add a catchall debugging route
         Log::write('Configuring catchall route');
         $this->router->respond('*', function (Request $request, Response $response) {
             Log::write(' ==> URI called : "' . $request->uri() . '" / User Agent : "' . $request->userAgent() . '"');
             Log::write(' <== Response code : ' . $response->code());
         });
     }
 }