|
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\Package\Types; |
|
10
|
|
|
use BEAR\Resource\ResourceInterface; |
|
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
|
|
|
use function assert; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @psalm-import-type Globals from RouterInterface |
|
20
|
|
|
* @psalm-import-type Server from RouterInterface |
|
21
|
|
|
* @psalm-import-type AppName from Types |
|
22
|
|
|
* @psalm-import-type Context from Types |
|
23
|
|
|
* @psalm-import-type AppDir from Types |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
final class Bootstrap |
|
27
|
|
|
{ |
|
28
|
|
|
private string $appDir; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(AbstractAppMeta $meta) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->appDir = $meta->appDir; |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param AppName $appName |
|
|
|
|
|
|
37
|
|
|
* @param Context $context |
|
|
|
|
|
|
38
|
|
|
* @param Globals $globals |
|
|
|
|
|
|
39
|
|
|
* @param Server $server |
|
|
|
|
|
|
40
|
|
|
* |
|
41
|
|
|
* @return 0|1 |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
|
|
public function __invoke(string $appName, string $context, array $globals, array $server): int |
|
44
|
|
|
{ |
|
45
|
|
|
assert($this->appDir !== ''); |
|
46
|
|
|
$injector = Injector::getInstance($appName, $context, $this->appDir); |
|
47
|
|
|
$injector->getInstance(HttpCacheInterface::class); |
|
48
|
|
|
$router = $injector->getInstance(RouterInterface::class); |
|
49
|
|
|
assert($router instanceof RouterInterface); |
|
50
|
|
|
$request = $router->match($globals, $server); |
|
51
|
|
|
try { |
|
52
|
|
|
/** @psalm-suppress all */ |
|
53
|
|
|
$resource = $injector->getInstance(ResourceInterface::class); |
|
54
|
|
|
$resource->{$request->method}->uri($request->path)($request->query); |
|
55
|
|
|
} catch (Throwable) { |
|
56
|
|
|
$injector->getInstance(TransferInterface::class); |
|
57
|
|
|
|
|
58
|
|
|
return 1; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// @codeCoverageIgnoreStart |
|
62
|
|
|
return 0; |
|
63
|
|
|
// @codeCoverageIgnoreEnd |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..