Merge "registration: Only allow one extension to set a specific config setting"
[lhc/web/wiklou.git] / includes / rcfeed / FormattedRCFeed.php
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 */
20
21 /**
22 * Base class for RC feed engines that send messages in a freely configurable
23 * format to a uri-addressed engine set in $wgRCEngines.
24 * @since 1.29
25 */
26 abstract class FormattedRCFeed extends RCFeed {
27 private $params;
28
29 /**
30 * @param array $params
31 * - 'uri'
32 * - 'formatter'
33 * @see $wgRCFeeds
34 */
35 public function __construct( array $params = [] ) {
36 $this->params = $params;
37 }
38
39 /**
40 * Send some text to the specified feed.
41 *
42 * @param array $feed The feed, as configured in an associative array
43 * @param string $line The text to send
44 * @return bool Success
45 */
46 abstract public function send( array $feed, $line );
47
48 /**
49 * @param RecentChange $rc
50 * @param string|null $actionComment
51 * @return bool Success
52 */
53 public function notify( RecentChange $rc, $actionComment = null ) {
54 $params = $this->params;
55 /** @var RCFeedFormatter $formatter */
56 $formatter = is_object( $params['formatter'] ) ? $params['formatter'] : new $params['formatter'];
57
58 $line = $formatter->getLine( $params, $rc, $actionComment );
59 if ( !$line ) {
60 // @codeCoverageIgnoreStart
61 // T109544 - If a feed formatter returns null, this will otherwise cause an
62 // error in at least RedisPubSubFeedEngine. Not sure best to handle this.
63 return;
64 // @codeCoverageIgnoreEnd
65 }
66 return $this->send( $params, $line );
67 }
68 }