Added SoapResponseListener
This listener allow return a raw result from the action. Before: /** * @Soap\Method("hello") * @Soap\Param("name", phpType = "string") * @Soap\Result(phpType = "string") */ public function helloAction($name) { return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Hello %s!', $name)); } After: /** * @Soap\Method("hello") * @Soap\Param("name", phpType = "string") * @Soap\Result(phpType = "string") */ public function helloAction($name) { return sprintf('Hello %s!', $name); }
This commit is contained in:
parent
2e34b1ce1d
commit
e3ddebfea4
56
EventListener/SoapResponseListener.php
Normal file
56
EventListener/SoapResponseListener.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapBundle.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapBundle\EventListener;
|
||||
|
||||
use BeSimple\SoapBundle\Soap\SoapRequest;
|
||||
use BeSimple\SoapBundle\Soap\SoapResponse;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
|
||||
|
||||
/**
|
||||
* SoapResponseListener.
|
||||
*
|
||||
* @author Francis Besset <francis.besset@gmail.com>
|
||||
*/
|
||||
class SoapResponseListener
|
||||
{
|
||||
/**
|
||||
* @var SoapResponse
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param SoapResponse $response The SoapResponse instance
|
||||
*/
|
||||
public function __construct(SoapResponse $response)
|
||||
{
|
||||
$this->response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the controller result in SoapResponse.
|
||||
*
|
||||
* @param GetResponseForControllerResultEvent $event A GetResponseForControllerResultEvent instance
|
||||
*/
|
||||
public function onKernelView(GetResponseForControllerResultEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
if (!$request instanceof SoapRequest) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response->setReturnValue($event->getControllerResult());
|
||||
$event->setResponse($this->response);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
<parameters>
|
||||
<parameter key="besimple.soap.response.class">BeSimple\SoapBundle\Soap\SoapResponse</parameter>
|
||||
<parameter key="besimple.soap.response.listener.class">BeSimple\SoapBundle\EventListener\SoapResponseListener</parameter>
|
||||
<parameter key="besimple.soap.context.class">BeSimple\SoapBundle\WebServiceContext</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>
|
||||
@ -20,6 +21,11 @@
|
||||
<services>
|
||||
<service id="besimple.soap.response" class="%besimple.soap.response.class%" />
|
||||
|
||||
<service id="besimple.soap.response.listener" class="%besimple.soap.response.listener.class%">
|
||||
<tag name="kernel.event_listener" event="kernel.view" method="onKernelView" />
|
||||
<argument type="service" id="besimple.soap.response" />
|
||||
</service>
|
||||
|
||||
<service id="besimple.soap.context.rpcliteral" class="%besimple.soap.context.class%" abstract="true">
|
||||
<argument type="service" id="besimple.soap.definition.loader" />
|
||||
<argument type="service" id="besimple.soap.definition.dumper.wsdl.rpcliteral" />
|
||||
|
@ -34,7 +34,7 @@ Annotations for Controllers
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
namespace My\App\Controller;
|
||||
namespace Acme\DemoBundle\Controller;
|
||||
|
||||
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
@ -48,7 +48,17 @@ Annotations for Controllers
|
||||
*/
|
||||
public function helloAction($name)
|
||||
{
|
||||
return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Hello %s!', $name));
|
||||
return sprintf('Hello %s!', $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Soap\Method("goodbye")
|
||||
* @Soap\Param("name", phpType = "string")
|
||||
* @Soap\Result(phpType = "string")
|
||||
*/
|
||||
public function goodbyeAction($name)
|
||||
{
|
||||
return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Goodbye %s!', $name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,5 +67,4 @@ Get your WSDL
|
||||
|
||||
To access your WSDL go to the following address: http://localhost/app_dev.php/ws/DemoApi?wsdl
|
||||
|
||||
To read the WSDL in your browser you can call this address: http://localhost/app_dev.php/ws/DemoApi
|
||||
|
||||
To read the WSDL in your browser you can call this address (without `wsdl` parameter): http://localhost/app_dev.php/ws/DemoApi
|
||||
|
Loading…
Reference in New Issue
Block a user