Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JHttpTransportCurl
+ Graphe d'héritage de JHttpTransportCurl:
+ Graphe de collaboration de JHttpTransportCurl:

Liste de tous les membres

Fonctions membres publiques

 __construct (JRegistry $options)
 request ($method, JUri $uri, $data=null, array $headers=null, $timeout=null, $userAgent=null)

Fonctions membres publiques statiques

static isSupported ()

Fonctions membres protégées

 getResponse ($content, $info)

Attributs protégés

 $options

Description détaillée

Définition à la ligne 19 du fichier curl.php.


Documentation des constructeurs et destructeur

JHttpTransportCurl::__construct ( JRegistry  $options)

Constructor. CURLOPT_FOLLOWLOCATION must be disabled when open_basedir or safe_mode are enabled.

Paramètres:
JRegistry$optionsClient options object.
Voir également:
http://www.php.net/manual/en/function.curl-setopt.php
Depuis:
11.3
Exceptions:
RuntimeException

Implémente JHttpTransport.

Définition à la ligne 36 du fichier curl.php.

{
if (!function_exists('curl_init') || !is_callable('curl_init'))
{
throw new RuntimeException('Cannot use a cURL transport when curl_init() is not available.');
}
$this->options = $options;
}

Documentation des fonctions membres

JHttpTransportCurl::getResponse (   $content,
  $info 
)
protected

Method to get a response object from a server response.

Paramètres:
string$contentThe complete server response, including headers as a string if the response has no errors.
array$infoThe cURL request information.
Renvoie:
JHttpResponse
Depuis:
11.3
Exceptions:
UnexpectedValueException

Définition à la ligne 186 du fichier curl.php.

{
// Create the response object.
$return = new JHttpResponse;
// Get the number of redirects that occurred.
$redirects = isset($info['redirect_count']) ? $info['redirect_count'] : 0;
/*
* Split the response into headers and body. If cURL encountered redirects, the headers for the redirected requests will
* also be included. So we split the response into header + body + the number of redirects and only use the last two
* sections which should be the last set of headers and the actual body.
*/
$response = explode("\r\n\r\n", $content, 2 + $redirects);
// Set the body for the response.
$return->body = array_pop($response);
// Get the last set of response headers as an array.
$headers = explode("\r\n", array_pop($response));
// Get the response code from the first offset of the response headers.
preg_match('/[0-9]{3}/', array_shift($headers), $matches);
$code = count($matches) ? $matches[0] : null;
if (is_numeric($code))
{
$return->code = (int) $code;
}
// No valid response code was detected.
else
{
throw new UnexpectedValueException('No HTTP response code found.');
}
// Add the response headers to the response object.
foreach ($headers as $header)
{
$pos = strpos($header, ':');
$return->headers[trim(substr($header, 0, $pos))] = trim(substr($header, ($pos + 1)));
}
return $return;
}
static JHttpTransportCurl::isSupported ( )
static

Method to check if HTTP transport cURL is available for use

Renvoie:
boolean true if available, else false
Depuis:
12.1

Implémente JHttpTransport.

Définition à la ligne 240 du fichier curl.php.

{
return function_exists('curl_version') && curl_version();
}
JHttpTransportCurl::request (   $method,
JUri  $uri,
  $data = null,
array  $headers = null,
  $timeout = null,
  $userAgent = null 
)

Send a request to the server and return a JHttpResponse object with the response.

Paramètres:
string$methodThe HTTP method for sending the request.
JUri$uriThe URI to the resource to request.
mixed$dataEither an associative array or a string to be sent with the request.
array$headersAn array of request headers to send with the request.
integer$timeoutRead timeout in seconds.
string$userAgentThe optional user agent string to send with the request.
Renvoie:
JHttpResponse
Depuis:
11.3
Exceptions:
RuntimeException

Implémente JHttpTransport.

Définition à la ligne 61 du fichier curl.php.

{
// Setup the cURL handle.
$ch = curl_init();
// Set the request method.
$options[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
// Don't wait for body when $method is HEAD
$options[CURLOPT_NOBODY] = ($method === 'HEAD');
// Initialize the certificate store
$options[CURLOPT_CAINFO] = $this->options->get('curl.certpath', __DIR__ . '/cacert.pem');
// If data exists let's encode it and make sure our Content-type header is set.
if (isset($data))
{
// If the data is a scalar value simply add it to the cURL post fields.
if (is_scalar($data) || (isset($headers['Content-Type']) && strpos($headers['Content-Type'], 'multipart/form-data') === 0))
{
$options[CURLOPT_POSTFIELDS] = $data;
}
// Otherwise we need to encode the value first.
else
{
$options[CURLOPT_POSTFIELDS] = http_build_query($data);
}
if (!isset($headers['Content-Type']))
{
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
}
// Add the relevant headers.
if (is_scalar($options[CURLOPT_POSTFIELDS]))
{
$headers['Content-Length'] = strlen($options[CURLOPT_POSTFIELDS]);
}
}
// Build the headers string for the request.
$headerArray = array();
if (isset($headers))
{
foreach ($headers as $key => $value)
{
$headerArray[] = $key . ': ' . $value;
}
// Add the headers string into the stream context options array.
$options[CURLOPT_HTTPHEADER] = $headerArray;
}
// If an explicit timeout is given user it.
if (isset($timeout))
{
$options[CURLOPT_TIMEOUT] = (int) $timeout;
$options[CURLOPT_CONNECTTIMEOUT] = (int) $timeout;
}
// If an explicit user agent is given use it.
if (isset($userAgent))
{
$options[CURLOPT_USERAGENT] = $userAgent;
}
// Set the request URL.
$options[CURLOPT_URL] = (string) $uri;
// We want our headers. :-)
$options[CURLOPT_HEADER] = true;
// Return it... echoing it would be tacky.
$options[CURLOPT_RETURNTRANSFER] = true;
// Override the Expect header to prevent cURL from confusing itself in its own stupidity.
// Link: http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/
$options[CURLOPT_HTTPHEADER][] = 'Expect:';
// Follow redirects.
$options[CURLOPT_FOLLOWLOCATION] = (bool) $this->options->get('follow_location', true);
// Set the cURL options.
curl_setopt_array($ch, $options);
// Execute the request and close the connection.
$content = curl_exec($ch);
// Check if the content is a string. If it is not, it must be an error.
if (!is_string($content))
{
$message = curl_error($ch);
if (empty($message))
{
// Error but nothing from cURL? Create our own
$message = 'No HTTP response received';
}
throw new RuntimeException($message);
}
// Get the request information.
$info = curl_getinfo($ch);
// Close the connection.
curl_close($ch);
return $this->getResponse($content, $info);
}

Documentation des données membres

JHttpTransportCurl::$options
protected

Définition à la ligne 25 du fichier curl.php.


La documentation de cette classe a été générée à partir du fichier suivant :