X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2FCurlResult.php;h=9f52edfad698137ae06936b80f0e7f7354af2ddd;hb=122ad0af14f046c2462a03fe33967dc41abfc8b5;hp=ca1ead91d15305798b3d06c2b8799bdb47526164;hpb=02bc99f67ba416455201ee6c249669fcbcca4e17;p=friendica.git diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index ca1ead91d1..9f52edfad6 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -29,7 +29,7 @@ use Friendica\Util\Network; /** * A content class for Curl call results */ -class CurlResult implements IHTTPResult +class CurlResult { /** * @var int HTTP return code or 0 if timeout or failure @@ -37,7 +37,7 @@ class CurlResult implements IHTTPResult private $returnCode; /** - * @var string[] the content type of the Curl call + * @var string the content type of the Curl call */ private $contentType; @@ -101,7 +101,7 @@ class CurlResult implements IHTTPResult * * @param string $url optional URL * - * @return IHTTPResult a CURL with error response + * @return CurlResult a CURL with error response * @throws InternalServerErrorException */ public static function createErrorCurl($url = '') @@ -223,49 +223,63 @@ class CurlResult implements IHTTPResult private function checkInfo() { if (isset($this->info['content_type'])) { - $this->contentType = [$this->info['content_type']]; + $this->contentType = $this->info['content_type']; } else { - $this->contentType = []; + $this->contentType = ''; } } - /** {@inheritDoc} */ + /** + * Gets the Curl Code + * + * @return string The Curl Code + */ public function getReturnCode() { return $this->returnCode; } - /** {@inheritDoc} */ + /** + * Returns the Curl Content Type + * + * @return string the Curl Content Type + */ public function getContentType() { return $this->contentType; } - /** {@inheritDoc} */ - public function getHeader($header) + /** + * Returns the Curl headers + * + * @param string $field optional header field. Return all fields if empty + * + * @return string the Curl headers or the specified content of the header variable + */ + public function getHeader(string $field = '') { - if (empty($header)) { - return []; + if (empty($field)) { + return $this->header; } - $header = strtolower(trim($header)); + $field = strtolower(trim($field)); $headers = $this->getHeaderArray(); - if (isset($headers[$header])) { - return $headers[$header]; + if (isset($headers[$field])) { + return $headers[$field]; } - return []; + return ''; } - /** {@inheritDoc} */ - public function getHeaders() - { - return $this->getHeaderArray(); - } - - /** {@inheritDoc} */ + /** + * Check if a specified header exists + * + * @param string $field header field + * + * @return boolean "true" if header exists + */ public function inHeader(string $field) { $field = strtolower(trim($field)); @@ -275,7 +289,11 @@ class CurlResult implements IHTTPResult return array_key_exists($field, $headers); } - /** {@inheritDoc} */ + /** + * Returns the Curl headers as an associated array + * + * @return array associated header array + */ public function getHeaderArray() { if (!empty($this->header_fields)) { @@ -289,59 +307,79 @@ class CurlResult implements IHTTPResult $parts = explode(':', $line); $headerfield = strtolower(trim(array_shift($parts))); $headerdata = trim(implode(':', $parts)); - if (empty($this->header_fields[$headerfield])) { - $this->header_fields[$headerfield] = [$headerdata]; - } elseif (!in_array($headerdata, $this->header_fields[$headerfield])) { - $this->header_fields[$headerfield][] = $headerdata; - } + $this->header_fields[$headerfield] = $headerdata; } return $this->header_fields; } - /** {@inheritDoc} */ + /** + * @return bool + */ public function isSuccess() { return $this->isSuccess; } - /** {@inheritDoc} */ + /** + * @return string + */ public function getUrl() { return $this->url; } - /** {@inheritDoc} */ + /** + * @return string + */ public function getRedirectUrl() { return $this->redirectUrl; } - /** {@inheritDoc} */ + /** + * @return string + */ public function getBody() { return $this->body; } - /** {@inheritDoc} */ + /** + * @return array + */ + public function getInfo() + { + return $this->info; + } + + /** + * @return bool + */ public function isRedirectUrl() { return $this->isRedirectUrl; } - /** {@inheritDoc} */ + /** + * @return int + */ public function getErrorNumber() { return $this->errorNumber; } - /** {@inheritDoc} */ + /** + * @return string + */ public function getError() { return $this->error; } - /** {@inheritDoc} */ + /** + * @return bool + */ public function isTimeout() { return $this->isTimeout;