|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BEAR\Package\Compiler; |
|
6
|
|
|
|
|
7
|
|
|
use BEAR\Package\Compiler\Module\App; |
|
8
|
|
|
use BEAR\Package\Injector; |
|
9
|
|
|
use BEAR\Resource\ResourceObject; |
|
10
|
|
|
use BEAR\Sunday\Extension\Application\AppInterface; |
|
11
|
|
|
use Throwable; |
|
12
|
|
|
|
|
13
|
|
|
use function assert; |
|
14
|
|
|
use function dirname; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @psalm-import-type Globals from \BEAR\Sunday\Extension\Router\RouterInterface |
|
18
|
|
|
* @psalm-import-type Server from \BEAR\Sunday\Extension\Router\RouterInterface |
|
19
|
|
|
*/ |
|
20
|
|
|
final class Bootstrap |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @psalm-param Globals $globals |
|
24
|
|
|
* @psalm-param Server $server |
|
25
|
|
|
* @phpstan-param array<string, mixed> $globals |
|
26
|
|
|
* @phpstan-param array<string, mixed> $server |
|
27
|
|
|
* |
|
28
|
|
|
* @return 0|1 |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
|
public function __invoke(string $context, array $globals, array $server): int |
|
31
|
|
|
{ |
|
32
|
|
|
$tmpDir = dirname(__DIR__, 2) . '/tests/tmp'; |
|
33
|
|
|
$app = Injector::getInstance('BEAR\Package\Compiler', $context, $tmpDir)->getInstance(AppInterface::class); |
|
34
|
|
|
assert($app instanceof App); |
|
35
|
|
|
if ($app->httpCache->isNotModified($server)) { |
|
36
|
|
|
$app->httpCache->transfer(); |
|
37
|
|
|
|
|
38
|
|
|
return 0; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$request = $app->router->match($globals, $server); |
|
42
|
|
|
try { |
|
43
|
|
|
/** @psalm-suppress all */ |
|
44
|
|
|
$response = $app->resource->{$request->method}->uri($request->path)($request->query); |
|
45
|
|
|
assert($response instanceof ResourceObject); |
|
46
|
|
|
$response->transfer($app->responder, $server); |
|
47
|
|
|
|
|
48
|
|
|
return 0; |
|
49
|
|
|
} catch (Throwable $e) { |
|
50
|
|
|
$app->throwableHandler->handle($e, $request)->transfer(); |
|
51
|
|
|
|
|
52
|
|
|
return 1; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.