The raw XML passed in the SOAP envelope must be in the body of the POST. In a Symfony application, you can get the body of a POST request by creating a Request object and calling its getContents () method.
Inside the controller
You can easily get the contents of the request in the controller, for example:
// src/MyProject/MyBundle/Controller/MyController.php use Symfony\Component\HttpFoundation\Request; ... $request = Request::createFromGlobals(); $soapEnvelope = $request->getContents();
In service
Best practice (for Symfony 2.4+) is to implement RequestStack in your service class in a service container. You can do this as a constructor argument for your service class by calling the setter method, etc. Here is a quick example of using injection through a constructor.
In your service container:
// src/MyProject/MyBundle/Resources/config/services.xml <service id="my.service" class="MyServiceClass"> <argument type="service" id="request_stack" /> </service>
Then in your service class:
// src/MyProject/MyBundle/Service/MyService.php use Symfony\Component\HttpFoundation\RequestStack; .... class MyServiceClass { /** * @var RequestStack $rs */ private $requestStack; /** * Constructor * * @param RequestStack $requestStack */ public function __construct(RequestStack $requestStack) { $this->requestStack = $requestStack; } /** * Some method where you need to access the raw SOAP xml */ public function myMethod() { $request = $this->requestStack->getCurrentRequest(); $soapEnvelope = $request->getContents(); } }
Reference documentation:
http://symfony.com/blog/new-in-symfony-2-4-the-request-stack
Haig bedrosian
source share