diff --git a/Controller/SoapWebServiceController.php b/Controller/SoapWebServiceController.php
index 250d99d..fc93eb8 100644
--- a/Controller/SoapWebServiceController.php
+++ b/Controller/SoapWebServiceController.php
@@ -58,15 +58,15 @@ class SoapWebServiceController extends ContainerAware
$this->serviceBinder = $webServiceContext->getServiceBinder();
$this->soapRequest = SoapRequest::createFromHttpRequest($this->container->get('request'));
- $this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, new SoapResponse());
+ $this->soapServer = $webServiceContext->getServerFactory()->create($this->soapRequest, $this->getResponse());
$this->soapServer->setObject($this);
ob_start();
$this->soapServer->handle($this->soapRequest->getSoapMessage());
- $this->soapResponse->setContent(ob_get_clean());
+ $this->getResponse()->setContent(ob_get_clean());
- return $this->soapResponse;
+ return $this->getResponse();
}
/**
@@ -127,14 +127,14 @@ class SoapWebServiceController extends ContainerAware
$this->soapResponse = $this->checkResponse($response);
// add response soap headers to soap server
- foreach ($this->soapResponse->getSoapHeaders() as $header) {
+ foreach ($this->getResponse()->getSoapHeaders() as $header) {
$this->soapServer->addSoapHeader($header->toNativeSoapHeader());
}
// return operation return value to soap server
return $this->serviceBinder->processServiceMethodReturnValue(
$method,
- $this->soapResponse->getReturnValue()
+ $this->getResponse()->getReturnValue()
);
} else {
// collect request soap headers
@@ -155,7 +155,7 @@ class SoapWebServiceController extends ContainerAware
*/
public function getResponse()
{
- return $this->soapResponse;
+ return $this->soapResponse ?: $this->soapResponse = $this->container->get('besimple.soap.response');
}
/**
@@ -165,12 +165,12 @@ class SoapWebServiceController extends ContainerAware
*
* @return SoapResponse A valid SoapResponse
*
- * @throws InvalidArgumentException if the given Response is null or not a SoapResponse
+ * @throws InvalidArgumentException if the given Response is not an instance of SoapResponse
*/
protected function checkResponse(Response $response)
{
if (!$response instanceof SoapResponse) {
- throw new \InvalidArgumentException();
+ throw new \InvalidArgumentException('You must return an instance of BeSimple\SoapBundle\Soap\SoapResponse');
}
return $response;
diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml
index b1cd5f6..873148a 100644
--- a/Resources/config/webservice.xml
+++ b/Resources/config/webservice.xml
@@ -4,6 +4,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+ BeSimple\SoapBundle\Soap\SoapResponse
BeSimple\SoapBundle\WebServiceContext
%kernel.cache_dir%/webservice
BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestHeaderMessageBinder
@@ -17,6 +18,8 @@
+
+
diff --git a/Resources/doc/reference/configuration.rst b/Resources/doc/reference/configuration.rst
index 4c2d469..1ccd620 100644
--- a/Resources/doc/reference/configuration.rst
+++ b/Resources/doc/reference/configuration.rst
@@ -34,18 +34,20 @@ Annotations for Controllers
.. code-block:: php
- use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
- use BeSimple\SoapBundle\Soap\SoapResponse;
+ namespace My\App\Controller;
- class DemoController extends Controller
+ use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
+ use Symfony\Component\DependencyInjection\ContainerAware;
+
+ class DemoController extends ContainerAware
{
/**
- * @Soap\Method("Hello")
+ * @Soap\Method("hello")
* @Soap\Param("name", phpType = "string")
* @Soap\Result(phpType = "string")
*/
public function helloAction($name)
{
- return new SoapResponse(sprintf('Hello %s!', $name));
+ return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Hello %s!', $name));
}
}
\ No newline at end of file
diff --git a/Resources/doc/tutorial/array.rst b/Resources/doc/tutorial/array.rst
index 7972624..aa12f33 100644
--- a/Resources/doc/tutorial/array.rst
+++ b/Resources/doc/tutorial/array.rst
@@ -9,7 +9,6 @@ Controller
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
@@ -21,6 +20,6 @@ Controller
*/
public function helloAction(array $names)
{
- return new SoapResponse("Hello ".implode(', ', $names));
+ return $this->container->get('besimple.soap.response')->setReturnValue("Hello ".implode(', ', $names));
}
}
\ No newline at end of file
diff --git a/Resources/doc/tutorial/complex_type.rst b/Resources/doc/tutorial/complex_type.rst
index edf03cd..24514ea 100644
--- a/Resources/doc/tutorial/complex_type.rst
+++ b/Resources/doc/tutorial/complex_type.rst
@@ -15,7 +15,6 @@ Controller
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
@@ -29,13 +28,13 @@ Controller
{
$user = $this->container->getDoctrine()->getRepository('MyApp:User')->findOneBy(array(
'name' => $name,
- );
+ ));
if (!$user) {
throw new \SoapFault('USER_NOT_FOUND', sprintf('The user with the name "%s" can not be found', $name));
}
- return new SoapResponse($user);
+ return $this->container->get('besimple.soap.response')->setReturnValue($user);
}
}
diff --git a/Resources/doc/tutorial/header.rst b/Resources/doc/tutorial/header.rst
index b71bd89..d1dc849 100644
--- a/Resources/doc/tutorial/header.rst
+++ b/Resources/doc/tutorial/header.rst
@@ -9,7 +9,6 @@ Controller
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
@@ -27,6 +26,6 @@ Controller
throw new \SoapFault("INVALID_API_KEY", "The api_key is invalid.");
}
- return new SoapResponse("Hello ".implode(', ', $names));
+ return $this->container->get('besimple.soap.response')->setReturnValue("Hello ".implode(', ', $names));
}
}
\ No newline at end of file
diff --git a/Soap/SoapResponse.php b/Soap/SoapResponse.php
index 5fba41b..1574b00 100644
--- a/Soap/SoapResponse.php
+++ b/Soap/SoapResponse.php
@@ -58,6 +58,8 @@ class SoapResponse extends Response
public function setReturnValue($value)
{
$this->soapReturnValue = $value;
+
+ return $this;
}
public function getReturnValue()