Esempio n. 1
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);
 }
Esempio n. 2
0
 /**
  * Checks that option parsing also works at the beginning of an URL
  */
 public function testParseOptionsMatchesURL()
 {
     $route = new Route('{id}/controller/{action}/', DummyController::class, 'run');
     $options = $route->parseOptions('/18/controller/view?p=123&o=456/invalid/l+o+l!!!.jpg');
     $this->assertArrayHasKey('action', $options);
     $this->assertArrayHasKey('id', $options);
     $this->assertEquals('view', $options['action']);
     $this->assertEquals('18', $options['id']);
 }