Merge "Don't check namespace in SpecialWantedtemplates"
[lhc/web/wiklou.git] / includes / libs / eventrelayer / EventRelayerMCRD.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 * @author Aaron Schulz
20 */
21
22 /**
23 * Relayed that uses the mcrelaypushd server
24 */
25 class EventRelayerMCRD extends EventRelayer {
26 /** @var MultiHttpClient */
27 protected $http;
28 /** @var string */
29 protected $baseUrl;
30
31 /**
32 * Additional params include 'mcrdConfig', which is a map of:
33 * - url : The base URL of the service (without paths)
34 * @param array $params
35 */
36 public function __construct( array $params ) {
37 parent::__construct( $params );
38
39 $this->baseUrl = $params['mcrdConfig']['url'];
40
41 $httpConfig = isset( $params['httpConfig'] ) ? $params['httpConfig'] : array();
42 if ( !isset( $httpConfig['connTimeout'] ) ) {
43 $httpConfig['connTimeout'] = 1;
44 }
45 if ( !isset( $httpConfig['reqTimeout'] ) ) {
46 $httpConfig['reqTimeout'] = .25;
47 }
48
49 $this->http = new MultiHttpClient( $httpConfig );
50 }
51
52 protected function doNotify( $channel, array $events ) {
53 if ( !count( $events ) ) {
54 return true;
55 }
56
57 $response = $this->http->run( array(
58 'url' => "{$this->baseUrl}/relayer/api/v1.0/" . rawurlencode( $channel ),
59 'method' => 'POST',
60 'body' => json_encode( array( 'events' => $events ) ),
61 'headers' => array( 'content-type' => 'application/json' )
62 ) );
63
64 return $response['code'] == 201;
65 }
66 }