Beispiel #1
0
 /**
  * Makes sure getters and setters are working fine.
  */
 public function testGettersAndSetters()
 {
     $route = new Route('/path/', DummyController::class, 'run');
     $this->assertInstanceOf(Route::class, $route->setController(\Exception::class));
     $this->assertEquals(\Exception::class, $route->getController());
     $this->assertInstanceOf(Route::class, $route->setMethod('forthelulz'));
     $this->assertEquals('forthelulz', $route->getMethod());
 }
Beispiel #2
0
 /**
  * Runs the controller found in the given route on the given URL
  *
  * @param Route     $route
  * @param string    $url
  *
  * @return mixed
  */
 private function runController(Route $route, string $url)
 {
     $controller = $route->getController();
     $method = $route->getMethod();
     $options = $route->parseOptions($url);
     $obj = $this->getControllerInstance($controller);
     $reflection = new \ReflectionClass($controller);
     if (!$reflection->hasMethod($method)) {
         throw new RuntimeException("{$controller} has no method {$method}!");
     }
     return call_user_func_array([$obj->init($this->container), $method], $options);
 }