Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| JavascriptCdnProxyController | |
0.00% |
0 / 5 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\JavascriptCdn\Controllers; |
| 3 | |
| 4 | use Apie\Core\ValueObjects\Exceptions\InvalidStringForValueObjectException; |
| 5 | use Apie\JavascriptCdn\JavascriptCdnProxy; |
| 6 | use Apie\JavascriptCdn\ValueObjects\JavascriptCdnPath; |
| 7 | use Nyholm\Psr7\Response; |
| 8 | use Psr\Http\Message\ResponseInterface; |
| 9 | use Psr\Http\Message\ServerRequestInterface; |
| 10 | |
| 11 | class JavascriptCdnProxyController |
| 12 | { |
| 13 | public function __construct(private readonly JavascriptCdnProxy $proxy) |
| 14 | { |
| 15 | } |
| 16 | |
| 17 | public function __invoke(ServerRequestInterface $request): ResponseInterface |
| 18 | { |
| 19 | try { |
| 20 | $path = new JavascriptCdnPath($request->getAttribute('path')); |
| 21 | } catch (InvalidStringForValueObjectException $e) { |
| 22 | return new Response(400, ['Content-Type' => 'text/plain'], 'Invalid npm package path.'); |
| 23 | } |
| 24 | |
| 25 | return $this->proxy->getResponse($path); |
| 26 | } |
| 27 | } |