2015-12-29 19:45:23 +00:00
|
|
|
<?php
|
2016-04-23 00:09:14 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
|
2015-12-29 19:45:23 +00:00
|
|
|
/**
|
|
|
|
|
* Factory class for spawning EventRelayer objects using configuration
|
|
|
|
|
*
|
|
|
|
|
* @author Aaron Schulz
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
class EventRelayerGroup {
|
|
|
|
|
/** @var array[] */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $configByChannel = [];
|
2015-12-29 19:45:23 +00:00
|
|
|
|
|
|
|
|
/** @var EventRelayer[] */
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $relayers = [];
|
2015-12-29 19:45:23 +00:00
|
|
|
|
|
|
|
|
/**
|
2016-04-23 00:09:14 +00:00
|
|
|
* @param array[] $config Channel configuration
|
2015-12-29 19:45:23 +00:00
|
|
|
*/
|
2016-04-23 00:09:14 +00:00
|
|
|
public function __construct( array $config ) {
|
|
|
|
|
$this->configByChannel = $config;
|
2015-12-29 19:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-04-23 00:09:14 +00:00
|
|
|
* @deprecated since 1.27 Use MediaWikiServices::getInstance()->getEventRelayerGroup()
|
2015-12-29 19:45:23 +00:00
|
|
|
* @return EventRelayerGroup
|
|
|
|
|
*/
|
|
|
|
|
public static function singleton() {
|
2016-04-23 00:09:14 +00:00
|
|
|
return MediaWikiServices::getInstance()->getEventRelayerGroup();
|
2015-12-29 19:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $channel
|
|
|
|
|
* @return EventRelayer Relayer instance that handles the given channel
|
|
|
|
|
*/
|
|
|
|
|
public function getRelayer( $channel ) {
|
|
|
|
|
$channelKey = isset( $this->configByChannel[$channel] )
|
|
|
|
|
? $channel
|
|
|
|
|
: 'default';
|
|
|
|
|
|
|
|
|
|
if ( !isset( $this->relayers[$channelKey] ) ) {
|
|
|
|
|
if ( !isset( $this->configByChannel[$channelKey] ) ) {
|
|
|
|
|
throw new UnexpectedValueException( "No config for '$channelKey'" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$config = $this->configByChannel[$channelKey];
|
|
|
|
|
$class = $config['class'];
|
|
|
|
|
|
|
|
|
|
$this->relayers[$channelKey] = new $class( $config );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->relayers[$channelKey];
|
|
|
|
|
}
|
|
|
|
|
}
|