Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
20 / 20 |
|
83.33% |
10 / 12 |
|
23.08% |
3 / 13 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Nyholm | |
100.00% |
20 / 20 |
|
83.33% |
10 / 12 |
|
23.08% |
3 / 13 |
|
100.00% |
2 / 2 |
11.28 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
13 / 13 |
|
81.82% |
9 / 11 |
|
16.67% |
2 / 12 |
|
100.00% |
1 / 1 |
8.21 | |||
| serverRequest | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celema\Core\Factory; |
| 6 | |
| 7 | use Celema\Core\Exception\RuntimeException; |
| 8 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 9 | use Nyholm\Psr7Server\ServerRequestCreator; |
| 10 | use Override; |
| 11 | use Psr\Http\Message\ServerRequestInterface; |
| 12 | |
| 13 | /** @api */ |
| 14 | class Nyholm extends AbstractFactory |
| 15 | { |
| 16 | protected Psr17Factory $factory; |
| 17 | |
| 18 | public function __construct() |
| 19 | { |
| 20 | if (!class_exists(Psr17Factory::class) || !class_exists(ServerRequestCreator::class)) { |
| 21 | throw new RuntimeException( |
| 22 | 'Install nyholm/psr7 and nyholm/psr7-server to use the default ' |
| 23 | . 'PSR-7 factory, or pass a custom Factory implementation to the App constructor', |
| 24 | ); |
| 25 | } |
| 26 | |
| 27 | $factory = new Psr17Factory(); |
| 28 | $this->factory = $factory; |
| 29 | $this->responseFactory = $factory; |
| 30 | $this->streamFactory = $factory; |
| 31 | $this->requestFactory = $factory; |
| 32 | $this->serverRequestFactory = $factory; |
| 33 | $this->uploadedFileFactory = $factory; |
| 34 | $this->uriFactory = $factory; |
| 35 | } |
| 36 | |
| 37 | #[Override] |
| 38 | public function serverRequest(): ServerRequestInterface |
| 39 | { |
| 40 | $creator = new ServerRequestCreator( |
| 41 | $this->factory, // ServerRequestFactory |
| 42 | $this->factory, // UriFactory |
| 43 | $this->factory, // UploadedFileFactory |
| 44 | $this->factory, // StreamFactory |
| 45 | ); |
| 46 | |
| 47 | return $creator->fromGlobals(); |
| 48 | } |
| 49 | } |