Soap server with attachments refactoring
This commit is contained in:
12
src/BeSimple/SoapCommon/AttachmentsHandler.php
Normal file
12
src/BeSimple/SoapCommon/AttachmentsHandler.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapCommon;
|
||||
|
||||
use BeSimple\SoapCommon\Storage\RequestHandlerAttachmentsStorage;
|
||||
|
||||
/** @todo: PBe - refactor this interface + usages -> inconsistent - adding storage, getting items - WTF APi? */
|
||||
interface AttachmentsHandler
|
||||
{
|
||||
public function addAttachmentStorage(RequestHandlerAttachmentsStorage $requestHandlerAttachmentsStorage);
|
||||
public function getAttachmentsFromStorage();
|
||||
}
|
@ -14,16 +14,13 @@ namespace BeSimple\SoapCommon\Converter;
|
||||
|
||||
use BeSimple\SoapCommon\Helper;
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
use BeSimple\SoapCommon\Converter\SoapKernelAwareInterface;
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterInterface;
|
||||
|
||||
/**
|
||||
* MTOM type converter.
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
class MtomTypeConverter implements TypeConverterInterface, SoapKernelAwareInterface
|
||||
class MtomTypeConverter implements TypeConverterInterface
|
||||
{
|
||||
/**
|
||||
* @var \BeSimple\SoapCommon\SoapKernel $soapKernel SoapKernel instance
|
||||
@ -54,25 +51,6 @@ class MtomTypeConverter implements TypeConverterInterface, SoapKernelAwareInterf
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($data);
|
||||
|
||||
$includes = $doc->getElementsByTagNameNS(Helper::NS_XOP, 'Include');
|
||||
$include = $includes->item(0);
|
||||
|
||||
// convert href -> myhref for external references as PHP throws exception in this case
|
||||
// http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/ext/soap/php_encoding.c?view=markup#l3436
|
||||
$ref = $include->getAttribute('myhref');
|
||||
|
||||
if ('cid:' === substr($ref, 0, 4)) {
|
||||
$contentId = urldecode(substr($ref, 4));
|
||||
|
||||
if (null !== ($part = $this->soapKernel->getAttachment($contentId))) {
|
||||
|
||||
return $part->getContent();
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -84,8 +62,6 @@ class MtomTypeConverter implements TypeConverterInterface, SoapKernelAwareInterf
|
||||
$part = new MimePart($data);
|
||||
$contentId = trim($part->getHeader('Content-ID'), '<>');
|
||||
|
||||
$this->soapKernel->addAttachment($part);
|
||||
|
||||
$doc = new \DOMDocument();
|
||||
$node = $doc->createElement($this->getTypeName());
|
||||
$doc->appendChild($node);
|
||||
@ -97,12 +73,4 @@ class MtomTypeConverter implements TypeConverterInterface, SoapKernelAwareInterf
|
||||
|
||||
return $doc->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setKernel(SoapKernel $soapKernel)
|
||||
{
|
||||
$this->soapKernel = $soapKernel;
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapCommon.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Converter;
|
||||
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
|
||||
/**
|
||||
* Internal type converter interface.
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
interface SoapKernelAwareInterface
|
||||
{
|
||||
/**
|
||||
* Set SoapKernel instance.
|
||||
*
|
||||
* @param \BeSimple\SoapCommon\SoapKernel $soapKernel SoapKernel instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setKernel(SoapKernel $soapKernel);
|
||||
}
|
@ -35,23 +35,6 @@ class SwaTypeConverter implements TypeConverterInterface
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($data);
|
||||
|
||||
// convert href -> myhref for external references as PHP throws exception in this case
|
||||
// http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/ext/soap/php_encoding.c?view=markup#l3436
|
||||
$ref = $doc->documentElement->getAttribute('myhref');
|
||||
|
||||
if ('cid:' === substr($ref, 0, 4)) {
|
||||
$contentId = urldecode(substr($ref, 4));
|
||||
|
||||
// @todo-critical: ci je nyni zodpovednost vygetovat attachmenty
|
||||
if (null !== ($part = $this->soapKernel->getAttachment($contentId))) {
|
||||
|
||||
return $part->getContent();
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -63,9 +46,6 @@ class SwaTypeConverter implements TypeConverterInterface
|
||||
$part = new MimePart($data);
|
||||
$contentId = trim($part->getHeader('Content-ID'), '<>');
|
||||
|
||||
// @todo-critical: ci je nyni zodpovednost nastrkat attachmenty
|
||||
//$this->soapKernel->addAttachment($part);
|
||||
|
||||
return sprintf('<%s href="%s"/>', $this->getTypeName(), 'cid:' . $contentId);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace BeSimple\SoapCommon\Mime;
|
||||
|
||||
use Exception;
|
||||
use BeSimple\SoapCommon\Helper;
|
||||
|
||||
/**
|
||||
@ -38,16 +39,14 @@ class MultiPart extends PartHeader
|
||||
/**
|
||||
* Mime parts.
|
||||
*
|
||||
* @var array(\BeSimple\SoapCommon\Mime\Part)
|
||||
* @var \BeSimple\SoapCommon\Mime\Part[]
|
||||
*/
|
||||
protected $parts = array();
|
||||
protected $parts = [];
|
||||
|
||||
/**
|
||||
* Construct new mime object.
|
||||
*
|
||||
* @param string $boundary Boundary string
|
||||
*
|
||||
* @return void
|
||||
* @param string $boundary
|
||||
*/
|
||||
public function __construct($boundary = null)
|
||||
{
|
||||
@ -55,10 +54,9 @@ class MultiPart extends PartHeader
|
||||
$this->setHeader('Content-Type', 'multipart/related');
|
||||
$this->setHeader('Content-Type', 'type', 'text/xml');
|
||||
$this->setHeader('Content-Type', 'charset', 'utf-8');
|
||||
if (is_null($boundary)) {
|
||||
$boundary = $this->generateBoundary();
|
||||
if ($boundary !== null) {
|
||||
$this->setHeader('Content-Type', 'boundary', $boundary);
|
||||
}
|
||||
$this->setHeader('Content-Type', 'boundary', $boundary);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,10 +71,11 @@ class MultiPart extends PartHeader
|
||||
$message = ($withHeaders === true) ? $this->generateHeaders() : "";
|
||||
// add parts
|
||||
foreach ($this->parts as $part) {
|
||||
$message .= "\r\n" . '--' . $this->getHeader('Content-Type', 'boundary') . "\r\n";
|
||||
$message .= "\n" . '--' . $this->getHeader('Content-Type', 'boundary') . "\n";
|
||||
$message .= $part->getMessagePart();
|
||||
}
|
||||
$message .= "\r\n" . '--' . $this->getHeader('Content-Type', 'boundary') . '--';
|
||||
$message .= "\n" . '--' . $this->getHeader('Content-Type', 'boundary') . '--';
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
@ -84,22 +83,23 @@ class MultiPart extends PartHeader
|
||||
* Get string array with MIME headers for usage in HTTP header (with CURL).
|
||||
* Only 'Content-Type' and 'Content-Description' headers are returned.
|
||||
*
|
||||
* @return arrray(string)
|
||||
* @return string[]
|
||||
*/
|
||||
public function getHeadersForHttp()
|
||||
{
|
||||
$allowed = array(
|
||||
$allowedHeaders = [
|
||||
'Content-Type',
|
||||
'Content-Description',
|
||||
);
|
||||
$headers = array();
|
||||
];
|
||||
$headers = [];
|
||||
foreach ($this->headers as $fieldName => $value) {
|
||||
if (in_array($fieldName, $allowed)) {
|
||||
if (in_array($fieldName, $allowedHeaders)) {
|
||||
$fieldValue = $this->generateHeaderFieldValue($value);
|
||||
// for http only ISO-8859-1
|
||||
$headers[] = $fieldName . ': '. iconv('utf-8', 'ISO-8859-1//TRANSLIT', $fieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
@ -122,44 +122,51 @@ class MultiPart extends PartHeader
|
||||
}
|
||||
|
||||
/**
|
||||
* Get part with given content id. If there is no content id given it
|
||||
* returns the main part that is defined through the content-id start
|
||||
* parameter.
|
||||
* Get part with given content id.
|
||||
*
|
||||
* @param string $contentId Content id of desired part
|
||||
*
|
||||
* @return \BeSimple\SoapCommon\Mime\Part|null
|
||||
* @return \BeSimple\SoapCommon\Mime\Part
|
||||
*/
|
||||
public function getPart($contentId = null)
|
||||
public function getPart($contentId)
|
||||
{
|
||||
if (is_null($contentId)) {
|
||||
$contentId = $this->mainPartContentId;
|
||||
}
|
||||
if (isset($this->parts[$contentId])) {
|
||||
return $this->parts[$contentId];
|
||||
}
|
||||
return null;
|
||||
|
||||
throw new Exception('MimePart not found by ID: ' . $contentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all parts.
|
||||
* Get main part.
|
||||
*
|
||||
* @param boolean $includeMainPart Should main part be in result set
|
||||
*
|
||||
* @return array(\BeSimple\SoapCommon\Mime\Part)
|
||||
* @return \BeSimple\SoapCommon\Mime\Part
|
||||
*/
|
||||
public function getParts($includeMainPart = false)
|
||||
public function getMainPart()
|
||||
{
|
||||
if ($includeMainPart === true) {
|
||||
$parts = $this->parts;
|
||||
} else {
|
||||
$parts = array();
|
||||
foreach ($this->parts as $cid => $part) {
|
||||
if ($cid != $this->mainPartContentId) {
|
||||
$parts[$cid] = $part;
|
||||
}
|
||||
foreach ($this->parts as $cid => $part) {
|
||||
if ($cid === $this->mainPartContentId) {
|
||||
return $part;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception('SoapRequest error: main part not found by Id: ' . $this->mainPartContentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment parts.
|
||||
*
|
||||
* @return \BeSimple\SoapCommon\Mime\Part[]
|
||||
*/
|
||||
public function getAttachments()
|
||||
{
|
||||
$parts = [];
|
||||
foreach ($this->parts as $cid => $part) {
|
||||
if ($cid !== $this->mainPartContentId) {
|
||||
$parts[$cid] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
return $parts;
|
||||
}
|
||||
|
||||
@ -168,7 +175,7 @@ class MultiPart extends PartHeader
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateBoundary()
|
||||
public function generateBoundary()
|
||||
{
|
||||
return 'urn:uuid:' . Helper::generateUUID();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class Parser
|
||||
*
|
||||
* @return \BeSimple\SoapCommon\Mime\MultiPart
|
||||
*/
|
||||
public static function parseMimeMessage($mimeMessage, array $headers = array())
|
||||
public static function parseMimeMessage($mimeMessage, array $headers = [])
|
||||
{
|
||||
$boundary = null;
|
||||
$start = null;
|
||||
@ -37,7 +37,7 @@ class Parser
|
||||
// add given headers, e.g. coming from HTTP headers
|
||||
if (count($headers) > 0) {
|
||||
foreach ($headers as $name => $value) {
|
||||
if ($name == 'Content-Type') {
|
||||
if ($name === 'Content-Type') {
|
||||
self::parseContentTypeHeader($multipart, $name, $value);
|
||||
$boundary = $multipart->getHeader('Content-Type', 'boundary');
|
||||
$start = $multipart->getHeader('Content-Type', 'start');
|
||||
@ -49,43 +49,57 @@ class Parser
|
||||
}
|
||||
$content = '';
|
||||
$currentPart = $multipart;
|
||||
$lines = preg_split("/(\r\n)/", $mimeMessage);
|
||||
foreach ($lines as $line) {
|
||||
// ignore http status code and POST *
|
||||
if (substr($line, 0, 5) == 'HTTP/' || substr($line, 0, 4) == 'POST') {
|
||||
continue;
|
||||
}
|
||||
if (isset($currentHeader)) {
|
||||
if (isset($line[0]) && ($line[0] === ' ' || $line[0] === "\t")) {
|
||||
$currentHeader .= $line;
|
||||
$lines = preg_split("/(\r\n)|(\n)/", $mimeMessage);
|
||||
if (self::hasBoundary($lines)) {
|
||||
foreach ($lines as $line) {
|
||||
// ignore http status code and POST *
|
||||
if (substr($line, 0, 5) == 'HTTP/' || substr($line, 0, 4) == 'POST') {
|
||||
continue;
|
||||
}
|
||||
if (strpos($currentHeader, ':') !== false) {
|
||||
list($headerName, $headerValue) = explode(':', $currentHeader, 2);
|
||||
$headerValue = iconv_mime_decode($headerValue, 0, 'utf-8');
|
||||
if (strpos($headerValue, ';') !== false) {
|
||||
self::parseContentTypeHeader($currentPart, $headerName, $headerValue);
|
||||
$boundary = $multipart->getHeader('Content-Type', 'boundary');
|
||||
$start = $multipart->getHeader('Content-Type', 'start');
|
||||
} else {
|
||||
$currentPart->setHeader($headerName, trim($headerValue));
|
||||
if (isset($currentHeader)) {
|
||||
if (isset($line[0]) && ($line[0] === ' ' || $line[0] === "\t")) {
|
||||
$currentHeader .= $line;
|
||||
continue;
|
||||
}
|
||||
if (strpos($currentHeader, ':') !== false) {
|
||||
list($headerName, $headerValue) = explode(':', $currentHeader, 2);
|
||||
$headerValue = iconv_mime_decode($headerValue, 0, 'utf-8');
|
||||
if (strpos($headerValue, ';') !== false) {
|
||||
self::parseContentTypeHeader($currentPart, $headerName, $headerValue);
|
||||
$boundary = $multipart->getHeader('Content-Type', 'boundary');
|
||||
$start = $multipart->getHeader('Content-Type', 'start');
|
||||
} else {
|
||||
$currentPart->setHeader($headerName, trim($headerValue));
|
||||
}
|
||||
}
|
||||
unset($currentHeader);
|
||||
}
|
||||
unset($currentHeader);
|
||||
}
|
||||
if ($inHeader) {
|
||||
if (trim($line) == '') {
|
||||
$inHeader = false;
|
||||
if ($inHeader) {
|
||||
if (trim($line) == '') {
|
||||
$inHeader = false;
|
||||
continue;
|
||||
}
|
||||
$currentHeader = $line;
|
||||
continue;
|
||||
}
|
||||
$currentHeader = $line;
|
||||
continue;
|
||||
} else {
|
||||
// check if we hit any of the boundaries
|
||||
if (strlen($line) > 0 && $line[0] == "-") {
|
||||
if (strcmp(trim($line), '--' . $boundary) === 0) {
|
||||
if ($currentPart instanceof Part) {
|
||||
$content = substr($content, 0, -2);
|
||||
} else {
|
||||
if (self::isBoundary($line)) {
|
||||
if (strcmp(trim($line), '--' . $boundary) === 0) {
|
||||
if ($currentPart instanceof Part) {
|
||||
$content = substr($content, 0, -1);
|
||||
self::decodeContent($currentPart, $content);
|
||||
// check if there is a start parameter given, if not set first part
|
||||
$isMain = (is_null($start) || $start == $currentPart->getHeader('Content-ID')) ? true : false;
|
||||
if ($isMain === true) {
|
||||
$start = $currentPart->getHeader('Content-ID');
|
||||
}
|
||||
$multipart->addPart($currentPart, $isMain);
|
||||
}
|
||||
$currentPart = new Part();
|
||||
$hitFirstBoundary = true;
|
||||
$inHeader = true;
|
||||
$content = '';
|
||||
} elseif (strcmp(trim($line), '--' . $boundary . '--') === 0) {
|
||||
$content = substr($content, 0, -1);
|
||||
self::decodeContent($currentPart, $content);
|
||||
// check if there is a start parameter given, if not set first part
|
||||
$isMain = (is_null($start) || $start == $currentPart->getHeader('Content-ID')) ? true : false;
|
||||
@ -93,34 +107,24 @@ class Parser
|
||||
$start = $currentPart->getHeader('Content-ID');
|
||||
}
|
||||
$multipart->addPart($currentPart, $isMain);
|
||||
$content = '';
|
||||
}
|
||||
$currentPart = new Part();
|
||||
$hitFirstBoundary = true;
|
||||
$inHeader = true;
|
||||
$content = '';
|
||||
} elseif (strcmp(trim($line), '--' . $boundary . '--') === 0) {
|
||||
$content = substr($content, 0, -2);
|
||||
self::decodeContent($currentPart, $content);
|
||||
// check if there is a start parameter given, if not set first part
|
||||
$isMain = (is_null($start) || $start == $currentPart->getHeader('Content-ID')) ? true : false;
|
||||
if ($isMain === true) {
|
||||
$start = $currentPart->getHeader('Content-ID');
|
||||
} else {
|
||||
if ($hitFirstBoundary === false) {
|
||||
if (trim($line) !== '') {
|
||||
$inHeader = true;
|
||||
$currentHeader = $line;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$multipart->addPart($currentPart, $isMain);
|
||||
$content = '';
|
||||
$content .= $line . "\n";
|
||||
}
|
||||
} else {
|
||||
if ($hitFirstBoundary === false) {
|
||||
if (trim($line) != '') {
|
||||
$inHeader = true;
|
||||
$currentHeader = $line;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$content .= $line . "\r\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$multipart->addPart(new Part($mimeMessage), true);
|
||||
}
|
||||
|
||||
return $multipart;
|
||||
}
|
||||
|
||||
@ -135,7 +139,6 @@ class Parser
|
||||
* @param string $headerName Header name
|
||||
* @param string $headerValue Header value
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private static function parseContentTypeHeader(PartHeader $part, $headerName, $headerValue)
|
||||
{
|
||||
@ -168,7 +171,6 @@ class Parser
|
||||
* @param \BeSimple\SoapCommon\Mime\Part $part Part to add content
|
||||
* @param string $content Content to decode
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private static function decodeContent(Part $part, $content)
|
||||
{
|
||||
@ -184,4 +186,21 @@ class Parser
|
||||
}
|
||||
$part->setContent($content);
|
||||
}
|
||||
|
||||
private static function hasBoundary(array $lines)
|
||||
{
|
||||
foreach ($lines as $line) {
|
||||
if (self::isBoundary($line)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function isBoundary($line)
|
||||
{
|
||||
return strlen($line) > 0 && $line[0] === "-";
|
||||
}
|
||||
}
|
@ -69,7 +69,6 @@ class Part extends PartHeader
|
||||
* @param string $encoding Encoding
|
||||
* @param string $contentId Content id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($content = null, $contentType = 'application/octet-stream', $charset = null, $encoding = self::ENCODING_BINARY, $contentId = null)
|
||||
{
|
||||
|
@ -19,12 +19,7 @@ namespace BeSimple\SoapCommon\Mime;
|
||||
*/
|
||||
abstract class PartHeader
|
||||
{
|
||||
/**
|
||||
* Mime headers.
|
||||
*
|
||||
* @var array(string=>mixed|array(mixed))
|
||||
*/
|
||||
protected $headers = array();
|
||||
protected $headers = [];
|
||||
|
||||
/**
|
||||
* Add a new header to the mime part.
|
||||
@ -39,10 +34,10 @@ abstract class PartHeader
|
||||
{
|
||||
if (isset($this->headers[$name]) && !is_null($subValue)) {
|
||||
if (!is_array($this->headers[$name])) {
|
||||
$this->headers[$name] = array(
|
||||
$this->headers[$name] = [
|
||||
'@' => $this->headers[$name],
|
||||
$value => $subValue,
|
||||
);
|
||||
];
|
||||
} else {
|
||||
$this->headers[$name][$value] = $subValue;
|
||||
}
|
||||
@ -76,6 +71,7 @@ abstract class PartHeader
|
||||
return $this->headers[$name];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -86,19 +82,12 @@ abstract class PartHeader
|
||||
*/
|
||||
protected function generateHeaders()
|
||||
{
|
||||
$charset = strtolower($this->getHeader('Content-Type', 'charset'));
|
||||
$preferences = array(
|
||||
'scheme' => 'Q',
|
||||
'input-charset' => 'utf-8',
|
||||
'output-charset' => $charset,
|
||||
);
|
||||
$headers = '';
|
||||
foreach ($this->headers as $fieldName => $value) {
|
||||
$fieldValue = $this->generateHeaderFieldValue($value);
|
||||
// do not use proper encoding as Apache Axis does not understand this
|
||||
// $headers .= iconv_mime_encode($field_name, $field_value, $preferences) . "\r\n";
|
||||
$headers .= $fieldName . ': ' . $fieldValue . "\r\n";
|
||||
$headers .= $fieldName . ': ' . $fieldValue . "\n";
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
@ -124,6 +113,7 @@ abstract class PartHeader
|
||||
} else {
|
||||
$fieldValue .= $value;
|
||||
}
|
||||
|
||||
return $fieldValue;
|
||||
}
|
||||
|
||||
@ -143,4 +133,4 @@ abstract class PartHeader
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,12 +45,12 @@ abstract class SoapMessage
|
||||
/**
|
||||
* Content types for SOAP versions.
|
||||
*
|
||||
* @var array(string=>string)
|
||||
* @var array (string=>string)
|
||||
*/
|
||||
static protected $versionToContentTypeMap = array(
|
||||
static protected $versionToContentTypeMap = [
|
||||
SOAP_1_1 => 'text/xml; charset=utf-8',
|
||||
SOAP_1_2 => 'application/soap+xml; charset=utf-8'
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* SOAP action.
|
||||
@ -64,7 +64,7 @@ abstract class SoapMessage
|
||||
*
|
||||
* @var array(\BeSimple\SoapCommon\Mime\Part)
|
||||
*/
|
||||
protected $attachments = array();
|
||||
protected $attachments;
|
||||
|
||||
/**
|
||||
* Message content (MIME Message or SOAP Envelope).
|
||||
@ -111,8 +111,8 @@ abstract class SoapMessage
|
||||
*/
|
||||
public static function getContentTypeForVersion($version)
|
||||
{
|
||||
if (!in_array($version, array(SOAP_1_1, SOAP_1_2))) {
|
||||
throw new \InvalidArgumentException("The 'version' argument has to be either 'SOAP_1_1' or 'SOAP_1_2'!");
|
||||
if (!in_array($version, [SOAP_1_1, SOAP_1_2])) {
|
||||
throw new \InvalidArgumentException('Invalid SOAP version: ' . $version);
|
||||
}
|
||||
|
||||
return self::$versionToContentTypeMap[$version];
|
||||
@ -138,10 +138,15 @@ abstract class SoapMessage
|
||||
$this->action = $action;
|
||||
}
|
||||
|
||||
public function hasAttachments()
|
||||
{
|
||||
return $this->attachments !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachments.
|
||||
*
|
||||
* @return array(\BeSimple\SoapCommon\Mime\Part)
|
||||
* @return \BeSimple\SoapCommon\Mime\Part[]
|
||||
*/
|
||||
public function getAttachments()
|
||||
{
|
||||
@ -151,7 +156,7 @@ abstract class SoapMessage
|
||||
/**
|
||||
* Set SOAP action.
|
||||
*
|
||||
* @param array(\BeSimple\SoapCommon\Mime\Part) $attachments Attachment array
|
||||
* @param \BeSimple\SoapCommon\Mime\Part[] $attachments
|
||||
*/
|
||||
public function setAttachments(array $attachments)
|
||||
{
|
||||
@ -165,10 +170,11 @@ abstract class SoapMessage
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if (null !== $this->contentDomDocument) {
|
||||
if ($this->contentDomDocument !== null) {
|
||||
$this->content = $this->contentDomDocument->saveXML();
|
||||
$this->contentDomDocument = null;
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,11 @@ class SoapOptions
|
||||
return $this->wsdlCacheDir;
|
||||
}
|
||||
|
||||
public function isWsdlCached()
|
||||
{
|
||||
return $this->wsdlCacheType !== self::SOAP_CACHE_TYPE_NONE;
|
||||
}
|
||||
|
||||
public function getWsdlCacheType()
|
||||
{
|
||||
return $this->wsdlCacheType;
|
||||
|
@ -10,11 +10,12 @@ class SoapRequestFactory
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param string $version SOAP version
|
||||
* @param string $contentType Content Type
|
||||
* @param string $content Content
|
||||
*
|
||||
* @return SoapRequest
|
||||
*/
|
||||
public static function create($location, $action, $version, $content = null)
|
||||
public static function create($location, $action, $version, $contentType, $content = null)
|
||||
{
|
||||
$request = new SoapRequest();
|
||||
// $content is if unmodified from SoapClient not a php string type!
|
||||
@ -22,7 +23,6 @@ class SoapRequestFactory
|
||||
$request->setLocation($location);
|
||||
$request->setAction($action);
|
||||
$request->setVersion($version);
|
||||
$contentType = SoapMessage::getContentTypeForVersion($version);
|
||||
$request->setContentType($contentType);
|
||||
|
||||
return $request;
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapCommon\Storage\AbstractStorage;
|
||||
|
||||
abstract class AbstractStorage
|
||||
{
|
||||
private $items;
|
||||
|
||||
protected function getItems()
|
||||
{
|
||||
$items = $this->items;
|
||||
$this->resetItems();
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
protected function setItems(array $items)
|
||||
{
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
private function resetItems()
|
||||
{
|
||||
$this->items = [];
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapCommon\Storage;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapAttachment;
|
||||
use BeSimple\SoapCommon\Storage\AbstractStorage\AbstractStorage;
|
||||
|
||||
class RequestHandlerAttachmentsStorage extends AbstractStorage
|
||||
{
|
||||
/**
|
||||
* @param SoapAttachment[] $attachments
|
||||
*/
|
||||
public function __construct(array $attachments)
|
||||
{
|
||||
parent::setItems($attachments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SoapAttachment[]
|
||||
*/
|
||||
public function getAttachments()
|
||||
{
|
||||
return parent::getItems();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user