fix parser and add attachment support
This commit is contained in:
parent
e151d06371
commit
f6ea609f46
|
@ -49,7 +49,7 @@ class Parser
|
|||
}
|
||||
$content = '';
|
||||
$currentPart = $multipart;
|
||||
$lines = preg_split("/\r\n|\n/", $mimeMessage);
|
||||
$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') {
|
||||
|
@ -74,7 +74,7 @@ class Parser
|
|||
unset($currentHeader);
|
||||
}
|
||||
if ($inHeader) {
|
||||
if ($line == '') {
|
||||
if (trim($line) == '') {
|
||||
$inHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class Parser
|
|||
}
|
||||
} else {
|
||||
if ($hitFirstBoundary === false) {
|
||||
if ($line != '') {
|
||||
if (trim($line) != '') {
|
||||
$inHeader = true;
|
||||
$currentHeader = $line;
|
||||
continue;
|
||||
|
@ -120,7 +120,6 @@ class Parser
|
|||
$content .= $line . "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $multipart;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace BeSimple\SoapCommon;
|
||||
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
|
||||
use BeSimple\SoapCommon\SoapRequest;
|
||||
use BeSimple\SoapCommon\SoapResponse;
|
||||
|
||||
|
@ -28,6 +30,13 @@ use BeSimple\SoapCommon\SoapResponseFilter;
|
|||
*/
|
||||
class SoapKernel
|
||||
{
|
||||
/**
|
||||
* Mime attachments.
|
||||
*
|
||||
* @var array(\BeSimple\SoapCommon\Mime\Part)
|
||||
*/
|
||||
protected $attachments = array();
|
||||
|
||||
/**
|
||||
* Request filters.
|
||||
*
|
||||
|
@ -42,6 +51,39 @@ class SoapKernel
|
|||
*/
|
||||
private $responseFilters = array();
|
||||
|
||||
/**
|
||||
* Add attachment.
|
||||
*
|
||||
* @param \BeSimple\SoapCommon\Mime\Part $attachment New attachment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addAttachment(MimePart $attachment)
|
||||
{
|
||||
$contentId = trim($part->getHeader('Content-ID'), '<>');
|
||||
|
||||
$this->attachments[$contentId] = $attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachment and remove from array.
|
||||
*
|
||||
* @param string $contentId Content ID of attachment
|
||||
*
|
||||
* @return \BeSimple\SoapCommon\Mime\Part|null
|
||||
*/
|
||||
public function getAttachment($contentId)
|
||||
{
|
||||
if (isset($this->attachments[$contentId])) {
|
||||
$part = $this->attachments[$contentId];
|
||||
unset($this->attachments[$contentId]);
|
||||
|
||||
return $part;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given object either as filter for SoapRequests or as filter for SoapResponses
|
||||
* or as filter for both depending on the implemented interfaces. Inner filters have to be registered
|
||||
|
@ -70,6 +112,9 @@ class SoapKernel
|
|||
*/
|
||||
public function filterRequest(SoapRequest $request)
|
||||
{
|
||||
$request->setAttachments($this->attachments);
|
||||
$this->attachments = array();
|
||||
|
||||
foreach ($this->requestFilters as $filter) {
|
||||
$filter->filterRequest($request);
|
||||
}
|
||||
|
@ -85,5 +130,7 @@ class SoapKernel
|
|||
foreach ($this->responseFilters as $filter) {
|
||||
$filter->filterResponse($response);
|
||||
}
|
||||
|
||||
$this->attachments = $response->getAttachments();
|
||||
}
|
||||
}
|
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace BeSimple\SoapCommon;
|
||||
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
|
||||
/**
|
||||
* Base class for SoapRequest and SoapResponse.
|
||||
*
|
||||
|
@ -52,6 +54,13 @@ abstract class SoapMessage
|
|||
*/
|
||||
protected $action;
|
||||
|
||||
/**
|
||||
* Mime attachments.
|
||||
*
|
||||
* @var array(\BeSimple\SoapCommon\Mime\Part)
|
||||
*/
|
||||
protected $attachments = array();
|
||||
|
||||
/**
|
||||
* Message content (MIME Message or SOAP Envelope).
|
||||
*
|
||||
|
@ -124,6 +133,26 @@ abstract class SoapMessage
|
|||
$this->action = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get attachments.
|
||||
*
|
||||
* @return array(\BeSimple\SoapCommon\Mime\Part)
|
||||
*/
|
||||
public function getAttachments()
|
||||
{
|
||||
return $this->attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set SOAP action.
|
||||
*
|
||||
* @param array(\BeSimple\SoapCommon\Mime\Part) $attachments Attachment array
|
||||
*/
|
||||
public function setAttachments(array $attachments)
|
||||
{
|
||||
$this->attachments = $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get message content (MIME Message or SOAP Envelope).
|
||||
*
|
||||
|
|
|
@ -52,7 +52,7 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
|||
$p2 = $mp->getPart('0x9d6ad00-0xa19ef48-0x9de7500-0xa4fae78-0xa382698');
|
||||
$this->assertEquals('binary', $p2->getHeader('Content-Transfer-Encoding'));
|
||||
$this->assertEquals('application/binary', $p2->getHeader('Content-Type'));
|
||||
$this->assertEquals(81, strlen($p2->getContent()));
|
||||
$this->assertEquals(79, strlen($p2->getContent()));
|
||||
}
|
||||
|
||||
public function testParserResponseAxis()
|
||||
|
|
Loading…
Reference in New Issue