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
|
|
|
public function __construct( |
30
|
|
|
ServerContext $serverContext, |
31
|
|
|
MimeTypeChecker $mimeTypeChecker, |
32
|
|
|
string $rootPath, |
33
|
|
|
?object $filesystem |
34
|
|
|
) { |
35
|
|
|
$container = require $rootPath . '/config/container.php'; |
36
|
|
|
assert($container instanceof ContainerInterface); |
37
|
|
|
$application = $container->get(Application::class); |
38
|
|
|
assert($application instanceof ReactApplication); |
39
|
|
|
(require $rootPath . '/router/middleware.php')($application, $container); |
40
|
|
|
(require $rootPath . '/router/routes.php')($application, $container); |
41
|
|
|
$this->container = $container; |
42
|
|
|
$this->application = $application; |
43
|
|
|
$this->serverContext = $serverContext; |
44
|
|
|
$this->filesystem = $filesystem; |
45
|
|
|
$this->mimeTypeChecker = $mimeTypeChecker; |
46
|
|
|
$this->rootPath = $rootPath; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** @psalm-suppress MixedReturnTypeCoercion */ |
50
|
|
|
public static function create( |
51
|
|
|
LoopInterface $loop, |
52
|
|
|
string $rootPath, |
53
|
|
|
ServerContext $serverContext, |
54
|
|
|
OutputPrinter $outputPrinter, |
55
|
|
|
MimeTypeChecker $mimeTypeChecker, |
56
|
|
|
$filesystem = null |
57
|
|
|
): PromiseInterface { |
58
|
|
|
if ($filesystem && !class_exists(FilesystemInterface::class)) { |
59
|
|
|
throw new \RuntimeException('Install react/filesystem package.'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return resolve(new self($serverContext, $mimeTypeChecker, $rootPath, $filesystem)) |
63
|
|
|
->then(fn (KernelAdapter $adapter): KernelAdapter => $adapter); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @psalm-suppress LessSpecificImplementedReturnType |
68
|
|
|
* @param ServerRequestInterface $request |
69
|
|
|
* @return PromiseResponse |
70
|
|
|
*/ |
71
|
|
|
public function handle(ServerRequestInterface $request): PromiseResponse |
72
|
|
|
{ |
73
|
|
|
return $this->application->handle($request); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public static function getStaticFolder(): ?string |
77
|
|
|
{ |
78
|
|
|
return 'public'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function shutDown(): PromiseInterface |
82
|
|
|
{ |
83
|
|
|
return resolve('nothing to do'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get watcher folders. |
88
|
|
|
* |
89
|
|
|
* @return string[] |
90
|
|
|
*/ |
91
|
|
|
public static function getObservableFolders(): array |
92
|
|
|
{ |
93
|
|
|
return ['src', 'public', 'templates']; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get watcher folders. |
98
|
|
|
* |
99
|
|
|
* @return string[] |
100
|
|
|
*/ |
101
|
|
|
public static function getObservableExtensions(): array |
102
|
|
|
{ |
103
|
|
|
return ['php', 'yml', 'yaml', 'xml', 'css', 'js', 'html', 'twig']; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get watcher ignoring folders. |
108
|
|
|
* |
109
|
|
|
* @return string[] |
110
|
|
|
*/ |
111
|
|
|
public static function getIgnorableFolders(): array |
112
|
|
|
{ |
113
|
|
|
return ['var']; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
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