Merge remote-tracking branch 'origin/request_headers'
This commit is contained in:
commit
51a36dfb87
@ -43,6 +43,11 @@ class SoapWebServiceController extends ContainerAware
|
||||
*/
|
||||
protected $serviceBinder;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $headers = array();
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Soap\SoapResponse
|
||||
*/
|
||||
@ -96,12 +101,15 @@ class SoapWebServiceController extends ContainerAware
|
||||
*/
|
||||
public function __call($method, $arguments)
|
||||
{
|
||||
if ($this->serviceBinder->isServiceHeader($method)) {
|
||||
// collect request soap headers
|
||||
$this->soapRequest->getSoapHeaders()->add(
|
||||
$this->serviceBinder->processServiceHeader($method, $arguments[0])
|
||||
);
|
||||
} elseif ($this->serviceBinder->isServiceMethod($method)) {
|
||||
if ($this->serviceBinder->isServiceMethod($method)) {
|
||||
// @TODO Add all SoapHeaders in SoapRequest
|
||||
foreach ($this->headers as $name => $value) {
|
||||
if ($this->serviceBinder->isServiceHeader($method, $name)) {
|
||||
$this->soapRequest->getSoapHeaders()->add($this->serviceBinder->processServiceHeader($method, $name, $value));
|
||||
}
|
||||
}
|
||||
$this->headers = null;
|
||||
|
||||
$this->soapRequest->attributes->add(
|
||||
$this->serviceBinder->processServiceMethodArguments($method, $arguments)
|
||||
);
|
||||
@ -127,9 +135,28 @@ class SoapWebServiceController extends ContainerAware
|
||||
$method,
|
||||
$this->soapResponse->getReturnValue()
|
||||
);
|
||||
} else {
|
||||
// collect request soap headers
|
||||
$this->headers[$method] = $arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Soap\SoapRequest
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->soapRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Soap\SoapResponse
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->soapResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the given Response is a SoapResponse.
|
||||
*
|
||||
@ -148,28 +175,12 @@ class SoapWebServiceController extends ContainerAware
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Soap\SoapRequest
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->soapRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Soap\SoapResponse
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->soapResponse;
|
||||
}
|
||||
|
||||
private function getWebServiceContext($webservice)
|
||||
{
|
||||
if(!$this->container->has('besimple.soap.context.'.$webservice))
|
||||
{
|
||||
if (!$this->container->has('besimple.soap.context.'.$webservice)) {
|
||||
throw new NotFoundHttpException(sprintf('No webservice with name "%s" found.', $webservice));
|
||||
}
|
||||
|
||||
return $this->container->get('besimple.soap.context.'.$webservice);
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class BeSimpleSoapExtension extends Extension
|
||||
// maps config options to service suffix
|
||||
private $bindingConfigToServiceSuffixMap = array(
|
||||
'rpc-literal' => 'rpcliteral',
|
||||
'document-wrapped' => 'documentwrapped'
|
||||
'document-wrapped' => 'documentwrapped',
|
||||
);
|
||||
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
|
@ -6,9 +6,11 @@
|
||||
<parameters>
|
||||
<parameter key="besimple.soap.context.class">BeSimple\SoapBundle\WebServiceContext</parameter>
|
||||
<parameter key="besimple.soap.cache_dir">%kernel.cache_dir%/webservice</parameter>
|
||||
<parameter key="besimple.soap.binder.request_header.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestHeaderMessageBinder</parameter>
|
||||
<parameter key="besimple.soap.binder.request.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder</parameter>
|
||||
<parameter key="besimple.soap.binder.response.rpcliteral.class">BeSimple\SoapBundle\ServiceBinding\RpcLiteralResponseMessageBinder</parameter>
|
||||
<parameter key="besimple.soap.binder.request.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestMessageBinder</parameter>
|
||||
<parameter key="besimple.soap.binder.request_header.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedRequestHeaderMessageBinder</parameter>
|
||||
<parameter key="besimple.soap.binder.response.documentwrapped.class">BeSimple\SoapBundle\ServiceBinding\DocumentLiteralWrappedResponseMessageBinder</parameter>
|
||||
<parameter key="besimple.soap.definition.dumper.wsdl.rpcliteral.class">BeSimple\SoapBundle\ServiceDefinition\Dumper\WsdlDumper</parameter>
|
||||
<parameter key="besimple.soap.converter.repository.class">BeSimple\SoapBundle\Converter\ConverterRepository</parameter>
|
||||
@ -24,6 +26,7 @@
|
||||
<argument type="collection">
|
||||
<argument key="cache_dir">%besimple.soap.cache_dir%</argument>
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.rpcliteral.class%</argument>
|
||||
<argument key="binder_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
|
||||
<argument key="binder_response_class">%besimple.soap.binder.response.rpcliteral.class%</argument>
|
||||
</argument>
|
||||
@ -37,6 +40,7 @@
|
||||
<argument type="collection">
|
||||
<argument key="cache_dir">%besimple.soap.cache_dir%</argument>
|
||||
<argument key="debug">%kernel.debug%</argument>
|
||||
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.documentwrapped.class%</argument>
|
||||
<argument key="binder_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
|
||||
<argument key="binder_response_class">%besimple.soap.binder.response.documentwrapped.class%</argument>
|
||||
</argument>
|
||||
|
@ -23,5 +23,6 @@ Tutorial
|
||||
|
||||
tutorial/array
|
||||
tutorial/complex_type
|
||||
tutorial/header
|
||||
|
||||
.. _`ckWebServicePlugin`: http://www.symfony-project.org/plugins/ckWebServicePlugin
|
32
Resources/doc/tutorial/header.rst
Normal file
32
Resources/doc/tutorial/header.rst
Normal file
@ -0,0 +1,32 @@
|
||||
Header
|
||||
======
|
||||
|
||||
Controller
|
||||
----------
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace My\App\Controller;
|
||||
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
|
||||
class DemoController extends ContainerAware
|
||||
{
|
||||
/**
|
||||
* @Soap\Method("hello")
|
||||
* @Soap\Header("api_key", phpType = "string")
|
||||
* @Soap\Param("names", phpType = "string[]")
|
||||
* @Soap\Result(phpType = "string")
|
||||
*/
|
||||
public function helloAction(array $names)
|
||||
{
|
||||
$soapHeaders = $this->container->get('request')->getSoapHeaders();
|
||||
if (!$soapHeaders->has('api_key') || '1234' !== $soapHeaders->get('api_key')->getData()) {
|
||||
throw new \SoapFault("INVALID_API_KEY", "The api_key is invalid.");
|
||||
}
|
||||
|
||||
return new SoapResponse("Hello ".implode(', ', $names));
|
||||
}
|
||||
}
|
33
ServiceBinding/RpcLiteralRequestHeaderMessageBinder.php
Normal file
33
ServiceBinding/RpcLiteralRequestHeaderMessageBinder.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?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\ServiceBinding;
|
||||
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class RpcLiteralRequestHeaderMessageBinder extends RpcLiteralRequestMessageBinder
|
||||
{
|
||||
private $header;
|
||||
|
||||
public function setHeader($header)
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
public function processMessage(Method $messageDefinition, $message, array $definitionComplexTypes = array())
|
||||
{
|
||||
$headerDefinition = $messageDefinition->getHeaders()->get($this->header);
|
||||
|
||||
return $this->processType($headerDefinition->getType()->getPhpType(), $message, $definitionComplexTypes);
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function processType($phpType, $message, array $definitionComplexTypes)
|
||||
protected function processType($phpType, $message, array $definitionComplexTypes)
|
||||
{
|
||||
if (preg_match('/^([^\[]+)\[\]$/', $phpType, $match)) {
|
||||
$isArray = true;
|
||||
@ -80,11 +80,15 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
||||
foreach ($definitionComplexTypes[$phpType] as $type) {
|
||||
$value = $this->processType($type->getValue(), $message->{$type->getName()}, $definitionComplexTypes);
|
||||
|
||||
if (null === $value && $type->isNillable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($type instanceof PropertyComplexType) {
|
||||
$instanceType->{$type->getOriginalName()} = $value;
|
||||
} elseif ($type instanceof MethodComplexType) {
|
||||
if (!$type->getSetter()) {
|
||||
throw new \LogicException();
|
||||
throw new \LogicException(sprintf('"setter" option must be specified to hydrate "%s::%s()"', $phpType, $type->getOriginalName()));
|
||||
}
|
||||
|
||||
$instanceType->{$type->getSetter()}($value);
|
||||
|
@ -25,6 +25,11 @@ class ServiceBinder
|
||||
*/
|
||||
private $definition;
|
||||
|
||||
/**
|
||||
* @var \BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface
|
||||
*/
|
||||
private $requestHeaderMessageBinder;
|
||||
|
||||
/**
|
||||
* @var \BeSimple\SoapBundle\ServiceBinding\MessageBinderInterface
|
||||
*/
|
||||
@ -35,32 +40,39 @@ class ServiceBinder
|
||||
*/
|
||||
private $responseMessageBinder;
|
||||
|
||||
public function __construct(ServiceDefinition $definition, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder) {
|
||||
$this->definition = $definition;
|
||||
$this->requestMessageBinder = $requestMessageBinder;
|
||||
public function __construct(ServiceDefinition $definition, MessageBinderInterface $requestHeaderMessageBinder, MessageBinderInterface $requestMessageBinder, MessageBinderInterface $responseMessageBinder) {
|
||||
$this->definition = $definition;
|
||||
|
||||
$this->requestHeaderMessageBinder = $requestHeaderMessageBinder;
|
||||
$this->requestMessageBinder = $requestMessageBinder;
|
||||
|
||||
$this->responseMessageBinder = $responseMessageBinder;
|
||||
}
|
||||
|
||||
public function isServiceHeader($name)
|
||||
public function isServiceHeader($method, $header)
|
||||
{
|
||||
return $this->definition->getHeaders()->has($name);
|
||||
return $this->definition->getMethods()->get($method)->getHeaders()->has($header);
|
||||
}
|
||||
|
||||
public function isServiceMethod($name)
|
||||
public function isServiceMethod($method)
|
||||
{
|
||||
return $this->definition->getMethods()->has($name);
|
||||
return $this->definition->getMethods()->has($method);
|
||||
}
|
||||
|
||||
public function processServiceHeader($name, $data)
|
||||
public function processServiceHeader($method, $header, $data)
|
||||
{
|
||||
$headerDefinition = $this->definition->getHeaders()->get($name);
|
||||
$methodDefinition = $this->definition->getMethods()->get($method);
|
||||
$headerDefinition = $methodDefinition->getHeaders()->get($header);
|
||||
|
||||
$this->requestHeaderMessageBinder->setHeader($header);
|
||||
$data = $this->requestHeaderMessageBinder->processMessage($methodDefinition, $data, $this->definition->getDefinitionComplexTypes());
|
||||
|
||||
return $this->createSoapHeader($headerDefinition, $data);
|
||||
}
|
||||
|
||||
public function processServiceMethodArguments($name, $arguments)
|
||||
public function processServiceMethodArguments($method, $arguments)
|
||||
{
|
||||
$methodDefinition = $this->definition->getMethods()->get($name);
|
||||
$methodDefinition = $this->definition->getMethods()->get($method);
|
||||
|
||||
return array_merge(
|
||||
array('_controller' => $methodDefinition->getController()),
|
||||
@ -79,6 +91,6 @@ class ServiceBinder
|
||||
{
|
||||
$qname = QName::fromPackedQName($headerDefinition->getType()->getXmlType());
|
||||
|
||||
return new SoapHeader($qname->getNamespace(), $qname->getName(), $data);
|
||||
return new SoapHeader($qname->getNamespace(), $headerDefinition->getName(), $data);
|
||||
}
|
||||
}
|
22
ServiceDefinition/Annotation/Header.php
Normal file
22
ServiceDefinition/Annotation/Header.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?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\ServiceDefinition\Annotation;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
class Header extends Param
|
||||
{
|
||||
public function getAliasName()
|
||||
{
|
||||
return 'header';
|
||||
}
|
||||
}
|
37
ServiceDefinition/Dumper/Wsdl.php
Normal file
37
ServiceDefinition/Dumper/Wsdl.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?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\ServiceDefinition\Dumper;
|
||||
|
||||
use Zend\Soap\Wsdl as BaseWsdl;
|
||||
|
||||
/**
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class Wsdl extends BaseWsdl
|
||||
{
|
||||
public function addBindingOperationHeader(\DOMElement $bindingOperation, array $headers, array $baseBinding)
|
||||
{
|
||||
foreach ($headers as $header) {
|
||||
$inputNode = $bindingOperation->getElementsByTagName('input')->item(0);
|
||||
|
||||
$headerNode = $this->toDomDocument()->createElement('soap:header');
|
||||
$headerNode->setAttribute('part', $header);
|
||||
|
||||
foreach ($baseBinding as $name => $value) {
|
||||
$headerNode->setAttribute($name, $value);
|
||||
}
|
||||
|
||||
$inputNode->appendChild($headerNode);
|
||||
}
|
||||
|
||||
return $bindingOperation;
|
||||
}
|
||||
}
|
@ -17,8 +17,6 @@ use BeSimple\SoapBundle\ServiceDefinition\Loader\AnnotationComplexTypeLoader;
|
||||
use BeSimple\SoapBundle\Util\Assert;
|
||||
use BeSimple\SoapBundle\Util\QName;
|
||||
|
||||
use Zend\Soap\Wsdl;
|
||||
|
||||
/**
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
@ -49,8 +47,13 @@ class WsdlDumper implements DumperInterface
|
||||
$this->wsdl->addService($this->getServiceName(), $this->getPortName(), $this->qualify($this->getBindingName()), $endpoint);
|
||||
|
||||
foreach ($definition->getMethods() as $method) {
|
||||
$requestParts = array();
|
||||
$responseParts = array();
|
||||
$requestHeaderParts =
|
||||
$requestParts =
|
||||
$responseParts = array();
|
||||
|
||||
foreach ($method->getHeaders() as $header) {
|
||||
$requestHeaderParts[$header->getName()] = $this->wsdl->getType($header->getType()->getPhpType());
|
||||
}
|
||||
|
||||
foreach ($method->getArguments() as $argument) {
|
||||
$requestParts[$argument->getName()] = $this->wsdl->getType($argument->getType()->getPhpType());
|
||||
@ -60,26 +63,38 @@ class WsdlDumper implements DumperInterface
|
||||
$responseParts['return'] = $this->wsdl->getType($method->getReturn()->getPhpType());
|
||||
}
|
||||
|
||||
if (!empty($requestHeaderParts)) {
|
||||
$this->wsdl->addMessage($this->getRequestHeaderMessageName($method), $requestHeaderParts);
|
||||
}
|
||||
$this->wsdl->addMessage($this->getRequestMessageName($method), $requestParts);
|
||||
$this->wsdl->addMessage($this->getResponseMessageName($method), $responseParts);
|
||||
|
||||
$portOperation = $this->wsdl->addPortOperation($port, $method->getName(), $this->qualify($this->getRequestMessageName($method)), $this->qualify($this->getResponseMessageName($method)));
|
||||
$portOperation = $this->wsdl->addPortOperation(
|
||||
$port,
|
||||
$method->getName(),
|
||||
$this->qualify($this->getRequestMessageName($method)),
|
||||
$this->qualify($this->getResponseMessageName($method))
|
||||
);
|
||||
$portOperation->setAttribute('parameterOrder', implode(' ', array_keys($requestParts)));
|
||||
|
||||
$bindingInput = array(
|
||||
'parts' => implode(' ', array_keys($requestParts)),
|
||||
'use' => 'literal',
|
||||
'namespace' => $definition->getNamespace(),
|
||||
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
|
||||
);
|
||||
$bindingOutput = array(
|
||||
'parts' => implode(' ', array_keys($responseParts)),
|
||||
$baseBinding = array(
|
||||
'use' => 'literal',
|
||||
'namespace' => $definition->getNamespace(),
|
||||
'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/',
|
||||
);
|
||||
|
||||
$bindingOperation = $this->wsdl->addBindingOperation($binding, $method->getName(), $bindingInput, $bindingOutput);
|
||||
$bindingOperation = $this->wsdl->addBindingOperation(
|
||||
$binding,
|
||||
$method->getName(),
|
||||
array_merge(array('parts' => implode(' ', array_keys($requestParts))), $baseBinding),
|
||||
array_merge(array('parts' => implode(' ', array_keys($responseParts))), $baseBinding)
|
||||
);
|
||||
$bindingOperation = $this->wsdl->addBindingOperationHeader(
|
||||
$bindingOperation,
|
||||
array_keys($requestHeaderParts),
|
||||
array_merge(array('message' => $this->qualify($this->getRequestHeaderMessageName($method))), $baseBinding)
|
||||
);
|
||||
|
||||
$this->wsdl->addSoapOperation($bindingOperation, $this->getSoapOperationName($method));
|
||||
}
|
||||
|
||||
@ -126,6 +141,11 @@ class WsdlDumper implements DumperInterface
|
||||
return $this->definition->getName().'Service';
|
||||
}
|
||||
|
||||
protected function getRequestHeaderMessageName(Method $method)
|
||||
{
|
||||
return $method->getName().'Header';
|
||||
}
|
||||
|
||||
protected function getRequestMessageName(Method $method)
|
||||
{
|
||||
return $method->getName().'Request';
|
||||
|
@ -16,7 +16,7 @@ use BeSimple\SoapBundle\ServiceDefinition\Strategy\ComplexType;
|
||||
use BeSimple\SoapBundle\Util\String;
|
||||
|
||||
use Zend\Soap\Exception;
|
||||
use Zend\Soap\Wsdl;
|
||||
use Zend\Soap\Wsdl as BaseWsdl;
|
||||
use Zend\Soap\Wsdl\Strategy;
|
||||
use Zend\Soap\Wsdl\Strategy\ArrayOfTypeSequence;
|
||||
|
||||
@ -46,7 +46,7 @@ class WsdlTypeStrategy implements Strategy
|
||||
*
|
||||
* @param \Zend\Soap\Wsdl $context
|
||||
*/
|
||||
public function setContext(Wsdl $context)
|
||||
public function setContext(BaseWsdl $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
|
||||
|
@ -10,13 +10,8 @@
|
||||
|
||||
namespace BeSimple\SoapBundle\ServiceDefinition\Loader;
|
||||
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Argument;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Method;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Type;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation\Method as MethodAnnotation;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation\Param as ParamAnnotation;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation\Result as ResultAnnotation;
|
||||
use BeSimple\SoapBundle\ServiceDefinition as Definition;
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation;
|
||||
|
||||
use Doctrine\Common\Annotations\Reader;
|
||||
|
||||
@ -50,7 +45,7 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
* @param string $class A class name
|
||||
* @param string $type The resource type
|
||||
*
|
||||
* @return ServiceDefinition A ServiceDefinition instance
|
||||
* @return \BeSimple\SoapBundle\ServiceDefinition\ServiceDefinition A ServiceDefinition instance
|
||||
*
|
||||
* @throws \InvalidArgumentException When route can't be parsed
|
||||
*/
|
||||
@ -61,48 +56,57 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass($class);
|
||||
$definition = new ServiceDefinition();
|
||||
$definition = new Definition\ServiceDefinition();
|
||||
|
||||
foreach ($class->getMethods() as $method) {
|
||||
$serviceArguments = array();
|
||||
$serviceArguments =
|
||||
$serviceHeaders = array();
|
||||
$serviceMethod =
|
||||
$serviceReturn = null;
|
||||
|
||||
foreach ($this->reader->getMethodAnnotations($method) as $i => $annotation) {
|
||||
if ($annotation instanceof ParamAnnotation) {
|
||||
$serviceArguments[] = new Argument(
|
||||
if ($annotation instanceof Annotation\Header) {
|
||||
$serviceHeaders[] = new Definition\Header(
|
||||
$annotation->getValue(),
|
||||
$this->getArgumentType($method, $annotation)
|
||||
);
|
||||
} elseif ($annotation instanceof MethodAnnotation) {
|
||||
} elseif ($annotation instanceof Annotation\Param) {
|
||||
$serviceArguments[] = new Definition\Argument(
|
||||
$annotation->getValue(),
|
||||
$this->getArgumentType($method, $annotation)
|
||||
);
|
||||
} elseif ($annotation instanceof Annotation\Method) {
|
||||
if ($serviceMethod) {
|
||||
throw new \LogicException(sprintf('@Method defined twice for "%s".', $method->getName()));
|
||||
throw new \LogicException(sprintf('@Soap\Method defined twice for "%s".', $method->getName()));
|
||||
}
|
||||
|
||||
$serviceMethod = new Method(
|
||||
$serviceMethod = new Definition\Method(
|
||||
$annotation->getValue(),
|
||||
$this->getController($method, $annotation)
|
||||
);
|
||||
} elseif ($annotation instanceof ResultAnnotation) {
|
||||
} elseif ($annotation instanceof Annotation\Result) {
|
||||
if ($serviceReturn) {
|
||||
throw new \LogicException(sprintf('@Result defined twice for "%s".', $method->getName()));
|
||||
throw new \LogicException(sprintf('@Soap\Result defined twice for "%s".', $method->getName()));
|
||||
}
|
||||
|
||||
$serviceReturn = new Type($annotation->getPhpType(), $annotation->getXmlType());
|
||||
$serviceReturn = new Definition\Type($annotation->getPhpType(), $annotation->getXmlType());
|
||||
}
|
||||
}
|
||||
|
||||
if (!$serviceMethod && (!empty($serviceArguments) || $serviceReturn)) {
|
||||
throw new \LogicException(sprintf('@Method non-existent for "%s".', $method->getName()));
|
||||
throw new \LogicException(sprintf('@Soap\Method non-existent for "%s".', $method->getName()));
|
||||
}
|
||||
|
||||
if ($serviceMethod) {
|
||||
$serviceMethod->setArguments($serviceArguments);
|
||||
$serviceMethod->setHeaders($serviceHeaders);
|
||||
|
||||
if ($serviceReturn) {
|
||||
$serviceMethod->setReturn($serviceReturn);
|
||||
if (!$serviceReturn) {
|
||||
throw new \LogicException(sprintf('@Soap\Result non-existent for "%s".', $method->getName()));
|
||||
}
|
||||
|
||||
$serviceMethod->setReturn($serviceReturn);
|
||||
|
||||
$definition->getMethods()->add($serviceMethod);
|
||||
}
|
||||
}
|
||||
@ -110,7 +114,13 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
return $definition;
|
||||
}
|
||||
|
||||
private function getController(\ReflectionMethod $method, MethodAnnotation $annotation)
|
||||
/**
|
||||
* @param \ReflectionMethod $method
|
||||
* @param \BeSimple\SoapBundle\ServiceDefinition\Annotation\Method $annotation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getController(\ReflectionMethod $method, Annotation\Method $annotation)
|
||||
{
|
||||
if(null !== $annotation->getService()) {
|
||||
return $annotation->getService() . ':' . $method->name;
|
||||
@ -121,11 +131,11 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $method
|
||||
* @param ParamAnnotation $annotation
|
||||
* @param \BeSimple\SoapBundle\ServiceDefinition\Annotation\Param $annotation
|
||||
*
|
||||
* @return \BeSimple\SoapBundle\ServiceDefinition\Type
|
||||
*/
|
||||
private function getArgumentType(\ReflectionMethod $method, ParamAnnotation $annotation)
|
||||
private function getArgumentType(\ReflectionMethod $method, Annotation\Param $annotation)
|
||||
{
|
||||
$phpType = $annotation->getPhpType();
|
||||
$xmlType = $annotation->getXmlType();
|
||||
@ -140,7 +150,7 @@ class AnnotationClassLoader implements LoaderInterface
|
||||
}
|
||||
}
|
||||
|
||||
return new Type($phpType, $xmlType);
|
||||
return new Definition\Type($phpType, $xmlType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,12 +17,14 @@ class Method
|
||||
private $name;
|
||||
private $controller;
|
||||
private $arguments;
|
||||
private $headers;
|
||||
private $return;
|
||||
|
||||
public function __construct($name = null, $controller = null, array $arguments = array(), Type $return = null)
|
||||
public function __construct($name = null, $controller = null, array $headers = array(), array $arguments = array(), Type $return = null)
|
||||
{
|
||||
$this->setName($name);
|
||||
$this->setController($controller);
|
||||
$this->setHeaders($headers);
|
||||
$this->setArguments($arguments);
|
||||
|
||||
if ($return) {
|
||||
@ -50,6 +52,17 @@ class Method
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
$this->headers = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Header');
|
||||
$this->headers->addAll($headers);
|
||||
}
|
||||
|
||||
public function getArguments()
|
||||
{
|
||||
return $this->arguments;
|
||||
|
@ -29,23 +29,16 @@ class ServiceDefinition
|
||||
*/
|
||||
private $methods;
|
||||
|
||||
/**
|
||||
* @var \BeSimple\SoapBundle\Util\Collection
|
||||
*/
|
||||
private $headers;
|
||||
|
||||
private $complexTypes = array();
|
||||
|
||||
public function __construct($name = null, $namespace = null, array $methods = array(), array $headers = array())
|
||||
public function __construct($name = null, $namespace = null, array $methods = array())
|
||||
{
|
||||
$this->setName($name);
|
||||
$this->setNamespace($namespace);
|
||||
|
||||
$this->methods = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Method');
|
||||
$this->headers = new Collection('getName', 'BeSimple\SoapBundle\ServiceDefinition\Header');
|
||||
|
||||
$this->setMethods($methods);
|
||||
$this->setHeaders($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -96,22 +89,6 @@ class ServiceDefinition
|
||||
$this->methods->addAll($methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \BeSimple\SoapBundle\Util\Collection
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $headers
|
||||
*/
|
||||
public function setHeaders(array $headers)
|
||||
{
|
||||
$this->headers->addAll($headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@ -119,11 +96,15 @@ class ServiceDefinition
|
||||
{
|
||||
$types = array();
|
||||
|
||||
foreach($this->methods as $method) {
|
||||
foreach($method->getArguments() as $argument) {
|
||||
foreach ($this->methods as $method) {
|
||||
foreach ($method->getArguments() as $argument) {
|
||||
$types[] = $argument->getType();
|
||||
}
|
||||
|
||||
foreach ($method->getHeaders() as $header) {
|
||||
$types[] = $header->getType();
|
||||
}
|
||||
|
||||
$types[] = $method->getReturn();
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_argument', null, array(
|
||||
new Method('complextype_argument', null, array(), array(
|
||||
new Argument('attributes', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')),
|
||||
)),
|
||||
array($attributes),
|
||||
@ -67,7 +67,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_argument', null, array(
|
||||
new Method('complextype_argument', null, array(), array(
|
||||
new Argument('attributes', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')),
|
||||
)),
|
||||
array($message),
|
||||
@ -90,7 +90,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_methods', null, array(
|
||||
new Method('complextype_methods', null, array(), array(
|
||||
new Argument('setters', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')),
|
||||
)),
|
||||
array($methods),
|
||||
@ -115,7 +115,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_complextype', null, array(
|
||||
new Method('complextype_complextype', null, array(), array(
|
||||
new Argument('complex_type', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')),
|
||||
)),
|
||||
array($complexType),
|
||||
@ -153,7 +153,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralRequestMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextypes_references', null, array(
|
||||
new Method('complextypes_references', null, array(), array(
|
||||
new Argument('complex_types', new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType[]')),
|
||||
)),
|
||||
array($complexTypes),
|
||||
@ -178,7 +178,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$messages[] = array(
|
||||
new Method('string_argument', null, array(
|
||||
new Method('string_argument', null, array(), array(
|
||||
new Argument('foo', new Type('string')),
|
||||
)),
|
||||
array('bar'),
|
||||
@ -186,7 +186,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$messages[] = array(
|
||||
new Method('string_int_arguments', null, array(
|
||||
new Method('string_int_arguments', null, array(), array(
|
||||
new Argument('foo', new Type('string')),
|
||||
new Argument('bar', new Type('int')),
|
||||
)),
|
||||
@ -197,7 +197,7 @@ class RpcLiteralRequestMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
$strings = new \stdClass();
|
||||
$strings->item = array('foo', 'bar', 'barfoo');
|
||||
$messages[] = array(
|
||||
new Method('array_string_arguments', null, array(
|
||||
new Method('array_string_arguments', null, array(), array(
|
||||
new Argument('foo', new Type('string[]')),
|
||||
new Argument('bar', new Type('int')),
|
||||
)),
|
||||
|
@ -47,7 +47,7 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
$attributes->bar = 20349;
|
||||
$messageBinder = new RpcLiteralResponseMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')),
|
||||
new Method('complextype', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes')),
|
||||
$attributes,
|
||||
$definitionComplexTypes
|
||||
);
|
||||
@ -65,7 +65,7 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
$message = array($attributes1, $attributes2);
|
||||
$messageBinder = new RpcLiteralResponseMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_argument', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')),
|
||||
new Method('complextype_argument', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')),
|
||||
$message,
|
||||
$definitionComplexTypes
|
||||
);
|
||||
@ -89,7 +89,7 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralResponseMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_methods', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')),
|
||||
new Method('complextype_methods', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Setters')),
|
||||
$setters,
|
||||
$this->getDefinitionComplexTypes()
|
||||
);
|
||||
@ -115,7 +115,7 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$messageBinder = new RpcLiteralResponseMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_complextype', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')),
|
||||
new Method('complextype_complextype', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\ComplexType')),
|
||||
$complexType,
|
||||
$this->getDefinitionComplexTypes()
|
||||
);
|
||||
@ -140,7 +140,7 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
$message = array($attributes, $attributes);
|
||||
$messageBinder = new RpcLiteralResponseMessageBinder();
|
||||
$result = $messageBinder->processMessage(
|
||||
new Method('complextype_argument', null, array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')),
|
||||
new Method('complextype_argument', null, array(), array(), new Type('\BeSimple\SoapBundle\Tests\ServiceBinding\fixtures\Attributes[]')),
|
||||
$message,
|
||||
$this->getDefinitionComplexTypes()
|
||||
);
|
||||
@ -154,13 +154,13 @@ class RpcLiteralResponseMessageBinderTest extends \PHPUnit_Framework_TestCase
|
||||
$messages = array();
|
||||
|
||||
$messages[] = array(
|
||||
new Method('boolean', null, array(), new Type('boolean')),
|
||||
new Method('boolean', null, array(), array(), new Type('boolean')),
|
||||
true,
|
||||
true,
|
||||
);
|
||||
|
||||
$messages[] = array(
|
||||
new Method('strings', null, array(), new Type('string[]')),
|
||||
new Method('strings', null, array(), array(), new Type('string[]')),
|
||||
array('hello', 'world'),
|
||||
array('hello', 'world'),
|
||||
);
|
||||
|
@ -87,6 +87,7 @@ class WebServiceContext
|
||||
if (null === $this->serviceBinder) {
|
||||
$this->serviceBinder = new ServiceBinder(
|
||||
$this->getServiceDefinition(),
|
||||
new $this->options['binder_request_header_class'](),
|
||||
new $this->options['binder_request_class'](),
|
||||
new $this->options['binder_response_class']()
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user