summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/BasicStrategy.php9
-rw-r--r--src/Exceptions/InvalidResponseException.php12
2 files changed, 20 insertions, 1 deletions
diff --git a/src/BasicStrategy.php b/src/BasicStrategy.php
index 62bc48e..5043576 100644
--- a/src/BasicStrategy.php
+++ b/src/BasicStrategy.php
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Lightscale\Router;
use Lightscale\Router\Contracts\Strategy;
+use Lightscale\Router\Exceptions\InvalidResponseException;
use Lightscale\Router\Exceptions\NotFoundException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -13,7 +14,13 @@ class BasicStrategy implements Strategy
{
public function runRoute(RouteCall $call): ResponseInterface
{
- return ($call->route->getHandler())($call);
+ $result = ($call->route->getHandler())($call);
+
+ if ($result instanceof ResponseInterface) {
+ return $result;
+ }
+
+ throw new InvalidResponseException();
}
public function notFound(RequestInterface $request): ResponseInterface
diff --git a/src/Exceptions/InvalidResponseException.php b/src/Exceptions/InvalidResponseException.php
new file mode 100644
index 0000000..98577a1
--- /dev/null
+++ b/src/Exceptions/InvalidResponseException.php
@@ -0,0 +1,12 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Lightscale\Router\Exceptions;
+
+use RuntimeException;
+
+class InvalidResponseException extends RuntimeException
+{
+ protected $message = 'Does not return an instance of ResponseInterface';
+}