Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
object.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage MediaWiki
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * MediaWiki API object class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage MediaWiki
17  * @since 12.3
18  */
19 abstract class JMediawikiObject
20 {
21 
22  /**
23  * @var JRegistry Options for the MediaWiki object.
24  * @since 12.3
25  */
26  protected $options;
27 
28  /**
29  * @var JMediawikiHttp The HTTP client object to use in sending HTTP requests.
30  * @since 12.3
31  */
32  protected $client;
33 
34  /**
35  * Constructor.
36  *
37  * @param JRegistry $options Mediawiki options object.
38  * @param JMediawikiHttp $client The HTTP client object.
39  *
40  * @since 12.3
41  */
42  public function __construct(JRegistry $options = null, JMediawikiHttp $client = null)
43  {
44  $this->options = isset($options) ? $options : new JRegistry;
45  $this->client = isset($client) ? $client : new JMediawikiHttp($this->options);
46  }
47 
48  /**
49  * Method to build and return a full request URL for the request.
50  *
51  * @param string $path URL to inflect
52  *
53  * @return string The request URL.
54  *
55  * @since 12.3
56  */
57  protected function fetchUrl($path)
58  {
59  // Append the path with output format
60  $path .= '&format=xml';
61 
62  $uri = new JUri($this->options->get('api.url') . '/api.php' . $path);
63 
64  if ($this->options->get('api.username', false))
65  {
66  $uri->setUser($this->options->get('api.username'));
67  }
68 
69  if ($this->options->get('api.password', false))
70  {
71  $uri->setPass($this->options->get('api.password'));
72  }
73 
74  return (string) $uri;
75  }
76 
77  /**
78  * Method to build request parameters from a string array.
79  *
80  * @param array $params string array that contains the parameters
81  *
82  * @return string request parameter
83  *
84  * @since 12.3
85  */
86  public function buildParameter(array $params)
87  {
88  $path = '';
89 
90  foreach ($params as $param)
91  {
92  $path .= $param;
93 
94  if (next($params) == true)
95  {
96  $path .= '|';
97  }
98  }
99 
100  return $path;
101  }
102 
103  /**
104  * Method to validate response for errors
105  *
106  * @param JHttpresponse $response reponse from the mediawiki server
107  *
108  * @return Object
109  *
110  * @since 12.3
111  */
112  public function validateResponse($response)
113  {
114  $xml = simplexml_load_string($response->body);
115 
116  if (isset($xml->warnings))
117  {
118  throw new DomainException($xml->warnings->info);
119  }
120 
121  if (isset($xml->error))
122  {
123  throw new DomainException($xml->error['info']);
124  }
125 
126  return $xml;
127  }
128 
129 }