Beispiel #1
0
 /**
  * Add a new route to be matched on dispatch
  *
  * Essentially, this method is a standard "Route" builder/factory,
  * allowing a loose argument format and a standard way of creating
  * Route instances
  *
  * This method takes its arguments in a very loose format
  * The only "required" parameter is the callback (which is very strange considering the argument definition order)
  *
  * <code>
  * $router = new Klein();
  *
  * $router->respond( function() {
  *     echo 'this works';
  * });
  * $router->respond( '/endpoint', function() {
  *     echo 'this also works';
  * });
  * $router->respond( 'POST', '/endpoint', function() {
  *     echo 'this also works!!!!';
  * });
  * </code>
  *
  * @param string | array $method    HTTP Method to match
  * @param string $path              Route URI path to match
  * @param callable $callback        Callable callback method to execute on route match
  * @access public
  * @return Route
  */
 public function respond($method, $path = '*', $callback = null)
 {
     // Get the arguments in a very loose format
     extract($this->parseLooseArgumentOrder(func_get_args()), EXTR_OVERWRITE);
     $route = $this->route_factory->build($callback, $path, $method);
     $this->routes->add($route);
     return $route;
 }
 public function testAddCallableConvertsToRoute()
 {
     // Create our collection with NO data
     $routes = new RouteCollection();
     $callable = function () {
     };
     // Add our data
     $routes->add($callable);
     $this->assertNotSame($callable, current($routes->all()));
     $this->assertTrue(current($routes->all()) instanceof Route);
 }