Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Soap Client #26

Open
joelwurtz opened this issue Jul 25, 2016 · 14 comments
Open

Add Soap Client #26

joelwurtz opened this issue Jul 25, 2016 · 14 comments

Comments

@joelwurtz
Copy link
Member

Q A
Bug? no
New Feature? yes

This is a feature request for adding a soap client (extending the one from PHP) which use a HttpClient implementation to send the soap request.

Having this allow to profit of all the debugging offer by the HttplugBundle for Soap requests.

Here is an example of what we have done in a project :

/**
 * Wrapper around PHP SoapClient to use a HttpClient instead of php, allow better control over the request.
 */
class SoapClient extends \SoapClient
{
    private $httpClient;

    public function __construct(HttpClient $httpClient, $wsdl, array $options = [])
    {
        $this->httpClient = $httpClient;

        parent::__construct($wsdl, $options);
    }

    /**
     * {@inheritdoc}
     */
    public function __doRequest($body, $location, $action, $version, $one_way = 0)
    {
        $headers = [
            'Content-Type' => sprintf('application/soap+xml; charset=utf-8; action="%s"', $action),
        ];

        if ($version === SOAP_1_1) {
            $headers = [
                'Content-Type' => 'text/xml; charset=utf-8',
                'SOAPAction'   => $action,
            ];
        }

        try {
            $response = $this->httpClient->sendRequest(new Request('POST', $location, $headers, $body));
        } catch (HttpException $exception) {
            return $exception->getResponse()->getBody()->getContents();
        }

        return $response->getBody()->getContents();
    }
}
@sagikazarmark
Copy link
Member

To be honest, I always wanted to do something like this, so huge 👍 if we can create something like that.

@dbu
Copy link
Contributor

dbu commented Jul 25, 2016

that sounds useful!

does it introduce any additional dependencies? even if not, i wonder if it should be part of client-common or its own repository. its a bit hidden away in client-common, and not a generic http client thing but specific to a higher layer protocol. on the other hand, if the code in the description is everything we need for it, we can just as well have it in here.

@joelwurtz
Copy link
Member Author

joelwurtz commented Jul 25, 2016

does it introduce any additional dependencies ?

It requires the soap extension from php, but IMO we can just add a check in the file and throw an exception if extension is not present, otherwise this extension is available in most package manager of linux distribution

if the code in the description is everything we need for it, we can just as well have it in here.

Pretty much, this may need a factory for the request, apart from that it's a good first implementation.

Also as always i don't like adding new packages, even if it can be better in a decoupled vision it always introduces a bigger need for maintenance and complexify the whole thing, and IMO this is too much work given the current size of php-http team.

@sagikazarmark
Copy link
Member

sagikazarmark commented Jul 25, 2016

but IMO we can just add a check in the file and throw an exception if extension is not present

Do we need that? I am not against optional dependencies in this case. Also: would it make sense? We extend the class from the extension, so if we add a check inside the class, it wouldn't make a difference.

@dbu
Copy link
Contributor

dbu commented Jul 25, 2016

i guess \SoapClient is only available with the soap extension. not sure if it could be a problem for people without soap extension if this file exists and some tool loads all classes or something.

@tuupola
Copy link

tuupola commented Nov 11, 2016

Have you seen this? https://github.com/goetas-webservices/soap-client

@xabbuh
Copy link
Member

xabbuh commented Nov 11, 2016

I think I would prefer to have it in its own package. You could then also declare dependencies just right from the beginning for this new client implementation.

Apart from that I think implementing such a client would be a very nice addition.

@sagikazarmark
Copy link
Member

Have you see this? https://github.com/goetas-webservices/soap-client

Hm, nice, no I haven't.

@xabbuh well, the usual workflow now is to start experimental features in separate repos and merge them on demand, so at least for a start it should be in a separate repo, but I can't decide anymore what should come next. Probably you are right.

@xabbuh
Copy link
Member

xabbuh commented Nov 11, 2016

A bit unrelated to the proposed HTTPlug SOAP client: It could be interesting to see it were possible to create a \Soap_Client polyfill using the goetas-webservices/soap-client package.

@sagikazarmark
Copy link
Member

sagikazarmark commented Nov 11, 2016

Finally something that I could put here: https://github.com/polyphill
:trollface:

tuupola added a commit to tuupola/cache-plugin that referenced this issue Feb 6, 2017
This is useful for example when using a HTTPlug based SoapClient.
php-http/client-common#26
tuupola added a commit to tuupola/cache-plugin that referenced this issue Feb 10, 2017
This is useful for example when using a HTTPlug based SoapClient.
php-http/client-common#26
@GrahamCampbell
Copy link
Contributor

Are new APIs still launched today using SOAP?

@dbu
Copy link
Contributor

dbu commented Jul 19, 2020

i guess java people still sometimes do soap. or you build a system that needs to talk to a legacy system that is written in soap. in our projects we talk to SAP, and the devs there regularly extend the soap api...

that said, this suggestion has been open for a while and nobody wanted it enough to put the effort into it. imho we can close this issue here.

@veewee
Copy link

veewee commented Oct 30, 2021

We are doing exactly this for a while now in phpro/soap-client and recently moved it to a new standalone package.

It allows for adding http plugins to php's soap client for doing advanced things like WSSE.

You might be interested in using a combination of these packages:

@dbu
Copy link
Contributor

dbu commented Nov 1, 2021

awesome, thanks for those links!

do you want to add a sub-section "Third party PSR-18 clients" to https://docs.php-http.org/en/latest/clients.html that links to those 2 packages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants