Skip to content

Commit 54dc801

Browse files
committed
Upgrade webonyx graphql to 15.0+
1 parent ebdbef7 commit 54dc801

9 files changed

+66
-25
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
"require": {
2323
"php": "^8.1",
2424
"psr/container": "^1.0|^2.0",
25-
"psr/event-dispatcher": "^1.0",
25+
"railt/event-dispatcher": "^2.0",
2626
"railt/http": "^2.0",
2727
"railt/http-factory": "^2.0",
2828
"railt/http-middleware": "^2.0",
2929
"railt/sdl": "^2.0",
30-
"railt/type-system": "^2.0",
31-
"symfony/event-dispatcher": "^5.4|^6.0"
30+
"railt/type-system": "^2.0"
3231
},
3332
"autoload": {
3433
"psr-4": {

src/Application.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Railt\Foundation;
66

7+
use Psr\EventDispatcher\EventDispatcherInterface;
78
use Railt\Contracts\Http\Middleware\MiddlewareInterface;
9+
use Railt\EventDispatcher\EventDispatcher;
810
use Railt\Foundation\Connection\OnDestructor;
911
use Railt\Foundation\Event\Connection\ConnectionClosed;
1012
use Railt\Foundation\Event\Connection\ConnectionEstablished;
@@ -18,8 +20,6 @@
1820
use Railt\SDL\Compiler;
1921
use Railt\SDL\CompilerInterface;
2022
use Railt\TypeSystem\DictionaryInterface;
21-
use Symfony\Component\EventDispatcher\EventDispatcher;
22-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
2323

2424
final class Application implements ApplicationInterface
2525
{
@@ -32,6 +32,8 @@ final class Application implements ApplicationInterface
3232

3333
private readonly MutablePipelineInterface $pipeline;
3434

35+
private readonly EventDispatcherInterface $dispatcher;
36+
3537
/**
3638
* @param iterable<array-key, MiddlewareInterface>|MutablePipelineInterface $middleware
3739
* @param iterable<array-key, ExtensionInterface>|Repository $extensions
@@ -41,22 +43,18 @@ public function __construct(
4143
private readonly CompilerInterface $compiler = new Compiler(),
4244
iterable|MutablePipelineInterface $middleware = [],
4345
iterable|Repository $extensions = [],
44-
private readonly EventDispatcherInterface $dispatcher = new EventDispatcher(),
46+
?EventDispatcherInterface $dispatcher = null,
4547
) {
46-
if (!$middleware instanceof MutablePipelineInterface) {
47-
$middleware = new Pipeline($middleware);
48-
}
49-
50-
if (!$extensions instanceof Repository) {
51-
$extensions = new Repository($extensions);
52-
}
53-
48+
$this->pipeline = !$middleware instanceof MutablePipelineInterface
49+
? new Pipeline($middleware)
50+
: $middleware;
51+
$this->extensions = !$extensions instanceof Repository
52+
? new Repository($extensions)
53+
: $extensions;
54+
$this->dispatcher = new EventDispatcher($dispatcher);
5455
/** @psalm-suppress PropertyTypeCoercion */
5556
$this->connections = new \WeakMap();
5657

57-
$this->extensions = $extensions;
58-
$this->pipeline = $middleware;
59-
6058
$this->bootDefaultExtensions();
6159
}
6260

src/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Railt\Contracts\Http\ResponseInterface;
1010
use Railt\Http\Middleware\PipelineInterface;
1111
use Railt\TypeSystem\DictionaryInterface;
12-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12+
use Railt\EventDispatcher\EventDispatcherInterface;
1313

1414
final class Connection implements ConnectionInterface
1515
{

src/ExecutorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Railt\Contracts\Http\Middleware\RequestHandlerInterface;
88
use Railt\TypeSystem\DictionaryInterface;
9-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9+
use Railt\EventDispatcher\EventDispatcherInterface;
1010

1111
interface ExecutorInterface
1212
{

src/Extension/DefaultValueResolverExtension.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,28 @@
1010
use Railt\TypeSystem\ListType;
1111
use Railt\TypeSystem\NonNullType;
1212
use Railt\TypeSystem\WrappingTypeInterface;
13-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13+
use Railt\EventDispatcher\EventDispatcherInterface;
1414

1515
final class DefaultValueResolverExtension implements ExtensionInterface
1616
{
17+
/**
18+
* @var \Closure(FieldResolving):void
19+
*/
20+
private readonly \Closure $fieldResolving;
21+
22+
public function __construct()
23+
{
24+
$this->fieldResolving = $this->tryFieldResolving(...);
25+
}
26+
1727
public function load(EventDispatcherInterface $dispatcher): void
1828
{
19-
$dispatcher->addListener(FieldResolving::class, $this->tryFieldResolving(...));
29+
$dispatcher->addListener(FieldResolving::class, $this->fieldResolving);
30+
}
31+
32+
public function unload(EventDispatcherInterface $dispatcher): void
33+
{
34+
$dispatcher->removeListener(FieldResolving::class, $this->fieldResolving);
2035
}
2136

2237
private function tryFieldResolving(FieldResolving $event): void

src/Extension/ExtensionInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
namespace Railt\Foundation\Extension;
66

7-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7+
use Railt\EventDispatcher\EventDispatcherInterface;
88

99
interface ExtensionInterface
1010
{
1111
public function load(EventDispatcherInterface $dispatcher): void;
12+
13+
public function unload(EventDispatcherInterface $dispatcher): void;
1214
}

src/Extension/Repository.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Railt\Foundation\Extension;
66

7-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7+
use Railt\EventDispatcher\EventDispatcherInterface;
88

99
/**
1010
* @template-implements \IteratorAggregate<array-key, ExtensionInterface>
1111
*/
12-
final class Repository implements ExtensionInterface, \IteratorAggregate, \Countable
12+
final class Repository implements RepositoryInterface, \IteratorAggregate
1313
{
1414
/**
1515
* @var list<ExtensionInterface>
@@ -46,6 +46,17 @@ public function load(EventDispatcherInterface $dispatcher): void
4646
}
4747
}
4848

49+
public function unload(EventDispatcherInterface $dispatcher): void
50+
{
51+
while ($this->loaded !== []) {
52+
$extension = \array_shift($this->loaded);
53+
54+
$extension->unload($dispatcher);
55+
56+
$this->registered[] = $extension;
57+
}
58+
}
59+
4960
public function count(): int
5061
{
5162
return \count($this->loaded) + \count($this->registered);

src/Extension/RepositoryInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Railt\Foundation\Extension;
6+
7+
/**
8+
* @template-implements \Traversable<array-key, ExtensionInterface>
9+
*/
10+
interface RepositoryInterface extends ExtensionInterface, \Traversable, \Countable
11+
{
12+
/**
13+
* @param ExtensionInterface $extension
14+
*/
15+
public function register(ExtensionInterface $extension): void;
16+
}

tests/Architecture/ComposerDependenciesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testDependencies(): Rule
2828
Selector::namespace('Railt\Http\Middleware'),
2929
Selector::namespace('Railt\SDL'),
3030
Selector::namespace('Railt\TypeSystem'),
31-
Selector::namespace('Symfony\Component\EventDispatcher'),
31+
Selector::namespace('Railt\EventDispatcher'),
3232
)
3333
;
3434
}

0 commit comments

Comments
 (0)