* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Multipart extends Writer { /** @var string */ protected $subType; /** @var string */ protected $boundary; /** @var \PSX\Http\ResponseInterface[] */ protected $parts; /** * @param string $subType * @param string|null $boundary */ public function __construct($subType = 'mixed', $boundary = null) { parent::__construct(null, null); $this->subType = $subType; $this->boundary = $boundary === null ? $this->generateBoundary() : $boundary; $this->parts = []; } /** * @return string */ public function getSubType() { return $this->subType; } /** * @return string|null */ public function getBoundary() { return $this->boundary; } /** * @param \PSX\Http\ResponseInterface $response */ public function addPart(ResponseInterface $response) { $this->parts[] = $response; } /** * @return \PSX\Http\ResponseInterface[] */ public function getParts() { return $this->parts; } /** * @inheritdoc */ public function writeTo(ResponseInterface $response) { $response->setHeader('Content-Type', 'multipart/' . $this->subType . '; boundary="' . $this->boundary . '"'); $parts = $this->getParts(); foreach ($parts as $part) { $out = '--' . $this->boundary . Http::NEW_LINE; $headers = ResponseParser::buildHeaderFromMessage($part); foreach ($headers as $header) { $out.= $header . Http::NEW_LINE; } $out.= Http::NEW_LINE; $out.= (string) $part->getBody(); $out.= Http::NEW_LINE; $response->getBody()->write($out); } $response->getBody()->write('--' . $this->boundary . '--' . Http::NEW_LINE); } private function generateBoundary() { return sha1(uniqid()); } } __halt_compiler();----SIGNATURE:----j56faRe1AFG7v/FFYFb7TP9OhXgkGJ0tUp44++Yhq1l9k6B9qZgFvNiRJJYjYFcVeqdKPab2YEe4bfy0z9ZN3hmlHTLy8wo18eg0ZtQORsDwgvhWwqwgmAzsdcn7fNh9heGNz/VffvBphKoRf9DmQx/1LRoeQi9h4y/1vu3sxGerBbYqeMG/878R9ig4gwwpnJCWDR/4Wjho8SLxAwjcweAYLlrnu6SU5HhDjlXyA33dBvcWnE+ThJozPvDF/PlRM9ZkFzxVj+scmvej4gsdDuO+/JF4GTWyXCPfFjg3TT71Zrb40wzpe93R7whtwYHiilWOTALzVJD8UL6wjONDUbcUjijiJvLEqOvadezs7wDPRBDXH4tL0FRVbA7NbXo4mrmDppUH1pDkObvp1149a5o4NlQAZekYs+leyUqqbluTuucVgy1vK06pH7EZQ+SLl/5tGpSvVpH2M0rqEmtS7K7cGxcs5pVkUgzA4j25CTckhz0KnZ/cea8MQx6BmYSfpk4N4gqwZCT1RYDE25fU8PNGAfr8SkgKK+2lStMGuwu+U+Z8drHzYmGWUGkR3hOytJ8f32MNDeUQnaKcvzDCKdbPbDvufOzehtoco+6PAXb3mPLMOZbR0E8prsdV17+TmjBjDRs2CRYUBav2DkKgK2HmcIvatFKgAG982YyYgQo=----ATTACHMENT:----NDQ2MTg4NjE3NDE0MjA5NCA1NTM0ODExMjM1MzgxNjA0IDQzMTk3NjY4OTUwMjI3OTk=