2 use MediaWiki\MediaWikiServices
;
5 * Factory class for spawning EventRelayer objects using configuration
10 class EventRelayerGroup
{
12 protected $configByChannel = [];
14 /** @var EventRelayer[] */
15 protected $relayers = [];
18 * @param array[] $config Channel configuration
20 public function __construct( array $config ) {
21 $this->configByChannel
= $config;
25 * @deprecated since 1.27 Use MediaWikiServices::getInstance()->getEventRelayerGroup()
26 * @return EventRelayerGroup
28 public static function singleton() {
29 return MediaWikiServices
::getInstance()->getEventRelayerGroup();
33 * @param string $channel
34 * @return EventRelayer Relayer instance that handles the given channel
36 public function getRelayer( $channel ) {
37 $channelKey = isset( $this->configByChannel
[$channel] )
41 if ( !isset( $this->relayers
[$channelKey] ) ) {
42 if ( !isset( $this->configByChannel
[$channelKey] ) ) {
43 throw new UnexpectedValueException( "No config for '$channelKey'" );
46 $config = $this->configByChannel
[$channelKey];
47 $class = $config['class'];
49 $this->relayers
[$channelKey] = new $class( $config );
52 return $this->relayers
[$channelKey];