1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20use Psr\Log\LoggerAwareInterface;
21use Psr\Log\LoggerInterface;
22use Psr\Log\NullLogger;
23
24/**
25 * Base class for reliable event relays
26 *
27 * @stable to extend
28 */
29abstract class EventRelayer implements LoggerAwareInterface {
30	/** @var LoggerInterface */
31	protected $logger;
32
33	/**
34	 * @stable to call
35	 *
36	 * @param array $params
37	 */
38	public function __construct( array $params ) {
39		$this->logger = new NullLogger();
40	}
41
42	/**
43	 * @param string $channel
44	 * @param array $event Event data map
45	 * @return bool Success
46	 */
47	final public function notify( $channel, $event ) {
48		return $this->doNotify( $channel, [ $event ] );
49	}
50
51	/**
52	 * @param string $channel
53	 * @param array $events List of event data maps
54	 * @return bool Success
55	 */
56	final public function notifyMulti( $channel, $events ) {
57		return $this->doNotify( $channel, $events );
58	}
59
60	public function setLogger( LoggerInterface $logger ) {
61		$this->logger = $logger;
62	}
63
64	/**
65	 * @param string $channel
66	 * @param array $events List of event data maps
67	 * @return bool Success
68	 */
69	abstract protected function doNotify( $channel, array $events );
70}
71