1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136:
<?php
/**
* @author: stev leibelt <artodeto@bazzline.net>
* @since: 2015-12-09
*/
namespace Net\Bazzline\Component\Curl\Response;
use InvalidArgumentException;
class Response
{
const ARRAY_KEY_CONTENT = 'content';
const ARRAY_KEY_CONTENT_TYPE = 'content_type';
const ARRAY_KEY_ERROR = 'error';
const ARRAY_KEY_ERROR_CODE = 'error_code';
const ARRAY_KEY_STATUS_CODE = 'status_code';
/** @var null|mixed */
private $content;
/** @var null|string */
private $contentType;
/** @var null|string */
private $error;
/** @var null|int */
private $errorCode;
/** @var array */
private $headerLines;
/** @var null|int */
private $statusCode;
/**
* @param mixed $content
* @param string $contentType
* @param string $error
* @param int $errorCode
* @param array $headerLines
* @param int $statusCode
*/
public function __construct($content, $contentType, $error, $errorCode, array $headerLines, $statusCode)
{
$this->content = $content;
$this->contentType = $contentType;
$this->error = $error;
$this->errorCode = $errorCode;
$this->headerLines = $headerLines;
$this->statusCode = $statusCode;
}
/**
* @return null|mixed
*/
public function content()
{
return $this->content;
}
/**
* @return null|string
*/
public function contentType()
{
return $this->contentType;
}
/**
* @param string $prefix
* @return null|string
* @throws InvalidArgumentException
*/
public function headerLine($prefix)
{
$valueIsNotAvailable = (!isset($this->headerLines[$prefix]));
if ($valueIsNotAvailable) {
throw new InvalidArgumentException(
'no headline available for prefix: "' . $prefix . '"'
);
}
return $this->headerLines[$prefix];
}
/**
* @return array
*/
public function headerLines()
{
return $this->headerLines;
}
/**
* @return null|string
*/
public function error()
{
return $this->error;
}
/**
* @return null|int
* @see: http://curl.haxx.se/libcurl/c/libcurl-errors.html
*/
public function errorCode()
{
return $this->errorCode;
}
/**
* @return null|int
*/
public function statusCode()
{
return $this->statusCode;
}
/**
* @return array
*/
public function convertIntoAnArray()
{
return [
self::ARRAY_KEY_CONTENT => $this->content,
self::ARRAY_KEY_CONTENT_TYPE => $this->contentType,
self::ARRAY_KEY_ERROR => $this->error,
self::ARRAY_KEY_ERROR_CODE => $this->errorCode,
self::ARRAY_KEY_STATUS_CODE => $this->statusCode
];
}
}