Skip to content

Add Soap Client #26

Open
Open
@joelwurtz

Description

@joelwurtz
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();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions