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 JHttpTransportStream
+ Graphe d'héritage de JHttpTransportStream:
+ Graphe de collaboration de JHttpTransportStream:

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 (array $headers, $body)

Attributs protégés

 $options

Description détaillée

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


Documentation des constructeurs et destructeur

JHttpTransportStream::__construct ( JRegistry  $options)

Constructor.

Paramètres:
JRegistry$optionsClient options object.
Depuis:
11.3
Exceptions:
RuntimeException

Implémente JHttpTransport.

Définition à la ligne 35 du fichier stream.php.

{
// Verify that fopen() is available.
if (!self::isSupported())
{
throw new RuntimeException('Cannot use a stream transport when fopen() is not available.');
}
// Verify that URLs can be used with fopen();
if (!ini_get('allow_url_fopen'))
{
throw new RuntimeException('Cannot use a stream transport when "allow_url_fopen" is disabled.');
}
$this->options = $options;
}

Documentation des fonctions membres

JHttpTransportStream::getResponse ( array  $headers,
  $body 
)
protected

Method to get a response object from a server response.

Paramètres:
array$headersThe response headers as an array.
string$bodyThe response body as a string.
Renvoie:
JHttpResponse
Depuis:
11.3
Exceptions:
UnexpectedValueException

Définition à la ligne 192 du fichier stream.php.

{
// Create the response object.
$return = new JHttpResponse;
// Set the body for the response.
$return->body = $body;
// Get the response code from the first offset of the response headers.
preg_match('/[0-9]{3}/', array_shift($headers), $matches);
$code = $matches[0];
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 JHttpTransportStream::isSupported ( )
static

Method to check if http transport stream available for use

Renvoie:
bool true if available else false
Depuis:
12.1

Implémente JHttpTransport.

Définition à la ligne 232 du fichier stream.php.

{
return function_exists('fopen') && is_callable('fopen');
}
JHttpTransportStream::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 67 du fichier stream.php.

{
// Create the stream context options array with the required method offset.
$options = array('method' => strtoupper($method));
// 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 stream context options.
if (is_scalar($data))
{
$options['content'] = $data;
}
// Otherwise we need to encode the value first.
else
{
$options['content'] = http_build_query($data);
}
if (!isset($headers['Content-Type']))
{
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8';
}
// Add the relevant headers.
$headers['Content-Length'] = strlen($options['content']);
}
// Build the headers string for the request.
$headerString = null;
if (isset($headers))
{
foreach ($headers as $key => $value)
{
$headerString .= $key . ': ' . $value . "\r\n";
}
// Add the headers string into the stream context options array.
$options['header'] = trim($headerString, "\r\n");
}
// If an explicit timeout is given user it.
if (isset($timeout))
{
$options['timeout'] = (int) $timeout;
}
// If an explicit user agent is given use it.
if (isset($userAgent))
{
$options['user_agent'] = $userAgent;
}
// Ignore HTTP errors so that we can capture them.
$options['ignore_errors'] = 1;
// Follow redirects.
$options['follow_location'] = (int) $this->options->get('follow_location', 1);
// Create the stream context for the request.
$context = stream_context_create(array('http' => $options));
// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
// Open the stream for reading.
$stream = @fopen((string) $uri, 'r', false, $context);
if (!$stream)
{
if (!$php_errormsg)
{
// Error but nothing from php? Create our own
$php_errormsg = sprintf('Could not connect to resource: %s', $uri, $err, $errno);
}
// Restore error tracking to give control to the exception handler
ini_set('track_errors', $track_errors);
throw new RuntimeException($php_errormsg);
}
// Restore error tracking to what it was before.
ini_set('track_errors', $track_errors);
// Get the metadata for the stream, including response headers.
$metadata = stream_get_meta_data($stream);
// Get the contents from the stream.
$content = stream_get_contents($stream);
// Close the stream.
fclose($stream);
if (isset($metadata['wrapper_data']['headers']))
{
$headers = $metadata['wrapper_data']['headers'];
}
elseif (isset($metadata['wrapper_data']))
{
$headers = $metadata['wrapper_data'];
}
else
{
$headers = array();
}
return $this->getResponse($headers, $content);
}

Documentation des données membres

JHttpTransportStream::$options
protected

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


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