PHPRouter\Route::dispatch PHP Method

dispatch() public method

public dispatch ( )
    public function dispatch()
    {
        $action = explode('::', $this->config['_controller']);
        if ($this->parametersByName) {
            $this->parameters = array($this->parameters);
        }
        $this->action = !empty($action[1]) && trim($action[1]) !== '' ? $action[1] : null;
        if (!is_null($this->action)) {
            $instance = new $action[0]();
            call_user_func_array(array($instance, $this->action), $this->parameters);
        } else {
            $instance = new $action[0]($this->parameters);
        }
    }

Usage Example

Example #1
0
 /**
  * @test
  */
 public function shouldCallSpecifiedCallback()
 {
     $route = new Route('GET /test/page/@number.html', '\\PhpRouter\\Test\\Test->page');
     $route->parseParams('/test/page/42.html');
     $this->assertEquals(42, $route->dispatch());
 }