-
This library was very easy to get started, but started to get overwhelming pretty quick :-) Can somebody put me in the right direction on how I would add two nodes to the body for all the requests? A custom middleware? How do I get started with these? Thank you all. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @rico , I can imagine it gets overwhelming... That's the downside of having it ultra flexible. :) There are a few ways to do this depending on your exact case:
If you think an event subscriber is the way to go: The basics are covered here: https://github.com/phpro/soap-client/blob/master/docs/events.md We use this approach for adding e.g. a session identifier to every soap request.
Example model implementation: final class RegisterSessionListener
{
public function __construct(private SessionProviderInterface $sessionProvider)
{
}
public function onClientRequest(RequestEvent $event): void
{
$request = $event->getRequest();
if (!$request instanceof RequiresShessionInterface) {
return;
}
$event->registerRequest(
$request->withSession(
$this->sessionProvider->provide()
)
);
}
} If you think an HTTP middleware is the way to go:
Example middleware for manipulating soap body public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
return $next((new XmlMessageManipulator)(
$request,
function (Document $document) {
$body = $document->locate(new SoapBodyLocator());
append($YOURELEMENTS)($body);
return $document;
}
));
} You can read more about manipulating the document here: https://github.com/veewee/xml/blob/main/docs/dom.md Hope this gets you in the right direction :) |
Beta Was this translation helpful? Give feedback.
-
Hi @veewee, a huge thank you for the detailed and helpful answer. I was able to solve it using a simple event subscriber. I guess this project is almost too simple to get started, so that people like me, without much of knowledge in the domain, get stuck easily. But your answer is great to find the right direction :-) |
Beta Was this translation helpful? Give feedback.
Hello @rico ,
I can imagine it gets overwhelming... That's the downside of having it ultra flexible. :)
We do our best to document everything as good as possible, but feel free to improve the documentation.
There are a few ways to do this depending on your exact case:
If you think an event subscriber is the way to go:
The basics are covered here: https://github.com/phpro/soap-client/blob/master/docs/events.md
We …