diff options
author | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2025-01-07 01:17:32 +0100 |
---|---|---|
committer | Bartosz Dziewoński <dziewonski@fastmail.fm> | 2025-02-12 04:31:10 +0100 |
commit | 837128824f750f439e272431344a9a225fb35d39 (patch) | |
tree | 29bcf23df5887205be1aa24f5cfbf7316461448a /includes/Notification/RecipientSet.php | |
parent | 3258c2ef99d96cbab7a86c6e674edb257b6e9296 (diff) | |
download | mediawikicore-837128824f750f439e272431344a9a225fb35d39.tar.gz mediawikicore-837128824f750f439e272431344a9a225fb35d39.zip |
Add a built-in way to send notifications
Create a provider pattern for sending notifications (T383992).
There is no base notifications handler in core; they can only
be provided by extensions.
A handler in the Echo extension, compatible with the existing
Echo notifications system, will be implemented in T383993.
Co-Authored-By: Piotr Miazga <pmiazga@wikimedia.org>
Bug: T383992
Change-Id: I16b309935c3d29c3cde4459b5e36abce063a8534
Diffstat (limited to 'includes/Notification/RecipientSet.php')
-rw-r--r-- | includes/Notification/RecipientSet.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/includes/Notification/RecipientSet.php b/includes/Notification/RecipientSet.php new file mode 100644 index 000000000000..b8f2895fd5e9 --- /dev/null +++ b/includes/Notification/RecipientSet.php @@ -0,0 +1,40 @@ +<?php + +namespace MediaWiki\Notification; + +use ArrayIterator; +use IteratorAggregate; +use MediaWiki\User\UserIdentity; +use Wikimedia\Assert\Assert; + +/** + * @since 1.44 + * @unstable + */ +class RecipientSet implements IteratorAggregate { + + /** + * @var UserIdentity[] + */ + private array $recipients; + + /** + * @param UserIdentity|UserIdentity[] $recipients + */ + public function __construct( $recipients ) { + if ( !is_array( $recipients ) ) { + $recipients = [ $recipients ]; + } + Assert::parameterElementType( UserIdentity::class, $recipients, '$recipients' ); + $this->recipients = $recipients; + } + + /** @return UserIdentity[] */ + public function getRecipients(): array { + return $this->recipients; + } + + public function getIterator(): ArrayIterator { + return new ArrayIterator( $this->recipients ); + } +} |