summaryrefslogtreecommitdiffstats
path: root/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php')
-rw-r--r--vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php136
1 files changed, 60 insertions, 76 deletions
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php
index 3e408b6d8..b07685fcb 100644
--- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php
+++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Curl.php
@@ -5,54 +5,49 @@ namespace PicoFeed\Client;
use PicoFeed\Logging\Logger;
/**
- * cURL HTTP client
+ * cURL HTTP client.
*
* @author Frederic Guillot
- * @package Client
*/
class Curl extends Client
{
/**
- * HTTP response body
+ * HTTP response body.
*
- * @access private
* @var string
*/
private $body = '';
/**
- * Body size
+ * Body size.
*
- * @access private
- * @var integer
+ * @var int
*/
private $body_length = 0;
/**
- * HTTP response headers
+ * HTTP response headers.
*
- * @access private
* @var array
*/
private $response_headers = array();
/**
- * Counter on the number of header received
+ * Counter on the number of header received.
*
- * @access private
- * @var integer
+ * @var int
*/
private $response_headers_count = 0;
/**
- * cURL callback to read the HTTP body
+ * cURL callback to read the HTTP body.
*
* If the function return -1, curl stop to read the HTTP response
*
- * @access public
- * @param resource $ch cURL handler
- * @param string $buffer Chunk of data
- * @return integer Length of the buffer
+ * @param resource $ch cURL handler
+ * @param string $buffer Chunk of data
+ *
+ * @return int Length of the buffer
*/
public function readBody($ch, $buffer)
{
@@ -69,23 +64,21 @@ class Curl extends Client
}
/**
- * cURL callback to read HTTP headers
+ * cURL callback to read HTTP headers.
+ *
+ * @param resource $ch cURL handler
+ * @param string $buffer Header line
*
- * @access public
- * @param resource $ch cURL handler
- * @param string $buffer Header line
- * @return integer Length of the buffer
+ * @return int Length of the buffer
*/
public function readHeaders($ch, $buffer)
{
$length = strlen($buffer);
if ($buffer === "\r\n" || $buffer === "\n") {
- $this->response_headers_count++;
- }
- else {
-
- if (! isset($this->response_headers[$this->response_headers_count])) {
+ ++$this->response_headers_count;
+ } else {
+ if (!isset($this->response_headers[$this->response_headers_count])) {
$this->response_headers[$this->response_headers_count] = '';
}
@@ -96,12 +89,12 @@ class Curl extends Client
}
/**
- * cURL callback to passthrough the HTTP status header to the client
+ * cURL callback to passthrough the HTTP status header to the client.
+ *
+ * @param resource $ch cURL handler
+ * @param string $buffer Header line
*
- * @access public
- * @param resource $ch cURL handler
- * @param string $buffer Header line
- * @return integer Length of the buffer
+ * @return int Length of the buffer
*/
public function passthroughHeaders($ch, $buffer)
{
@@ -109,8 +102,7 @@ class Curl extends Client
if ($status !== 0) {
header(':', true, $status);
- }
- elseif (isset($headers['Content-Type'])) {
+ } elseif (isset($headers['Content-Type'])) {
header($buffer);
}
@@ -118,25 +110,25 @@ class Curl extends Client
}
/**
- * cURL callback to passthrough the HTTP body to the client
+ * cURL callback to passthrough the HTTP body to the client.
*
* If the function return -1, curl stop to read the HTTP response
*
- * @access public
- * @param resource $ch cURL handler
- * @param string $buffer Chunk of data
- * @return integer Length of the buffer
+ * @param resource $ch cURL handler
+ * @param string $buffer Chunk of data
+ *
+ * @return int Length of the buffer
*/
public function passthroughBody($ch, $buffer)
{
echo $buffer;
+
return strlen($buffer);
}
/**
- * Prepare HTTP headers
+ * Prepare HTTP headers.
*
- * @access private
* @return string[]
*/
private function prepareHeaders()
@@ -159,16 +151,15 @@ class Curl extends Client
}
/**
- * Prepare curl proxy context
+ * Prepare curl proxy context.
+ *
+ * @param resource $ch
*
- * @access private
- * @param resource $ch
* @return resource $ch
*/
private function prepareProxyContext($ch)
{
if ($this->proxy_hostname) {
-
Logger::setMessage(get_called_class().' Proxy: '.$this->proxy_hostname.':'.$this->proxy_port);
curl_setopt($ch, CURLOPT_PROXYPORT, $this->proxy_port);
@@ -178,8 +169,7 @@ class Curl extends Client
if ($this->proxy_username) {
Logger::setMessage(get_called_class().' Proxy credentials: Yes');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxy_username.':'.$this->proxy_password);
- }
- else {
+ } else {
Logger::setMessage(get_called_class().' Proxy credentials: No');
}
}
@@ -188,10 +178,10 @@ class Curl extends Client
}
/**
- * Prepare curl auth context
+ * Prepare curl auth context.
+ *
+ * @param resource $ch
*
- * @access private
- * @param resource $ch
* @return resource $ch
*/
private function prepareAuthContext($ch)
@@ -204,10 +194,10 @@ class Curl extends Client
}
/**
- * Set write/header functions
+ * Set write/header functions.
+ *
+ * @param resource $ch
*
- * @access private
- * @param resource $ch
* @return resource $ch
*/
private function prepareDownloadMode($ch)
@@ -218,7 +208,6 @@ class Curl extends Client
if ($this->isPassthroughEnabled()) {
$write_function = 'passthroughBody';
$header_function = 'passthroughHeaders';
-
}
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, $write_function));
@@ -228,9 +217,8 @@ class Curl extends Client
}
/**
- * Prepare curl context
+ * Prepare curl context.
*
- * @access private
* @return resource
*/
private function prepareContext()
@@ -266,9 +254,7 @@ class Curl extends Client
}
/**
- * Execute curl context
- *
- * @access private
+ * Execute curl context.
*/
private function executeContext()
{
@@ -297,11 +283,11 @@ class Curl extends Client
}
/**
- * Do the HTTP request
+ * Do the HTTP request.
*
- * @access public
- * @param bool $follow_location Flag used when there is an open_basedir restriction
- * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...]
+ * @param bool $follow_location Flag used when there is an open_basedir restriction
+ *
+ * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...]
*/
public function doRequest($follow_location = true)
{
@@ -309,22 +295,22 @@ class Curl extends Client
list($status, $headers) = HttpHeaders::parse(explode("\n", $this->response_headers[$this->response_headers_count - 1]));
- if ($follow_location && ($status == 301 || $status == 302)) {
+ if ($follow_location && $this->isRedirection($status)) {
return $this->handleRedirection($headers['Location']);
}
return array(
'status' => $status,
'body' => $this->body,
- 'headers' => $headers
+ 'headers' => $headers,
);
}
/**
- * Handle manually redirections when there is an open base dir restriction
+ * Handle manually redirections when there is an open base dir restriction.
+ *
+ * @param string $location Redirected URL
*
- * @access private
- * @param string $location Redirected URL
* @return array
*/
private function handleRedirection($location)
@@ -338,8 +324,7 @@ class Curl extends Client
$this->response_headers_count = 0;
while (true) {
-
- $nb_redirects++;
+ ++$nb_redirects;
if ($nb_redirects >= $this->max_redirects) {
throw new MaxRedirectException('Maximum number of redirections reached');
@@ -347,14 +332,13 @@ class Curl extends Client
$result = $this->doRequest(false);
- if ($result['status'] == 301 || $result['status'] == 302) {
+ if ($this->isRedirection($result['status'])) {
$this->url = Url::resolve($result['headers']['Location'], $this->url);
$this->body = '';
$this->body_length = 0;
$this->response_headers = array();
$this->response_headers_count = 0;
- }
- else {
+ } else {
break;
}
}
@@ -363,14 +347,14 @@ class Curl extends Client
}
/**
- * Handle cURL errors (throw individual exceptions)
+ * Handle cURL errors (throw individual exceptions).
*
* We don't use constants because they are not necessary always available
* (depends of the version of libcurl linked to php)
*
* @see http://curl.haxx.se/libcurl/c/libcurl-errors.html
- * @access private
- * @param integer $errno cURL error code
+ *
+ * @param int $errno cURL error code
*/
private function handleError($errno)
{