|
3 | 3 | namespace Runtime\Bref; |
4 | 4 |
|
5 | 5 | use Bref\Event\Handler; |
| 6 | +use Bref\Event\Http\HttpHandler; |
6 | 7 | use Bref\Event\Http\Psr15Handler; |
7 | 8 | use Illuminate\Contracts\Http\Kernel; |
8 | 9 | use Psr\Container\ContainerInterface; |
@@ -33,24 +34,33 @@ public function __construct(array $options = []) |
33 | 34 |
|
34 | 35 | public function getRunner(?object $application): RunnerInterface |
35 | 36 | { |
| 37 | + if ($application instanceof ContainerInterface) { |
| 38 | + $handler = explode(':', $_SERVER['_HANDLER']); |
| 39 | + if (!isset($handler[1]) || '' === $handler[1]) { |
| 40 | + throw new \RuntimeException(sprintf('Application is instance of ContainerInterface but the handler does not contain a service. The handler must be on format "path/to/file.php:App\\Lambda\\MyHandler". You provided "%s".', $_SERVER['_HANDLER'])); |
| 41 | + } |
| 42 | + $application = $application->get($handler[1]); |
| 43 | + } |
| 44 | + |
36 | 45 | if ($application instanceof HttpKernelInterface) { |
| 46 | + if (!class_exists(HttpHandler::class)) { |
| 47 | + throw new \RuntimeException(sprintf('The Bref Runtime needs package bref/bref to support %s applications. Try running "composer require bref/bref".', HttpKernelInterface::class)); |
| 48 | + } |
37 | 49 | $application = new SymfonyHttpHandler($application); |
38 | 50 | } |
39 | 51 |
|
40 | 52 | if ($application instanceof Kernel) { |
| 53 | + if (!class_exists(HttpHandler::class)) { |
| 54 | + throw new \RuntimeException(sprintf('The Bref Runtime needs package bref/bref to support %s applications. Try running "composer require bref/bref".', Kernel::class)); |
| 55 | + } |
41 | 56 | $application = new LaravelHttpHandler($application); |
42 | 57 | } |
43 | 58 |
|
44 | 59 | if ($application instanceof RequestHandlerInterface) { |
45 | | - $application = new Psr15Handler($application); |
46 | | - } |
47 | | - |
48 | | - if ($application instanceof ContainerInterface) { |
49 | | - $handler = explode(':', $_SERVER['_HANDLER']); |
50 | | - if (!isset($handler[1]) || '' === $handler[1]) { |
51 | | - throw new \RuntimeException(sprintf('Application is instance of ContainerInterface but the handler does not contain a service. The handler must be on format "path/to/file.php:App\\Lambda\\MyHandler". You provided "%s".', $_SERVER['_HANDLER'])); |
| 60 | + if (!class_exists(Psr15Handler::class)) { |
| 61 | + throw new \RuntimeException(sprintf('The Bref Runtime needs package bref/bref to support %s applications. Try running "composer require bref/bref".', RequestHandlerInterface::class)); |
52 | 62 | } |
53 | | - $application = $application->get($handler[1]); |
| 63 | + $application = new Psr15Handler($application); |
54 | 64 | } |
55 | 65 |
|
56 | 66 | if ($application instanceof Handler) { |
|
0 commit comments