litphp /
bolt
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Lit\Bolt; |
||||
| 6 | |||||
| 7 | use Lit\Air\Injection\SetterInjector; |
||||
| 8 | use Lit\Bolt\Middlewares\EventsHub; |
||||
| 9 | use Lit\Bolt\Middlewares\RequestContext; |
||||
| 10 | use Lit\Nimo\Middlewares\MiddlewarePipe; |
||||
| 11 | use Lit\Voltage\App; |
||||
| 12 | use Lit\Voltage\Interfaces\ThrowableResponseInterface; |
||||
| 13 | use Psr\Http\Message\ResponseInterface; |
||||
| 14 | |||||
| 15 | /** |
||||
| 16 | * Bolt application |
||||
| 17 | */ |
||||
| 18 | class BoltApp extends App |
||||
| 19 | { |
||||
| 20 | public const SETTER_INJECTOR = SetterInjector::class; |
||||
| 21 | /** |
||||
| 22 | * @var ?EventsHub |
||||
| 23 | * @deprecated |
||||
| 24 | */ |
||||
| 25 | protected $eventsHub; |
||||
| 26 | /** |
||||
| 27 | * @var ?RequestContext |
||||
| 28 | */ |
||||
| 29 | protected $requestContext; |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Injector for EventsHub |
||||
| 33 | * |
||||
| 34 | * @param EventsHub|null $eventsHub The EventsHub. |
||||
| 35 | * @return $this |
||||
| 36 | * @deprecated |
||||
| 37 | */ |
||||
| 38 | 2 | public function injectEventsHub(?EventsHub $eventsHub) |
|||
| 39 | { |
||||
| 40 | 2 | @trigger_error('EventsHub is deprecated', E_USER_DEPRECATED); |
|||
| 41 | 2 | $this->eventsHub = $eventsHub; |
|||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||||
| 42 | 2 | return $this; |
|||
| 43 | } |
||||
| 44 | |||||
| 45 | /** |
||||
| 46 | * Injector for RequestContext |
||||
| 47 | * |
||||
| 48 | * @param RequestContext|null $requestContext The RequestContext. |
||||
| 49 | * @return $this |
||||
| 50 | */ |
||||
| 51 | 2 | public function injectRequestContext(?RequestContext $requestContext) |
|||
| 52 | { |
||||
| 53 | 2 | $this->requestContext = $requestContext; |
|||
| 54 | 2 | return $this; |
|||
| 55 | } |
||||
| 56 | |||||
| 57 | /** |
||||
| 58 | * Getter for EventsHub |
||||
| 59 | * |
||||
| 60 | * @return EventsHub |
||||
| 61 | */ |
||||
| 62 | public function getEventsHub(): EventsHub |
||||
| 63 | { |
||||
| 64 | assert($this->eventsHub !== null); |
||||
|
0 ignored issues
–
show
The property
Lit\Bolt\BoltApp::$eventsHub has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 65 | return $this->eventsHub; |
||||
|
0 ignored issues
–
show
The property
Lit\Bolt\BoltApp::$eventsHub has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 66 | } |
||||
| 67 | |||||
| 68 | 2 | protected function main(): ResponseInterface |
|||
| 69 | { |
||||
| 70 | try { |
||||
| 71 | 2 | $pipe = new MiddlewarePipe(); |
|||
| 72 | 2 | if (isset($this->requestContext)) { |
|||
| 73 | 2 | $pipe->append($this->requestContext); |
|||
|
0 ignored issues
–
show
It seems like
$this->requestContext can also be of type null; however, parameter $middleware of Lit\Nimo\Middlewares\MiddlewarePipe::append() does only seem to accept Psr\Http\Server\MiddlewareInterface, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 74 | } |
||||
| 75 | 2 | if (isset($this->eventsHub)) { |
|||
| 76 | 2 | $pipe->append($this->eventsHub); |
|||
| 77 | } |
||||
| 78 | 2 | $pipe->append($this->middlewarePipe); |
|||
| 79 | |||||
| 80 | 2 | return $pipe->process($this->request, $this->businessLogicHandler); |
|||
| 81 | } catch (ThrowableResponseInterface $e) { |
||||
| 82 | return $e->getResponse(); |
||||
| 83 | } |
||||
| 84 | } |
||||
| 85 | } |
||||
| 86 |