File tree Expand file tree Collapse file tree
src/Subscription/StatefulSubscriber
tests/Integration/Subscription Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55namespace Patchlevel \EventSourcing \Subscription \StatefulSubscriber ;
66
7+ use LogicException ;
78use Patchlevel \EventSourcing \Subscription \Subscriber \BatchableSubscriber ;
89use Patchlevel \Hydrator \Attribute \Ignore ;
10+ use ReflectionClass ;
11+
12+ use const PHP_VERSION_ID ;
913
1014abstract class StatefulSubscriber implements BatchableSubscriber
1115{
@@ -35,4 +39,17 @@ public function forceCommit(): bool
3539 {
3640 return false ;
3741 }
42+
43+ public static function createLazy (StatefulSubscriberStore $ store ): static
44+ {
45+ if (PHP_VERSION_ID < 80400 ) {
46+ throw new LogicException ('Lazy subscriber is only supported on PHP 8.4 or higher ' );
47+ }
48+
49+ $ reflection = new ReflectionClass (static ::class);
50+
51+ return $ reflection ->newLazyGhost (static function ($ object ) use ($ store ): void {
52+ $ object ->__construct ($ store );
53+ });
54+ }
3855}
Original file line number Diff line number Diff line change @@ -1670,7 +1670,7 @@ public function testStatefulSubscriber(): void
16701670 $ schemaDirector ->create ();
16711671
16721672 $ subscriberRepository = new MetadataSubscriberAccessorRepository ([
1673- new ProfileInlineStatefulSubscriber (
1673+ ProfileInlineStatefulSubscriber:: createLazy (
16741674 $ stateStore ,
16751675 ),
16761676 ]);
You can’t perform that action at this time.
0 commit comments