3 * Factory class for spawning EventRelayer objects using configuration
8 class EventRelayerGroup
{
10 protected $configByChannel = [];
12 /** @var EventRelayer[] */
13 protected $relayers = [];
15 /** @var EventRelayerGroup */
16 protected static $instance = null;
19 * @param Config $config
21 protected function __construct( Config
$config ) {
22 $this->configByChannel
= $config->get( 'EventRelayerConfig' );
26 * @return EventRelayerGroup
28 public static function singleton() {
29 if ( !self
::$instance ) {
30 self
::$instance = new self( RequestContext
::getMain()->getConfig() );
33 return self
::$instance;
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] )
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];