1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BEAR\Package\Compiler; |
6
|
|
|
|
7
|
|
|
use BEAR\AppMeta\AbstractAppMeta; |
8
|
|
|
use BEAR\Package\Injector; |
9
|
|
|
use BEAR\Resource\ResourceInterface; |
10
|
|
|
use BEAR\Sunday\Extension\Application\AppInterface; |
11
|
|
|
use BEAR\Sunday\Extension\Router\RouterInterface; |
12
|
|
|
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface; |
13
|
|
|
use BEAR\Sunday\Extension\Transfer\TransferInterface; |
14
|
|
|
use Throwable; |
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
|
|
|
|
21
|
|
|
final class Bootstrap |
22
|
|
|
{ |
23
|
|
|
/** @var string */ |
24
|
|
|
private $appDir; |
25
|
|
|
|
26
|
|
|
public function __construct(AbstractAppMeta $meta) |
27
|
|
|
{ |
28
|
|
|
$this->appDir = $meta->appDir; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @psalm-param Globals $globals |
33
|
|
|
* @psalm-param Server $server |
34
|
|
|
* @phpstan-param array<string, mixed> $globals |
35
|
|
|
* @phpstan-param array<string, mixed> $server |
36
|
|
|
* |
37
|
|
|
* @return 0|1 |
|
|
|
|
38
|
|
|
*/ |
39
|
|
|
public function __invoke(string $appName, string $context, array $globals, array $server): int |
40
|
|
|
{ |
41
|
|
|
$injector = Injector::getInstance($appName, $context, $this->appDir); |
42
|
|
|
$app = $injector->getInstance(AppInterface::class); |
|
|
|
|
43
|
|
|
$injector->getInstance(HttpCacheInterface::class); |
44
|
|
|
$router = $injector->getInstance(RouterInterface::class); |
45
|
|
|
$request = $router->match($globals, $server); |
46
|
|
|
try { |
47
|
|
|
/** @psalm-suppress all */ |
48
|
|
|
$resource = $injector->getInstance(ResourceInterface::class); |
49
|
|
|
$resource->{$request->method}->uri($request->path)($request->query); |
50
|
|
|
} catch (Throwable $e) { |
51
|
|
|
$injector->getInstance(TransferInterface::class); |
52
|
|
|
|
53
|
|
|
return 1; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// @codeCoverageIgnoreStart |
57
|
|
|
return 0; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
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.