Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
http.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  * HTTP client class for connecting to a MediaWiki instance.
14  *
15  * @package Joomla.Platform
16  * @subpackage MediaWiki
17  * @since 12.3
18  */
19 class JMediawikiHttp extends JHttp
20 {
21  /**
22  * Constructor.
23  *
24  * @param JRegistry $options Client options object.
25  * @param JHttpTransport $transport The HTTP transport object.
26  *
27  * @since 12.3
28  */
29  public function __construct(JRegistry $options = null, JHttpTransport $transport = null)
30  {
31  // Override the JHttp contructor to use JHttpTransportStream.
32  $this->options = isset($options) ? $options : new JRegistry;
33  $this->transport = isset($transport) ? $transport : new JHttpTransportStream($this->options);
34 
35  // Make sure the user agent string is defined.
36  $this->options->def('api.useragent', 'JMediawiki/1.0');
37 
38  // Set the default timeout to 120 seconds.
39  $this->options->def('api.timeout', 120);
40  }
41 
42  /**
43  * Method to send the GET command to the server.
44  *
45  * @param string $url Path to the resource.
46  * @param array $headers An array of name-value pairs to include in the header of the request.
47  *
48  * @return JHttpResponse
49  *
50  * @since 12.3
51  */
52  public function get($url, array $headers = null)
53  {
54  // Look for headers set in the options.
55  $temp = (array) $this->options->get('headers');
56 
57  foreach ($temp as $key => $val)
58  {
59  if (!isset($headers[$key]))
60  {
61  $headers[$key] = $val;
62  }
63  }
64 
65  return $this->transport->request('GET', new JUri($url), null, $headers, $this->options->get('api.timeout'), $this->options->get('api.useragent'));
66  }
67 
68  /**
69  * Method to send the POST command to the server.
70  *
71  * @param string $url Path to the resource.
72  * @param mixed $data Either an associative array or a string to be sent with the request.
73  * @param array $headers An array of name-value pairs to include in the header of the request.
74  *
75  * @return JHttpResponse
76  *
77  * @since 12.3
78  */
79  public function post($url, $data, array $headers = null)
80  {
81  // Look for headers set in the options.
82  $temp = (array) $this->options->get('headers');
83 
84  foreach ($temp as $key => $val)
85  {
86  if (!isset($headers[$key]))
87  {
88  $headers[$key] = $val;
89  }
90  }
91 
92  return $this->transport->request('POST', new JUri($url), $data, $headers, $this->options->get('api.timeout'), $this->options->get('api.useragent'));
93  }
94 }