Debian Codegraph @

includes/recentchanges/RCFeed/RCFeed.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 InvalidArgumentException;
24 use RecentChange;
25
26 /**
27 * @see $wgRCFeeds
28 * @since 1.29
29 * @ingroup RecentChanges
30 */
31 abstract class RCFeed {
32 /**
33 * @param array $params
34 */
35 public function __construct( array $params = [] ) {
36 }
37
38 /**
39 * Dispatch the recent changes notification.
40 *
41 * @param RecentChange $rc
42 * @param string|null $actionComment
43 * @return bool Success
44 */
45 abstract public function notify( RecentChange $rc, $actionComment = null );
46
47 /**
48 * @param array $params
49 * @return RCFeed
50 */
51 final public static function factory( array $params ): RCFeed {
52 if ( !isset( $params['class'] ) ) {
53 if ( !isset( $params['uri'] ) ) {
54 throw new InvalidArgumentException( 'RCFeeds must have a class set' );
55 }
56 if ( strpos( $params['uri'], 'udp:' ) === 0 ) {
57 $params['class'] = UDPRCFeedEngine::class;
58 } elseif ( strpos( $params['uri'], 'redis:' ) === 0 ) {
59 $params['class'] = RedisPubSubFeedEngine::class;
60 } else {
61 global $wgRCEngines;
62 wfDeprecated( '$wgRCFeeds without class', '1.38' );
63 $scheme = parse_url( $params['uri'], PHP_URL_SCHEME );
64 if ( !$scheme ) {
65 throw new InvalidArgumentException( "Invalid RCFeed uri: {$params['uri']}" );
66 }
67 if ( !isset( $wgRCEngines[$scheme] ) ) {
68 throw new InvalidArgumentException( "Unknown RCFeed engine: $scheme" );
69 }
70 $params['class'] = $wgRCEngines[$scheme];
71 }
72 }
73
74 $class = $params['class'];
75 if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $class ) ) {
76 return $class;
77 }
78 if ( !class_exists( $class ) ) {
79 throw new InvalidArgumentException( "Unknown class '$class'." );
80 }
81 return new $class( $params );
82 }
83 }
84 /** @deprecated class alias since 1.43 */
85 class_alias( RCFeed::class, 'RCFeed' );