Special case opus mime detction
[mediawiki.git] / includes / EventRelayerGroup.php
blob9360693a4b8e368635d624a02d2b0dd16a98630b
1 <?php
2 use MediaWiki\MediaWikiServices;
4 /**
5 * Factory class for spawning EventRelayer objects using configuration
7 * @author Aaron Schulz
8 * @since 1.27
9 */
10 class EventRelayerGroup {
11 /** @var array[] */
12 protected $configByChannel = [];
14 /** @var EventRelayer[] */
15 protected $relayers = [];
17 /**
18 * @param array[] $config Channel configuration
20 public function __construct( array $config ) {
21 $this->configByChannel = $config;
24 /**
25 * @deprecated since 1.27 Use MediaWikiServices::getInstance()->getEventRelayerGroup()
26 * @return EventRelayerGroup
28 public static function singleton() {
29 return MediaWikiServices::getInstance()->getEventRelayerGroup();
32 /**
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] )
38 ? $channel
39 : 'default';
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];