1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Antidot\React; |
6
|
|
|
|
7
|
|
|
use Antidot\Application\Http\Application; |
8
|
|
|
use Drift\Console\OutputPrinter; |
9
|
|
|
use Drift\Server\Adapter\KernelAdapter; |
10
|
|
|
use Drift\Server\Context\ServerContext; |
11
|
|
|
use Drift\Server\Mime\MimeTypeChecker; |
12
|
|
|
use Psr\Container\ContainerInterface; |
13
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
14
|
|
|
use React\EventLoop\LoopInterface; |
15
|
|
|
use React\Filesystem\FilesystemInterface; |
|
|
|
|
16
|
|
|
use React\Promise\PromiseInterface; |
17
|
|
|
use function React\Promise\resolve; |
18
|
|
|
|
19
|
|
|
final class DriftKernelAdapter implements KernelAdapter |
20
|
|
|
{ |
21
|
|
|
private ServerContext $serverContext; |
22
|
|
|
private MimeTypeChecker $mimeTypeChecker; |
23
|
|
|
private string $rootPath; |
24
|
|
|
private ContainerInterface $container; |
25
|
|
|
private ReactApplication $application; |
26
|
|
|
/** @var object|FilesystemInterface|null */ |
27
|
|
|
private ?object $filesystem = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* DriftKernelAdapter constructor. |
31
|
|
|
* @param ServerContext $serverContext |
32
|
|
|
* @param MimeTypeChecker $mimeTypeChecker |
33
|
|
|
* @param string $rootPath |
34
|
|
|
* @psalm-suppress UndefinedClass |
35
|
|
|
* @param FilesystemInterface|null $filesystem |
36
|
|
|
*/ |
37
|
|
|
public function __construct( |
38
|
|
|
ServerContext $serverContext, |
39
|
|
|
MimeTypeChecker $mimeTypeChecker, |
40
|
|
|
string $rootPath, |
41
|
|
|
?FilesystemInterface $filesystem |
42
|
|
|
) { |
43
|
|
|
$container = require $rootPath . '/config/container.php'; |
44
|
|
|
assert($container instanceof ContainerInterface); |
45
|
|
|
$application = $container->get(Application::class); |
46
|
|
|
assert($application instanceof ReactApplication); |
47
|
|
|
(require $rootPath . '/router/middleware.php')($application, $container); |
48
|
|
|
(require $rootPath . '/router/routes.php')($application, $container); |
49
|
|
|
$this->container = $container; |
50
|
|
|
$this->application = $application; |
51
|
|
|
$this->serverContext = $serverContext; |
52
|
|
|
$this->filesystem = $filesystem; |
53
|
|
|
$this->mimeTypeChecker = $mimeTypeChecker; |
54
|
|
|
$this->rootPath = $rootPath; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** @psalm-suppress MixedReturnTypeCoercion */ |
58
|
|
|
public static function create( |
59
|
|
|
LoopInterface $loop, |
60
|
|
|
string $rootPath, |
61
|
|
|
ServerContext $serverContext, |
62
|
|
|
OutputPrinter $outputPrinter, |
63
|
|
|
MimeTypeChecker $mimeTypeChecker, |
64
|
|
|
?FilesystemInterface $filesystem = null |
65
|
|
|
): PromiseInterface { |
66
|
|
|
if ($filesystem && !class_exists(FilesystemInterface::class)) { |
67
|
|
|
throw new \RuntimeException('Install react/filesystem package.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return resolve(new self($serverContext, $mimeTypeChecker, $rootPath, $filesystem)) |
71
|
|
|
->then(fn (KernelAdapter $adapter): KernelAdapter => $adapter); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @psalm-suppress LessSpecificImplementedReturnType |
76
|
|
|
* @param ServerRequestInterface $request |
77
|
|
|
* @return PromiseResponse |
78
|
|
|
*/ |
79
|
|
|
public function handle(ServerRequestInterface $request): PromiseResponse |
80
|
|
|
{ |
81
|
|
|
return $this->application->handle($request); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public static function getStaticFolder(): ?string |
85
|
|
|
{ |
86
|
|
|
return 'public'; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function shutDown(): PromiseInterface |
90
|
|
|
{ |
91
|
|
|
return resolve('nothing to do'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get watcher folders. |
96
|
|
|
* |
97
|
|
|
* @return string[] |
98
|
|
|
*/ |
99
|
|
|
public static function getObservableFolders(): array |
100
|
|
|
{ |
101
|
|
|
return ['src', 'public', 'templates']; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get watcher folders. |
106
|
|
|
* |
107
|
|
|
* @return string[] |
108
|
|
|
*/ |
109
|
|
|
public static function getObservableExtensions(): array |
110
|
|
|
{ |
111
|
|
|
return ['php', 'yml', 'yaml', 'xml', 'css', 'js', 'html', 'twig']; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get watcher ignoring folders. |
116
|
|
|
* |
117
|
|
|
* @return string[] |
118
|
|
|
*/ |
119
|
|
|
public static function getIgnorableFolders(): array |
120
|
|
|
{ |
121
|
|
|
return ['var']; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths