Add 'src/BeSimple/SoapBundle/' from commit 'e99f707b105c0a0472260d8d42a5a14a7fb7a211'
git-subtree-dir: src/BeSimple/SoapBundle git-subtree-mainline:9a8d23fa23
git-subtree-split:e99f707b10
This commit is contained in:
40
src/BeSimple/SoapBundle/Soap/SoapAttachment.php
Normal file
40
src/BeSimple/SoapBundle/Soap/SoapAttachment.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
class SoapAttachment
|
||||
{
|
||||
private $id;
|
||||
private $type;
|
||||
private $content;
|
||||
|
||||
public function __construct($id, $type, $content)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
}
|
77
src/BeSimple/SoapBundle/Soap/SoapClientBuilder.php
Normal file
77
src/BeSimple/SoapBundle/Soap/SoapClientBuilder.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
use BeSimple\SoapCommon\Classmap;
|
||||
use BeSimple\SoapCommon\Converter\TypeConverterCollection;
|
||||
use BeSimple\SoapClient\SoapClientBuilder as BaseSoapClientBuilder;
|
||||
|
||||
class SoapClientBuilder extends BaseSoapClientBuilder
|
||||
{
|
||||
protected $soapClient;
|
||||
|
||||
public function __construct($wsdl, array $options, Classmap $classmap = null, TypeConverterCollection $converters = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->checkOptions($options);
|
||||
|
||||
$this
|
||||
->withWsdl($wsdl)
|
||||
->withTrace($options['debug'])
|
||||
;
|
||||
|
||||
if (isset($options['user_agent'])) {
|
||||
$this->withUserAgent($options['user_agent']);
|
||||
}
|
||||
|
||||
if (isset($options['cache_type'])) {
|
||||
$this->withWsdlCache($options['cache_type']);
|
||||
}
|
||||
|
||||
if ($classmap) {
|
||||
$this->withClassmap($classmap);
|
||||
}
|
||||
|
||||
if ($converters) {
|
||||
$this->withTypeConverters($converters);
|
||||
}
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
if (!$this->soapClient) {
|
||||
$this->soapClient = parent::build();
|
||||
}
|
||||
|
||||
return $this->soapClient;
|
||||
}
|
||||
|
||||
protected function checkOptions(array $options)
|
||||
{
|
||||
$checkOptions = array(
|
||||
'debug' => false,
|
||||
'cache_type' => null,
|
||||
'exceptions' => true,
|
||||
'user_agent' => 'BeSimpleSoap',
|
||||
);
|
||||
|
||||
// check option names and live merge, if errors are encountered Exception will be thrown
|
||||
$invalid = array();
|
||||
$isInvalid = false;
|
||||
foreach ($options as $key => $value) {
|
||||
if (!array_key_exists($key, $checkOptions)) {
|
||||
$isInvalid = true;
|
||||
$invalid[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isInvalid) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The "%s" class does not support the following options: "%s".',
|
||||
get_class($this),
|
||||
implode('\', \'', $invalid)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
50
src/BeSimple/SoapBundle/Soap/SoapHeader.php
Normal file
50
src/BeSimple/SoapBundle/Soap/SoapHeader.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
class SoapHeader
|
||||
{
|
||||
private $namespace;
|
||||
private $name;
|
||||
private $data;
|
||||
|
||||
public function __construct($namespace, $name, $data)
|
||||
{
|
||||
$this->namespace = $namespace;
|
||||
$this->name = $name;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->namespace;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function toNativeSoapHeader()
|
||||
{
|
||||
return new \SoapHeader($this->namespace, $this->name, $this->data);
|
||||
}
|
||||
}
|
167
src/BeSimple/SoapBundle/Soap/SoapRequest.php
Normal file
167
src/BeSimple/SoapBundle/Soap/SoapRequest.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
use BeSimple\SoapBundle\Util\Collection;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use Zend\Mime\Mime;
|
||||
use Zend\Mime\Message;
|
||||
|
||||
/**
|
||||
* SoapRequest.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class SoapRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $soapMessage;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $soapAction;
|
||||
|
||||
/**
|
||||
* @var \BeSimple\SoapBundle\Util\Collection
|
||||
*/
|
||||
protected $soapHeaders;
|
||||
|
||||
/**
|
||||
* @var \BeSimple\SoapBundle\Util\Collection
|
||||
*/
|
||||
protected $soapAttachments;
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
*
|
||||
* @return SoapRequest
|
||||
*/
|
||||
public static function createFromHttpRequest(Request $request)
|
||||
{
|
||||
return new static($request->query->all(), $request->request->all(), $request->attributes->all(), $request->cookies->all(), $request->files->all(), $request->server->all(), $request->content);
|
||||
}
|
||||
|
||||
public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
|
||||
{
|
||||
parent::initialize($query, $request, $attributes, $cookies, $files, $server, $content);
|
||||
|
||||
$this->soapMessage = null;
|
||||
$this->soapHeaders = new Collection('getName', 'BeSimple\SoapBundle\Soap\SoapHeader');
|
||||
$this->soapAttachments = new Collection('getId', 'BeSimple\SoapBundle\Soap\SoapAttachment');
|
||||
|
||||
$this->setRequestFormat('soap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the XML string of the SOAP message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSoapMessage()
|
||||
{
|
||||
if(null === $this->soapMessage) {
|
||||
$this->soapMessage = $this->initializeSoapMessage();
|
||||
}
|
||||
|
||||
return $this->soapMessage;
|
||||
}
|
||||
|
||||
public function getSoapHeaders()
|
||||
{
|
||||
return $this->soapHeaders;
|
||||
}
|
||||
|
||||
public function getSoapAttachments()
|
||||
{
|
||||
return $this->soapAttachments;
|
||||
}
|
||||
|
||||
protected function initializeSoapMessage()
|
||||
{
|
||||
if($this->server->has('CONTENT_TYPE')) {
|
||||
$type = $this->splitContentTypeHeader($this->server->get('CONTENT_TYPE'));
|
||||
|
||||
switch($type['_type']) {
|
||||
case 'multipart/related':
|
||||
if($type['type'] == 'application/xop+xml') {
|
||||
return $this->initializeMtomSoapMessage($type, $this->getContent());
|
||||
} else {
|
||||
//log error
|
||||
}
|
||||
break;
|
||||
case 'application/soap+xml':
|
||||
// goto fallback
|
||||
break;
|
||||
default:
|
||||
// log error
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// fallback
|
||||
return $this->getContent();
|
||||
}
|
||||
|
||||
protected function initializeMtomSoapMessage(array $contentTypeHeader, $content)
|
||||
{
|
||||
if(!isset($contentTypeHeader['start']) || !isset($contentTypeHeader['start-info']) || !isset($contentTypeHeader['boundary'])) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$mimeMessage = Message::createFromMessage($content, $contentTypeHeader['boundary']);
|
||||
$mimeParts = $mimeMessage->getParts();
|
||||
|
||||
$soapMimePartId = trim($contentTypeHeader['start'], '<>');
|
||||
$soapMimePartType = $contentTypeHeader['start-info'];
|
||||
|
||||
$rootPart = array_shift($mimeParts);
|
||||
$rootPartType = $this->splitContentTypeHeader($rootPart->type);
|
||||
|
||||
// TODO: add more checks to achieve full compatibility to MTOM spec
|
||||
// http://www.w3.org/TR/soap12-mtom/
|
||||
if($rootPart->id != $soapMimePartId || $rootPartType['_type'] != 'application/xop+xml' || $rootPartType['type'] != $soapMimePartType) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
foreach($mimeParts as $mimePart) {
|
||||
$this->soapAttachments->add(new SoapAttachment(
|
||||
$mimePart->id,
|
||||
$mimePart->type,
|
||||
// handle content decoding / prevent encoding
|
||||
$mimePart->getContent()
|
||||
));
|
||||
}
|
||||
|
||||
// handle content decoding / prevent encoding
|
||||
return $rootPart->getContent();
|
||||
}
|
||||
|
||||
protected function splitContentTypeHeader($header)
|
||||
{
|
||||
$result = array();
|
||||
$parts = explode(';', strtolower($header));
|
||||
|
||||
$result['_type'] = array_shift($parts);
|
||||
|
||||
foreach($parts as $part) {
|
||||
list($key, $value) = explode('=', trim($part), 2);
|
||||
|
||||
$result[$key] = trim($value, '"');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
69
src/BeSimple/SoapBundle/Soap/SoapResponse.php
Normal file
69
src/BeSimple/SoapBundle/Soap/SoapResponse.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\Soap;
|
||||
|
||||
use BeSimple\SoapBundle\Util\Collection;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* SoapResponse.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
class SoapResponse extends Response
|
||||
{
|
||||
/**
|
||||
* @var \BeSimple\SoapBundle\Util\Collection
|
||||
*/
|
||||
protected $soapHeaders;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $soapReturnValue;
|
||||
|
||||
public function __construct($returnValue = null)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->soapHeaders = new Collection('getName', 'BeSimple\SoapBundle\Soap\SoapHeader');
|
||||
$this->setReturnValue($returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SoapHeader $soapHeader
|
||||
*/
|
||||
public function addSoapHeader(SoapHeader $soapHeader)
|
||||
{
|
||||
$this->soapHeaders->add($soapHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Util\Collection
|
||||
*/
|
||||
public function getSoapHeaders()
|
||||
{
|
||||
return $this->soapHeaders;
|
||||
}
|
||||
|
||||
public function setReturnValue($value)
|
||||
{
|
||||
$this->soapReturnValue = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReturnValue()
|
||||
{
|
||||
return $this->soapReturnValue;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user