Esempio n. 1
0
 /**
  * Makes sure instantiation of a given controller works and that the 'init' method exists.
  */
 public function testInstantiationOfControllerSucceedsAndInitMethodExists()
 {
     $route = new Route('/path/', DummyController::class, 'view');
     $controllerName = $route->getController();
     $controller = new $controllerName();
     $this->assertInstanceOf(GenericController::class, $controller);
     $this->assertTrue(method_exists($controller, 'init'));
 }
Esempio n. 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);
 }