Debian Codegraph @

includes/recentchanges/RCFeed/FormattedRCFeed.php

raw symbols SCIP
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 namespace MediaWiki\RCFeed;
22
23 use RecentChange;
24
25 /**
26 * Base class for RCFeed implementations that use RCFeedFormatter.
27 *
28 * Parameters:
29 * - formatter: [required] Which RCFeedFormatter class to use.
30 *
31 * @see $wgRCFeeds
32 * @since 1.29
33 * @ingroup RecentChanges
34 */
35 abstract class FormattedRCFeed extends RCFeed {
36 private array $params;
37
38 /**
39 * @param array $params
40 */
41 public function __construct( array $params ) {
42 $this->params = $params;
43 }
44
45 /**
46 * Send some text to the specified feed.
47 *
48 * @param array $feed The feed, as configured in an associative array
49 * @param string $line The text to send
50 * @return bool Success
51 */
52 abstract public function send( array $feed, $line );
53
54 /**
55 * @param RecentChange $rc
56 * @param string|null $actionComment
57 * @return bool Success
58 */
59 public function notify( RecentChange $rc, $actionComment = null ) {
60 $params = $this->params;
61 /** @var RCFeedFormatter $formatter */
62 $formatter = is_object( $params['formatter'] ) ? $params['formatter'] : new $params['formatter'];
63
64 $line = $formatter->getLine( $params, $rc, $actionComment );
65 if ( !$line ) {
66 // @codeCoverageIgnoreStart
67 // T109544 - If a feed formatter returns null, this will otherwise cause an
68 // error in at least RedisPubSubFeedEngine. Not sure best to handle this.
69 // @phan-suppress-next-line PhanTypeMismatchReturnProbablyReal
70 return;
71 // @codeCoverageIgnoreEnd
72 }
73 return $this->send( $params, $line );
74 }
75 }
76 /** @deprecated class alias since 1.43 */
77 class_alias( FormattedRCFeed::class, 'FormattedRCFeed' );