Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

if (!defined('SOAP_LITERAL_WRAPPED')) {
define('SOAP_LITERAL_WRAPPED', 3);
}
/**
* BeSimpleSoapExtension.
*
Expand All @@ -35,6 +38,15 @@ class BeSimpleSoapExtension extends Extension
'rpc-literal' => 'rpcliteral',
'document-wrapped' => 'documentwrapped',
);
private $styleMap = [
'rpc' => \SOAP_RPC,
'document' => \SOAP_DOCUMENT,
];
private $useMap = [
'encoded' => \SOAP_ENCODED,
'literal' => \SOAP_LITERAL,
'wrapped' => \SOAP_LITERAL_WRAPPED,
];

public function load(array $configs, ContainerBuilder $container)
{
Expand Down Expand Up @@ -152,7 +164,10 @@ private function createClient($client, ContainerBuilder $container)

private function createWebServiceContext(array $config, ContainerBuilder $container)
{
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
$bindingSuffix = $this->bindingConfigToServiceSuffixMap[$config['binding']];
list($style, $use) = explode('-', $config['binding']);
$config['style'] = $this->styleMap[$style];
$config['use'] = $this->useMap[$use];
unset($config['binding']);

$contextId = 'besimple.soap.context.'.$config['name'];
Expand Down
11 changes: 9 additions & 2 deletions src/BeSimple/SoapBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ private function addServicesSection(ArrayNodeDefinition $rootNode)
->scalarNode('binding')
->defaultValue('document-wrapped')
->validate()
->ifNotInArray(array('rpc-literal', 'document-wrapped'))
->thenInvalid("Service binding style has to be either 'rpc-literal' or 'document-wrapped'")
->ifNotInArray([ 'rpc-literal', 'document-wrapped' /*, 'rpc-encoded', , 'document-literal'*/ ])
->thenInvalid("Service binding style has to be either 'rpc-literal' or 'document-wrapped'!"/* or 'rpc-encoded' or 'document-literal' */)
->end()
->end()
->scalarNode('version')
->defaultValue(2)
->validate()
->ifNotInArray([ 1, 2 ])
->thenInvalid("Service protocol version has to be either 1 or 2")
->end()
->end()
->scalarNode('cache_type')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace BeSimple\SoapBundle\ServiceBinding;

use BeSimple\SoapBundle\ServiceDefinition\Method;
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
/**
* Description of DocumentLiteralWrappedRequestHeaderBinder
*
* @author Michal Mičko <michal.micko@mediaaction.cz>
*/
class DocumentLiteralWrappedRequestHeaderMessageBinder extends DocumentLiteralWrappedRequestMessageBinder
{
private $header;

public function setHeader($header)
{
$this->header = $header;
}

public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
{
$this->typeRepository = $typeRepository;
$headerDefinition = $messageDefinition->getHeaders()->get($this->header);

return $this->processType($headerDefinition->getType(), $message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,108 @@
namespace BeSimple\SoapBundle\ServiceBinding;

use BeSimple\SoapBundle\ServiceDefinition\Method;
use BeSimple\SoapCommon\Definition\Type\ArrayOfType;
use BeSimple\SoapCommon\Definition\Type\ComplexType;
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
use BeSimple\SoapCommon\Util\MessageBinder;

/**
* @author Christian Kerl <christian-kerl@web.de>
*/
class DocumentLiteralWrappedRequestMessageBinder implements MessageBinderInterface
{
public function processMessage(Method $messageDefinition, $message)
protected $typeRepository;

public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
{
$this->typeRepository = $typeRepository;

if(count($message) > 1) {
throw new \InvalidArgumentException();
}

$result = array();
$message = $message[0];

foreach($messageDefinition->getArguments() as $argument) {
$result[$argument->getName()] = $message->{$argument->getName()};
foreach($messageDefinition->getInput()->all() as $argument) {
$result[$argument->getName()] = $this->processType($argument->getType(), $message->{$argument->getName()});
}

return $result;
}

protected function processType($phpType, $message)
{
$isArray = false;

$type = $this->typeRepository->getType($phpType);
if ($type instanceof ArrayOfType) {
$isArray = true;
$array = array();

$type = $this->typeRepository->getType($type->get('item')->getType());
}

// @TODO Fix array reference
if ($type instanceof ComplexType) {
$phpType = $type->getPhpType();

if ($isArray) {
if (isset($message->item)) {
foreach ($message->item as $complexType) {
$array[] = $this->checkComplexType($phpType, $complexType);
}

// See https://github.com/BeSimple/BeSimpleSoapBundle/issues/29
if (in_array('BeSimple\SoapCommon\Type\AbstractKeyValue', class_parents($phpType))) {
$assocArray = array();
foreach ($array as $keyValue) {
$assocArray[$keyValue->getKey()] = $keyValue->getValue();
}

$array = $assocArray;
}
}

$message = $array;
} else {
$message = $this->checkComplexType($phpType, $message);
}
} elseif ($isArray) {
if (isset($message->item)) {
$message = $message->item;
} else {
$message = $array;
}
}

return $message;
}

protected function checkComplexType($phpType, $message)
{
$hash = spl_object_hash($message);
if (isset($this->messageRefs[$hash])) {
return $this->messageRefs[$hash];
}

$this->messageRefs[$hash] = $message;

$messageBinder = new MessageBinder($message);
foreach ($this->typeRepository->getType($phpType)->all() as $type) {
$property = $type->getName();
$value = $messageBinder->readProperty($property);

if (null !== $value) {
$value = $this->processType($type->getType(), $value);

$messageBinder->writeProperty($property, $value);
} elseif (!$type->isNillable()) {
// @TODO use xmlType instead of phpType
throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName()));
}
}

return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,100 @@
namespace BeSimple\SoapBundle\ServiceBinding;

use BeSimple\SoapBundle\ServiceDefinition\Method;
use BeSimple\SoapCommon\Definition\Type\ArrayOfType;
use BeSimple\SoapCommon\Definition\Type\ComplexType;
use BeSimple\SoapCommon\Definition\Type\TypeRepository;
use BeSimple\SoapCommon\Util\MessageBinder;

/**
* @author Christian Kerl <christian-kerl@web.de>
*/
class DocumentLiteralWrappedResponseMessageBinder implements MessageBinderInterface
{
public function processMessage(Method $messageDefinition, $message)
public function processMessage(Method $messageDefinition, $message, TypeRepository $typeRepository)
{
$this->typeRepository = $typeRepository;

$result = new \stdClass();
$result->{$messageDefinition->getName().'Result'} = $message;
//$result->{$messageDefinition->getName().'Result'} = $message;
foreach ($messageDefinition->getOutput()->all() as $name => $part) {
//$result->{$name} = $message;
$result->{$name} = $this->processType($part->getType(), $message);
break; // only one iteration
}

return $result;
}

private function processType($phpType, $message)
{
$isArray = false;

$type = $this->typeRepository->getType($phpType);
if ($type instanceof ArrayOfType) {
$isArray = true;

$type = $this->typeRepository->getType($type->get('item')->getType());
}

if ($type instanceof ComplexType) {
$phpType = $type->getPhpType();

if ($isArray) {
$array = array();

// See https://github.com/BeSimple/BeSimpleSoapBundle/issues/29
if (is_array($message) && in_array('BeSimple\SoapCommon\Type\AbstractKeyValue', class_parents($phpType))) {
$keyValue = array();
foreach ($message as $key => $value) {
$keyValue[] = new $phpType($key, $value);
}

$message = $keyValue;
}

foreach ($message as $complexType) {
$array[] = $this->checkComplexType($phpType, $complexType);
}

$message = $array;
} else {
$message = $this->checkComplexType($phpType, $message);
}
}

return $message;
}

private function checkComplexType($phpType, $message)
{
$hash = spl_object_hash($message);
if (isset($this->messageRefs[$hash])) {
return $this->messageRefs[$hash];
}

$this->messageRefs[$hash] = $message;

if (!$message instanceof $phpType) {
throw new \InvalidArgumentException(sprintf('The instance class must be "%s", "%s" given.', $phpType, get_class($message)));
}

$messageBinder = new MessageBinder($message);
foreach ($this->typeRepository->getType($phpType)->all() as $type) {
$property = $type->getName();
$value = $messageBinder->readProperty($property);

if (null !== $value) {
$value = $this->processType($type->getType(), $value);

$messageBinder->writeProperty($property, $value);
}

if (!$type->isNillable() && null === $value) {
throw new \InvalidArgumentException(sprintf('"%s::%s" cannot be null.', $phpType, $type->getName()));
}
}

return $message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public function processMessage(Method $messageDefinition, $message, TypeReposito
{
$this->typeRepository = $typeRepository;

return $this->processType($messageDefinition->getOutput()->get('return')->getType(), $message);
//return $this->processType($messageDefinition->getOutput()->get('return')->getType(), $message);
return $this->processType(current($messageDefinition->getOutput()->all())->getType(), $message);
}

private function processType($phpType, $message)
Expand Down
11 changes: 11 additions & 0 deletions src/BeSimple/SoapBundle/ServiceDefinition/Annotation/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Param extends Configuration implements TypedElementInterface
private $value;
private $phpType;
private $xmlType;
private $isNillable = false;

public function getValue()
{
Expand All @@ -34,6 +35,11 @@ public function getXmlType()
return $this->xmlType;
}

public function isNillable()
{
return $this->isNillable;
}

public function setValue($value)
{
$this->value = $value;
Expand All @@ -49,6 +55,11 @@ public function setXmlType($xmlType)
$this->xmlType = $xmlType;
}

public function setNillable($isNillable)
{
$this->isNillable = (bool) $isNillable;
}

public function getAliasName()
{
return 'param';
Expand Down
11 changes: 11 additions & 0 deletions src/BeSimple/SoapBundle/ServiceDefinition/Annotation/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
*/
class Result extends Configuration implements TypedElementInterface
{
private $value = 'return';
private $phpType;
private $xmlType;

public function getValue()
{
return $this->value;
}

public function getPhpType()
{
return $this->phpType;
Expand All @@ -28,6 +34,11 @@ public function getXmlType()
return $this->xmlType;
}

public function setValue($value)
{
$this->value = $value;
}

public function setPhpType($phpType)
{
$this->phpType = $phpType;
Expand Down
Loading