SoapClient large refactoring & tests update
This commit is contained in:
@ -28,57 +28,38 @@ use BeSimple\SoapCommon\Helper;
|
||||
*/
|
||||
class Part extends PartHeader
|
||||
{
|
||||
/**
|
||||
* Encoding type base 64
|
||||
*/
|
||||
const ENCODING_BASE64 = 'base64';
|
||||
|
||||
/**
|
||||
* Encoding type binary
|
||||
*/
|
||||
const ENCODING_BINARY = 'binary';
|
||||
|
||||
/**
|
||||
* Encoding type eight bit
|
||||
*/
|
||||
const ENCODING_EIGHT_BIT = '8bit';
|
||||
|
||||
/**
|
||||
* Encoding type seven bit
|
||||
*/
|
||||
const ENCODING_SEVEN_BIT = '7bit';
|
||||
|
||||
/**
|
||||
* Encoding type quoted printable
|
||||
*/
|
||||
const ENCODING_QUOTED_PRINTABLE = 'quoted-printable';
|
||||
|
||||
/**
|
||||
* Content.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
const CHARSET_UTF8 = 'utf-8';
|
||||
|
||||
const CONTENT_TYPE_STREAM = 'application/octet-stream';
|
||||
const CONTENT_TYPE_PDF = 'application/pdf';
|
||||
|
||||
/** @var mixed */
|
||||
protected $content;
|
||||
|
||||
/**
|
||||
* Construct new mime object.
|
||||
*
|
||||
* @param mixed $content Content
|
||||
* @param string $contentType Content type
|
||||
* @param string $charset Charset
|
||||
* @param string $encoding Encoding
|
||||
* @param string $contentId Content id
|
||||
*
|
||||
*/
|
||||
public function __construct($content = null, $contentType = 'application/octet-stream', $charset = null, $encoding = self::ENCODING_BINARY, $contentId = null)
|
||||
{
|
||||
public function __construct(
|
||||
$content = null,
|
||||
$contentType = self::CONTENT_TYPE_STREAM,
|
||||
$charset = self::CHARSET_UTF8,
|
||||
$encoding = self::ENCODING_BINARY,
|
||||
$contentId = null
|
||||
) {
|
||||
$this->content = $content;
|
||||
|
||||
$this->setHeader('Content-Type', $contentType);
|
||||
if (!is_null($charset)) {
|
||||
$this->setHeader('Content-Type', 'charset', $charset);
|
||||
} else {
|
||||
$this->setHeader('Content-Type', 'charset', 'utf-8');
|
||||
}
|
||||
$this->setHeader('Content-Type', 'charset', $charset);
|
||||
$this->setHeader('Content-Transfer-Encoding', $encoding);
|
||||
if (is_null($contentId)) {
|
||||
$contentId = $this->generateContentId();
|
||||
@ -106,6 +87,16 @@ class Part extends PartHeader
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function hasContentId($contentTypeContentId)
|
||||
{
|
||||
return $contentTypeContentId === $this->getContentId();
|
||||
}
|
||||
|
||||
public function getContentId()
|
||||
{
|
||||
return $this->getHeader('Content-ID');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mime content.
|
||||
*
|
||||
@ -137,10 +128,10 @@ class Part extends PartHeader
|
||||
{
|
||||
$encoding = strtolower($this->getHeader('Content-Transfer-Encoding'));
|
||||
$charset = strtolower($this->getHeader('Content-Type', 'charset'));
|
||||
if ($charset != 'utf-8') {
|
||||
$content = iconv('utf-8', $charset . '//TRANSLIT', $this->content);
|
||||
if ($charset !== self::CHARSET_UTF8) {
|
||||
$content = iconv(self::CHARSET_UTF8, $charset.'//TRANSLIT', $this->getContent());
|
||||
} else {
|
||||
$content = $this->content;
|
||||
$content = $this->getContent();
|
||||
}
|
||||
switch ($encoding) {
|
||||
case self::ENCODING_BASE64:
|
||||
|
Reference in New Issue
Block a user