summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2016-10-11 18:35:07 +0200
committerGitHub <noreply@github.com>2016-10-11 18:35:07 +0200
commit6aa9e824cb0e3a00fd7d235ba7529e6dde3075c8 (patch)
treec8dcc3b4cf055b086c84a4a934e61c8387e494ff /src
parente0ecc0b543d4bd6fea11947bc82128ad599f245f (diff)
parent3906df8a6897ecf1f3ee96ea31bbe6e6bdff8433 (diff)
downloadrouter-origin/runner.zip
router-origin/runner.tar.gz
router-origin/runner.tar.bz2
Merge pull request #4 from Minstel/runnerorigin/runner
Implementation and tests for Runner/Controller
Diffstat (limited to 'src')
-rw-r--r--src/Router/Runner/Controller.php14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Router/Runner/Controller.php b/src/Router/Runner/Controller.php
index ed8c060..0969c21 100644
--- a/src/Router/Runner/Controller.php
+++ b/src/Router/Runner/Controller.php
@@ -14,7 +14,7 @@ use Psr\Http\Message\ResponseInterface;
class Controller extends Runner
{
/**
- * Route to a file
+ * Route to a controller
*
* @param RequestInterface $request
* @param ResponseInterface $response
@@ -22,6 +22,18 @@ class Controller extends Runner
*/
public function run(RequestInterface $request, ResponseInterface $response)
{
+ $class = !empty($this->route->controller) ? $this->route->controller : null;
+ if (!class_exists($class)) {
+ throw new \RuntimeException("Can not route to controller '$class': class not exists");
+ }
+
+ if (!method_exists($class, '__invoke')) {
+ throw new \RuntimeException("Can not route to controller '$class': class does not have '__invoke' method");
+ }
+
+ $controller = new $class($this->route);
+
+ return $controller($request, $response);
}
}