Skip to content

Commit dbed97b

Browse files
committed
add latest drift server
1 parent dd55162 commit dbed97b

File tree

3 files changed

+48
-17
lines changed

3 files changed

+48
-17
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"php": "^7.4|^8.0",
1818
"antidot-fw/framework": "^0.2.0",
1919
"beberlei/assert": "^3.3",
20-
"drift/server": "^0.1.18",
20+
"drift/server": "^0.1.20",
2121
"psr/container": "^1.0.0",
2222
"ramsey/uuid": "^4.1",
2323
"react/http": "^1.2"
@@ -62,5 +62,8 @@
6262
"laminas": {
6363
"config-provider": "Antidot\\React\\Container\\Config\\ConfigProvider"
6464
}
65+
},
66+
"suggest": {
67+
"react/filesystem": "^0.1.2"
6568
}
6669
}

src/Container/Config/ConfigProvider.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,7 @@ public function __invoke(): array
3333
Socket::class => SocketFactory::class,
3434
],
3535
],
36-
'console' => [
37-
'commands' => [
38-
'server:run' => RunServerCommand::class,
39-
'server:watch' => WatchServerCommand::class
40-
],
41-
'factories' => [
42-
RunServerCommand::class => RunServerCommandFactory::class,
43-
WatchServerCommand::class => WatchServerCommandFactory::class,
44-
],
45-
],
36+
'console' => $this->getConsoleConfig(),
4637
'server' => [
4738
'host' => '0.0.0.0',
4839
'port' => 5555,
@@ -53,4 +44,29 @@ public function __invoke(): array
5344
]
5445
];
5546
}
47+
48+
private function getConsoleConfig(): array
49+
{
50+
$hasWatcher = class_exists(WatchServerCommand::class);
51+
52+
return $hasWatcher
53+
? [
54+
'commands' => [
55+
'server:run' => RunServerCommand::class,
56+
'server:watch' => WatchServerCommand::class
57+
],
58+
'factories' => [
59+
RunServerCommand::class => RunServerCommandFactory::class,
60+
WatchServerCommand::class => WatchServerCommandFactory::class,
61+
]
62+
]
63+
: [
64+
'commands' => [
65+
'server:run' => RunServerCommand::class,
66+
],
67+
'factories' => [
68+
RunServerCommand::class => RunServerCommandFactory::class,
69+
]
70+
];
71+
}
5672
}

src/DriftKernelAdapter.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,27 @@
1818

1919
final class DriftKernelAdapter implements KernelAdapter
2020
{
21-
private FilesystemInterface $filesystem;
2221
private ServerContext $serverContext;
2322
private MimeTypeChecker $mimeTypeChecker;
2423
private string $rootPath;
2524
private ContainerInterface $container;
2625
private ReactApplication $application;
26+
/** @var object|FilesystemInterface|null */
27+
private ?object $filesystem = null;
2728

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+
*/
2837
public function __construct(
2938
ServerContext $serverContext,
30-
FilesystemInterface $filesystem,
3139
MimeTypeChecker $mimeTypeChecker,
32-
string $rootPath
40+
string $rootPath,
41+
?FilesystemInterface $filesystem
3342
) {
3443
$container = require $rootPath . '/config/container.php';
3544
assert($container instanceof ContainerInterface);
@@ -50,12 +59,15 @@ public static function create(
5059
LoopInterface $loop,
5160
string $rootPath,
5261
ServerContext $serverContext,
53-
FilesystemInterface $filesystem,
5462
OutputPrinter $outputPrinter,
55-
MimeTypeChecker $mimeTypeChecker
63+
MimeTypeChecker $mimeTypeChecker,
64+
?FilesystemInterface $filesystem = null
5665
): PromiseInterface {
66+
if ($filesystem && !class_exists(FilesystemInterface::class)) {
67+
throw new \RuntimeException('Install react/filesystem package.');
68+
}
5769

58-
return resolve(new self($serverContext, $filesystem, $mimeTypeChecker, $rootPath))
70+
return resolve(new self($serverContext, $mimeTypeChecker, $rootPath, $filesystem))
5971
->then(fn (KernelAdapter $adapter): KernelAdapter => $adapter);
6072
}
6173

0 commit comments

Comments
 (0)