-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
77 changed files
with
2,429 additions
and
1,984 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
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AwdStudio\Bus\Exception; | ||
|
||
final class InvalidHandler extends BusException | ||
{ | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AwdStudio\Bus\Exception; | ||
|
||
final class NoHandlerDefined extends BusException | ||
{ | ||
public function __construct(object $message) | ||
{ | ||
parent::__construct(\sprintf('No handlers for a message "%s"', \get_class($message)), 1, null); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AwdStudio\Bus\Handler; | ||
|
||
use AwdStudio\Bus\HandlerLocator; | ||
|
||
/** | ||
* @psalm-template TCallback of callable | ||
* @phpstan-template TCallback of callable | ||
* | ||
* @extends HandlerLocator<TCallback> | ||
*/ | ||
interface HandlerRegistry extends HandlerLocator | ||
{ | ||
/** | ||
* Registers a handler from a PSR-container as a message handler. | ||
* | ||
* @param string $messageId | ||
* @param string $handlerId | ||
* | ||
* @throws \AwdStudio\Bus\Exception\InvalidHandler | ||
* | ||
* @psalm-param class-string $messageId | ||
* @phpstan-param class-string $messageId | ||
*/ | ||
public function register(string $messageId, string $handlerId): void; | ||
} |
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,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AwdStudio\Bus\Handler; | ||
|
||
use AwdStudio\Bus\HandlerLocator; | ||
|
||
/** | ||
* @psalm-external-mutation-free | ||
* | ||
* @implements HandlerLocator<callable(object $message, mixed ...$extraParams): mixed> | ||
*/ | ||
final class InMemoryHandlerLocator implements HandlerLocator | ||
{ | ||
/** | ||
* @var array | ||
* | ||
* @psalm-var array<class-string, list<callable(object $message, mixed ...$extraParams): mixed>> | ||
* @phpstan-var array<class-string, list<callable(object $message, mixed ...$extraParams): mixed>> | ||
*/ | ||
private $handlers; | ||
|
||
public function __construct() | ||
{ | ||
$this->handlers = []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function add(string $messageId, callable $handler): void | ||
{ | ||
$this->handlers[$messageId][] = $handler; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has(string $messageId): bool | ||
{ | ||
return !empty($this->handlers[$messageId]); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get(string $messageId): \Traversable | ||
{ | ||
foreach ($this->handlers[$messageId] ?? [] as $handler) { | ||
yield $handler; | ||
} | ||
} | ||
} |
Oops, something went wrong.