| 1 |
<?php |
| 2 |
/* |
| 3 |
* This file is part of the ManageWP Worker plugin. |
| 4 |
* |
| 5 |
* (c) ManageWP LLC <contact@managewp.com> |
| 6 |
* |
| 7 |
* For the full copyright and license information, please view the LICENSE |
| 8 |
* file that was distributed with this source code. |
| 9 |
*/ |
| 10 |
|
| 11 |
class MWP_Http_MultipartResponsePart |
| 12 |
{ |
| 13 |
|
| 14 |
/** @var array */ |
| 15 |
private $headers = array(); |
| 16 |
|
| 17 |
/** @var string Must conform RFC 1314 (@see https://en.wikipedia.org/wiki/MIME#Content-Transfer-Encoding) */ |
| 18 |
private $encoding = 'binary'; |
| 19 |
|
| 20 |
/** @var MWP_Stream_Interface */ |
| 21 |
private $body; |
| 22 |
|
| 23 |
public function __construct($headers, $body = null, $encoding = 'binary') |
| 24 |
{ |
| 25 |
$this->headers = array_change_key_case($headers, CASE_LOWER); |
| 26 |
$this->setBody($body); |
| 27 |
$this->setEncoding($encoding); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* @param string $header |
| 32 |
* @param string $value |
| 33 |
*/ |
| 34 |
public function setHeader($header, $value) |
| 35 |
{ |
| 36 |
$this->headers[strtolower($header)] = $value; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @param $header |
| 41 |
* |
| 42 |
* @return string|null |
| 43 |
*/ |
| 44 |
public function getHeader($header) |
| 45 |
{ |
| 46 |
if ($this->hasHeader($header)) { |
| 47 |
return $this->headers[strtolower($header)]; |
| 48 |
} |
| 49 |
|
| 50 |
return null; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* @param string $header |
| 55 |
* |
| 56 |
* @return bool |
| 57 |
*/ |
| 58 |
public function hasHeader($header) |
| 59 |
{ |
| 60 |
return isset($this->headers[strtolower($header)]); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* @return array |
| 65 |
*/ |
| 66 |
public function getHeaders() |
| 67 |
{ |
| 68 |
return $this->headers; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* @return MWP_Stream_Interface|null |
| 73 |
*/ |
| 74 |
public function getBody() |
| 75 |
{ |
| 76 |
return $this->body; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* @param MWP_Stream_Interface $body |
| 81 |
*/ |
| 82 |
public function setBody($body) |
| 83 |
{ |
| 84 |
if ($body !== null && !$body instanceof MWP_Stream_Interface) { |
| 85 |
$body = MWP_Stream_Stream::factory($body); |
| 86 |
} |
| 87 |
|
| 88 |
$this->body = $body; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* @return string |
| 93 |
*/ |
| 94 |
public function getEncoding() |
| 95 |
{ |
| 96 |
return $this->encoding; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* @param string $encoding |
| 101 |
*/ |
| 102 |
public function setEncoding($encoding) |
| 103 |
{ |
| 104 |
$this->encoding = $encoding; |
| 105 |
} |
| 106 |
} |
| 107 |
|