*/ private $channels = array(); /** * Adds a channel. A second channel with the same ID replaces the first. * * @param ChannelInterface $channel Channel. */ public function register( ChannelInterface $channel ): void { $this->channels[ $channel->id() ] = $channel; } /** * Whether a channel exists. * * @param string $id Channel ID. */ public function has( string $id ): bool { return isset( $this->channels[ $id ] ); } /** * One channel. * * @param string $id Channel ID. * @throws InvalidArgumentException When there is no such channel. */ public function get( string $id ): ChannelInterface { if ( ! isset( $this->channels[ $id ] ) ) { throw new InvalidArgumentException( 'Unknown channel "' . $id . '".' ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Plain-text message, escaped wherever it is shown. } return $this->channels[ $id ]; } /** * All channels. * * @return array */ public function all(): array { return $this->channels; } }