Fix use of RawMessage in Status::getMessage()
[mediawiki.git] / includes / EventRelayerGroup.php
blob9dfac795a6a4ce59c1cb97363ad24bacb897e200
1 <?php
2 /**
3 * Factory class for spawning EventRelayer objects using configuration
5 * @author Aaron Schulz
6 * @since 1.27
7 */
8 class EventRelayerGroup {
9 /** @var array[] */
10 protected $configByChannel = [];
12 /** @var EventRelayer[] */
13 protected $relayers = [];
15 /** @var EventRelayerGroup */
16 protected static $instance = null;
18 /**
19 * @param Config $config
21 protected function __construct( Config $config ) {
22 $this->configByChannel = $config->get( 'EventRelayerConfig' );
25 /**
26 * @return EventRelayerGroup
28 public static function singleton() {
29 if ( !self::$instance ) {
30 self::$instance = new self( RequestContext::getMain()->getConfig() );
33 return self::$instance;
36 /**
37 * @param string $channel
38 * @return EventRelayer Relayer instance that handles the given channel
40 public function getRelayer( $channel ) {
41 $channelKey = isset( $this->configByChannel[$channel] )
42 ? $channel
43 : 'default';
45 if ( !isset( $this->relayers[$channelKey] ) ) {
46 if ( !isset( $this->configByChannel[$channelKey] ) ) {
47 throw new UnexpectedValueException( "No config for '$channelKey'" );
50 $config = $this->configByChannel[$channelKey];
51 $class = $config['class'];
53 $this->relayers[$channelKey] = new $class( $config );
56 return $this->relayers[$channelKey];