1
0
Fork 0

Introduce IHTTPResult Interface as abstraction for CurlResult

This commit is contained in:
Philipp Holzer 2021-08-20 19:48:13 +02:00
parent 3e5ac1ad5d
commit 7009d90add
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
2 changed files with 108 additions and 57 deletions

View file

@ -29,7 +29,7 @@ use Friendica\Util\Network;
/** /**
* A content class for Curl call results * A content class for Curl call results
*/ */
class CurlResult class CurlResult implements IHTTPResult
{ {
/** /**
* @var int HTTP return code or 0 if timeout or failure * @var int HTTP return code or 0 if timeout or failure
@ -229,33 +229,19 @@ class CurlResult
} }
} }
/** /** {@inheritDoc} */
* Gets the Curl Code
*
* @return string The Curl Code
*/
public function getReturnCode() public function getReturnCode()
{ {
return $this->returnCode; return $this->returnCode;
} }
/** /** {@inheritDoc} */
* Returns the Curl Content Type
*
* @return string the Curl Content Type
*/
public function getContentType() public function getContentType()
{ {
return $this->contentType; return $this->contentType;
} }
/** /** {@inheritDoc} */
* 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 = '') public function getHeader(string $field = '')
{ {
if (empty($field)) { if (empty($field)) {
@ -273,13 +259,7 @@ class CurlResult
return ''; return '';
} }
/** /** {@inheritDoc} */
* Check if a specified header exists
*
* @param string $field header field
*
* @return boolean "true" if header exists
*/
public function inHeader(string $field) public function inHeader(string $field)
{ {
$field = strtolower(trim($field)); $field = strtolower(trim($field));
@ -289,11 +269,7 @@ class CurlResult
return array_key_exists($field, $headers); return array_key_exists($field, $headers);
} }
/** /** {@inheritDoc} */
* Returns the Curl headers as an associated array
*
* @return array associated header array
*/
public function getHeaderArray() public function getHeaderArray()
{ {
if (!empty($this->header_fields)) { if (!empty($this->header_fields)) {
@ -313,73 +289,55 @@ class CurlResult
return $this->header_fields; return $this->header_fields;
} }
/** /** {@inheritDoc} */
* @return bool
*/
public function isSuccess() public function isSuccess()
{ {
return $this->isSuccess; return $this->isSuccess;
} }
/** /** {@inheritDoc} */
* @return string
*/
public function getUrl() public function getUrl()
{ {
return $this->url; return $this->url;
} }
/** /** {@inheritDoc} */
* @return string
*/
public function getRedirectUrl() public function getRedirectUrl()
{ {
return $this->redirectUrl; return $this->redirectUrl;
} }
/** /** {@inheritDoc} */
* @return string
*/
public function getBody() public function getBody()
{ {
return $this->body; return $this->body;
} }
/** /** {@inheritDoc} */
* @return array
*/
public function getInfo() public function getInfo()
{ {
return $this->info; return $this->info;
} }
/** /** {@inheritDoc} */
* @return bool
*/
public function isRedirectUrl() public function isRedirectUrl()
{ {
return $this->isRedirectUrl; return $this->isRedirectUrl;
} }
/** /** {@inheritDoc} */
* @return int
*/
public function getErrorNumber() public function getErrorNumber()
{ {
return $this->errorNumber; return $this->errorNumber;
} }
/** /** {@inheritDoc} */
* @return string
*/
public function getError() public function getError()
{ {
return $this->error; return $this->error;
} }
/** /** {@inheritDoc} */
* @return bool
*/
public function isTimeout() public function isTimeout()
{ {
return $this->isTimeout; return $this->isTimeout;

View file

@ -0,0 +1,93 @@
<?php
namespace Friendica\Network;
/**
* Temporary class to map Friendica used variables based on PSR-7 HTTPResponse
*/
interface IHTTPResult
{
/**
* Gets the Return Code
*
* @return string The Return Code
*/
public function getReturnCode();
/**
* Returns the Content Type
*
* @return string the Content Type
*/
public function getContentType();
/**
* Returns the headers
*
* @param string $field optional header field. Return all fields if empty
*
* @return string the headers or the specified content of the header variable
*/
public function getHeader(string $field = '');
/**
* Check if a specified header exists
*
* @param string $field header field
*
* @return boolean "true" if header exists
*/
public function inHeader(string $field);
/**
* Returns the headers as an associated array
*
* @return array associated header array
*/
public function getHeaderArray();
/**
* @return bool
*/
public function isSuccess();
/**
* @return string
*/
public function getUrl();
/**
* @return string
*/
public function getRedirectUrl();
/**
* @return string
*/
public function getBody();
/**
* @return array
*/
public function getInfo();
/**
* @return boolean
*/
public function isRedirectUrl();
/**
* @return integer
*/
public function getErrorNumber();
/**
* @return string
*/
public function getError();
/**
* @return boolean
*/
public function isTimeout();
}