Beispiel #1
0
 public function testRun()
 {
     $run = false;
     $run = $this->test_router->run(function () use(&$run) {
         $run = true;
     });
     $this->assertEquals(true, $run);
 }
Beispiel #2
0
 /**
  * Run route
  *
  * @return array
  * @throws \Exception
  * @return bool
  */
 public function dispatch()
 {
     // Check path
     if ($this->injectors['path'] === null) {
         return false;
     }
     $method = $this->input->method();
     $path =& $this->injectors['path'];
     $prefixes =& $this->injectors['prefixes'];
     $app =& $this->app;
     if ($this->handle($this->routes, function ($route) use($path, $method, $prefixes, $app) {
         // Lookup rules
         $rules = isset($route['rules']) ? $route['rules'] : array();
         // Lookup defaults
         $defaults = isset($route['defaults']) ? $route['defaults'] : array();
         // Try to parse the params
         if (($params = Router::match($path, $route['path'], $rules, $defaults)) !== false) {
             // Method match
             if ($route['via'] && !in_array($method, $route['via'])) {
                 return false;
             }
             $app->input->params = $params;
             return Route::build($route['route'], null, $prefixes);
         }
         return false;
     })) {
         return true;
     }
     // Try to check automatic route parser
     if (isset($this->injectors['automatic']) && is_callable($this->injectors['automatic'])) {
         $routes = (array) call_user_func($this->injectors['automatic'], $this->injectors['path']);
         return $this->handle($routes, function ($route) use($prefixes) {
             if (!is_subclass_of($route, Middleware::_CLASS_, true)) {
                 return false;
             }
             return Route::build($route, null, $prefixes);
         });
     }
     return false;
 }
Beispiel #3
0
 /**
  * Run route
  *
  * @return array
  * @throws \Exception
  * @return bool
  */
 public function dispatch()
 {
     // Check path
     if ($this->injectors[1] === null) {
         return false;
     }
     $method = $this->input->method();
     $path =& $this->injectors[1];
     $prefixes =& $this->injectors['prefixes'];
     $app =& $this->app;
     if ($this->handle($this->routes, function ($route) use($path, $method, $prefixes, $app) {
         // Lookup rules
         $rules = isset($route['rules']) ? $route['rules'] : array();
         // Lookup defaults
         $defaults = isset($route['defaults']) ? $route['defaults'] : array();
         // Try to parse the params
         if (($params = Router::match($path, $route[1], $rules, $defaults, $app->cli)) !== false) {
             // Method match
             if ($route[0] && is_string($route[0]) && strpos($route[0], $method) === false && $route[0] !== '*') {
                 return false;
             }
             $app->input->params = $params;
             return Route::build($route[2], null, $prefixes);
         }
         return false;
     })) {
         return true;
     }
     // Try to check automatic route parser
     if (isset($this->injectors['automatic']) && is_callable($this->injectors['automatic'])) {
         $routes = (array) call_user_func($this->injectors['automatic'], $this->injectors[1]);
         return $this->handle($routes, function ($route) use($prefixes) {
             try {
                 return Route::build($route, null, $prefixes);
             } catch (\Exception $e) {
             }
         });
     }
     return false;
 }