-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d1bfe3
commit a692bf0
Showing
8 changed files
with
128 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Projector; | ||
|
||
use Patchlevel\EventSourcing\Metadata\MetadataException; | ||
|
||
use function sprintf; | ||
|
||
final class SubscribeAllNotSupported extends MetadataException | ||
{ | ||
/** @param class-string $projector */ | ||
public function __construct(string $projector, string $method) | ||
{ | ||
parent::__construct( | ||
sprintf( | ||
'subscribe all (*) not supported in projector "%s" method "%s"', | ||
$projector, | ||
$method, | ||
), | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\WatchServer; | ||
|
||
use Patchlevel\EventSourcing\Attribute\Subscribe; | ||
use Patchlevel\EventSourcing\EventBus\Message; | ||
|
||
final class WatchListener | ||
{ | ||
public function __construct( | ||
private readonly WatchServerClient $client, | ||
) { | ||
} | ||
|
||
#[Subscribe('*')] | ||
public function __invoke(Message $message): void | ||
{ | ||
try { | ||
$this->client->send($message); | ||
} catch (SendingFailed) { | ||
// to nothing | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,4 +112,54 @@ public function __invoke(Message $message): void | |
new ListenerDescriptor($listener2->__invoke(...)), | ||
], $listeners); | ||
} | ||
|
||
public function testSubscribeAll(): void | ||
{ | ||
$listener = new class { | ||
#[Subscribe('*')] | ||
public function __invoke(Message $message): void | ||
{ | ||
} | ||
}; | ||
|
||
$event = new ProfileCreated( | ||
ProfileId::fromString('1'), | ||
Email::fromString('[email protected]'), | ||
); | ||
|
||
$eventBus = new AttributeListenerProvider([$listener]); | ||
$listeners = $eventBus->listenersForEvent($event); | ||
|
||
self::assertEquals([ | ||
new ListenerDescriptor($listener->__invoke(...)), | ||
], $listeners); | ||
} | ||
|
||
public function testMixedSubscribeTypes(): void | ||
{ | ||
$listener = new class { | ||
#[Subscribe('*')] | ||
public function foo(Message $message): void | ||
{ | ||
} | ||
|
||
#[Subscribe(ProfileCreated::class)] | ||
public function bar(Message $message): void | ||
{ | ||
} | ||
}; | ||
|
||
$event = new ProfileCreated( | ||
ProfileId::fromString('1'), | ||
Email::fromString('[email protected]'), | ||
); | ||
|
||
$eventBus = new AttributeListenerProvider([$listener]); | ||
$listeners = $eventBus->listenersForEvent($event); | ||
|
||
self::assertEquals([ | ||
new ListenerDescriptor($listener->bar(...)), | ||
new ListenerDescriptor($listener->foo(...)), | ||
], $listeners); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters