-
Notifications
You must be signed in to change notification settings - Fork 14
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
10 changed files
with
109 additions
and
14 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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Freddie\Subscription; | ||
|
||
use Symfony\Component\Uid\Ulid; | ||
|
||
use function array_map; | ||
|
||
final class Subscriber | ||
{ | ||
/** | ||
* @var Subscription[] | ||
*/ | ||
public readonly array $subscriptions; | ||
|
||
/** | ||
* @var callable | ||
*/ | ||
private $callback; | ||
|
||
/** | ||
* @param string[] $topics | ||
*/ | ||
public function __construct( | ||
public readonly array $topics, | ||
public readonly mixed $payload = null, | ||
public readonly Ulid $id = new Ulid(), | ||
public bool $active = true, | ||
) { | ||
$this->subscriptions = array_map( | ||
fn(string $topic) => new Subscription($this, $topic), | ||
$this->topics, | ||
); | ||
} | ||
|
||
public function setCallback(callable $callback): void | ||
{ | ||
$this->callback = $callback; | ||
} | ||
|
||
/** | ||
* @param mixed ...$args | ||
*/ | ||
public function __invoke(...$args): void | ||
{ | ||
($this->callback)(...$args); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Freddie\Subscription; | ||
|
||
final class Subscription | ||
{ | ||
public function __construct( | ||
public Subscriber $subscriber, | ||
public string $topic, | ||
) { | ||
} | ||
} |
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