summaryrefslogtreecommitdiffstats
path: root/src/Router/RunnerFactory.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Router/RunnerFactory.php')
-rw-r--r--src/Router/RunnerFactory.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Router/RunnerFactory.php b/src/Router/RunnerFactory.php
new file mode 100644
index 0000000..08ed7b0
--- /dev/null
+++ b/src/Router/RunnerFactory.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Jasny\Router;
+
+use Jasny\Router\Route;
+use Jasny\Router\Runner;
+
+/**
+ * Factory of Runner instances
+ */
+class RunnerFactory
+{
+ /**
+ * Create Runner instance
+ *
+ * @param Route $route
+ * @return Runner
+ */
+ public function __invoke(Route $route)
+ {
+ if (isset($route->controller)) {
+ $class = Runner\Controller::class;
+ } elseif (isset($route->fn)) {
+ $class = Runner\Callback::class;
+ } elseif (isset($route->file)) {
+ $class = Runner\PhpScript::class;
+ } else {
+ throw new \InvalidArgumentException("Route has neither 'controller', 'fn' or 'file' defined");
+ }
+
+ return new $class();
+ }
+}