PHPackages                             tomasz-kusy/soap-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. tomasz-kusy/soap-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

tomasz-kusy/soap-client
=======================

0.6+tk(5mo ago)01.3k1MITPHPPHP ^7.1|^8.0

Since Sep 26Pushed 1mo agoCompare

[ Source](https://github.com/tomasz-kusy/soap-client)[ Packagist](https://packagist.org/packages/tomasz-kusy/soap-client)[ Fund](https://www.goetas.com/)[ GitHub Sponsors](https://github.com/goetas)[ RSS](/packages/tomasz-kusy-soap-client/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (36)Versions (33)Used By (0)

goetas-webservices / soap-client
================================

[](#goetas-webservices--soap-client)

[![Build Status](https://camo.githubusercontent.com/686e22107d09440ba0163c7ca944f2970fc30516a865ba44c0b0d050d4900959/68747470733a2f2f7472617669732d63692e6f72672f676f657461732d77656273657276696365732f736f61702d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/goetas-webservices/soap-client)[![Code Coverage](https://camo.githubusercontent.com/601c9fedbc359c090fe5844eee13099f2227d6fc95364830a126aae1007d0b83/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676f657461732d77656273657276696365732f736f61702d636c69656e742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/goetas-webservices/soap-client/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3f46bb1385514c6617ca535478de50fa0f4ac435c62da3c0ffee571635fd1ede/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f676f657461732d77656273657276696365732f736f61702d636c69656e742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/goetas-webservices/soap-client/?branch=master)

PHP implementation of SOAP 1.1 and 1.2 client specifications.

Strengths:

- Pure PHP, no dependencies on `ext-soap`
- Extensible (JMS event listeners support)
- PSR-7 HTTP messaging compatible
- Multi HTTP client (guzzle, buzz, curl, react)
- No WSDL/XSD parsing on production
- IDE type hinting support

Only document/literal style is supported and the webservice should follow the [WS-I](https://en.wikipedia.org/wiki/WS-I_Basic_Profile) guidelines.

There are no plans to support the deprecated rpc and encoded styles. Webservices not following the WS-I specifications might work, but they are officially not supported.

Demo
----

[](#demo)

[goetas-webservices/soap-client-demo](https://github.com/goetas-webservices/soap-client-demo) is a demo project that shows how to consume a SOAP api in a generic PHP web application.

Installation
------------

[](#installation)

The recommended way to install goetas-webservices / soap-client is using [Composer](https://getcomposer.org/):

Add this packages to your `composer.json` file.

```
{
    "require": {
        "goetas-webservices/soap-client": "^0.2",
    },
    "require-dev": {
        "goetas-webservices/wsdl2php": "^0.3",
    },
}

```

More dependencies might be needed depending on your PSR-7 and HTTP client preferred implementation. You can have a look to the [Dependencies](https://github.com/goetas-webservices/soap-client-demo#dependencies) section of a demo project to understand what can be necessary.

How to
======

[](#how-to)

To improve performance, this library is based on the concept that all the SOAP/WSDL metadata has to be compiled into PHP compatible metadata (in reality is a big plain PHP array, so is really fast).

To do this we have to define a configuration file (in this case called `config.yml`) that holds some important information.

Here is an example:

```
# config.yml

soap_client:
  alternative_endpoints:
    MyServiceName:
      MySoapPortName: http://localhost:8080/service

  namespaces:
    'http://www.example.org/test/': 'TestNs/MyApp'
  destinations_php:
    'TestNs/MyApp': soap/src
  destinations_jms:
    'TestNs/MyApp': soap/metadata
  aliases:
    'http://www.example.org/test/':
      MyCustomXSDType:  'MyCustomMappedPHPType'

  metadata:
    'test.wsdl': ~
    'http://www.webservicex.net/weather.asmx?WSDL': ~
```

This file has some important sections:

### SOAP Specific

[](#soap-specific)

- `alternative_endpoints` (optional) allows you to specify alternative URLs that can be used when developing your integration. If this parameter is not present, will be used the URL defined by the WSDL file, but if is set, will be used the specified URL for the service called *MyServiceName* and on *MySoapPortName* port.
- `unwrap_returns` (optional, default: *false*) allows to define the "wrapped" SOAP services mode. Instructs the client to "unwrap" all the returns.

### WSDL Specific

[](#wsdl-specific)

- `metadata` specifies where are placed WSDL files that will be used to generate al the required PHP metadata.

### XML/XSD Specific

[](#xmlxsd-specific)

- `namespaces` (required) defines the mapping between XML namespaces and PHP namespaces. (in the example we have the `http://www.example.org/test/` XML namespace mapped to `TestNs\MyApp`)
- `destinations_php` (required) specifies the directory where to save the PHP classes that belongs to `TestNs\MyApp` PHP namespace. (in this example `TestNs\MyApp` classes will ne saved into `soap/src` directory.
- `destinations_jms` (required) specifies the directory where to save JMS Serializer metadata files that belongs to `TestNs\MyApp` PHP namespace. (in this example `TestNs\MyApp` metadata will ne saved into `soap/metadata` directory.
- `aliases` (optional) specifies some mappings that are handled by custom JMS serializer handlers. Allows to specify to do not generate metadata for some XML types, and assign them directly a PHP class. For that PHP class is necessary to create a custom JMS serialize/deserialize handler.

Metadata generation
-------------------

[](#metadata-generation)

In order to be able to use the SOAP client we have to generate some metadata and PHP classes.

To do it we can run:

```
bin/soap-client generate \
 tests/config.yml \
 --dest-class=GlobalWeather/Container/SoapClientContainer \
 soap/src-gw/Container
```

- `bin/soap-client generate` is the command we are running
- `tests/config.yml` is a path to our configuration file
- `--dest-class=GlobalWeather/Container/SoapClientContainer` allows to specify the fully qualified class name of the container class that will hold all the webservice metadata.
- `soap/src/Container` is the path where to save the container class that holds all the webservice metadata (you will have to configure the auto loader to load it)

Using the client
----------------

[](#using-the-client)

Once all the metadata are generated we can use our SOAP client.

Let's see a minimal example:

```
// composer auto loader
require __DIR__ . '/vendor/autoload.php';

// instantiate the main container class
// the name was defined by --dest-class=GlobalWeather/Container/SoapClientContainer
// parameter during the generation process
$container = new SoapClientContainer();

// create a JMS serializer instance
$serializer = SoapContainerBuilder::createSerializerBuilderFromContainer($container)->build();
// get the metadata from the container
$metadata = $container->get('goetas_webservices.soap_client.metadata_reader');

$factory = new ClientFactory($metadata, $serializer);

/**
 * @var $client \GlobalWeather\SoapStubs\WeatherSoap
 */
 // get the soap client
$client = $factory->getClient('http://www.webservicex.net/weather.asmx?WSDL');

// call the webservice
$result = $client->getWeather(2010, "May", "USA");
```

Please note the `@var $client \GlobalWeather\SoapStubs\WeatherSoap`. The generated metadata have also a "stub" class that allows modern IDE to give you type hinting for parameters and return data.

This allows you to develop faster your client.

### Using the client with dynamic endpoints

[](#using-the-client-with-dynamic-endpoints)

Suppose that you have same Webservice with different endpoints (ex. for each customer), so you want to change endpoints dynamically and you don't want to write each new endpoint in your config and run the generator for each customer.

With the help of Symfony's `EnvVarProcessorInterface`, you can use `alternative_endpoints` to set dynamically the webservice endpoints.

Here is an example:

```
# config.yml
soap_client:
  alternative_endpoints:
    MyServiceName:
      MySoapPortName: 'env(custom_vars:ENDPOINT_SERVICE1_PORT1)'
```

So, `SoapClientContainer` will resolve at runtime the endpoint for the specific service and port and the value will be taken from the `ENDPOINT_SERVICE1_PORT1` variable.

Example of simple class that implements `EnvVarProcessorInterface`, responsible for providing a values for our custom endpoint locations (as `custom_vars:ENDPOINT_SERVICE1_PORT1`).

```
// SimpleEnvVarProcessor.php used for the `env(custom_vars:*)` variables resolution

use Symfony\Component\DependencyInjection\EnvVarProcessorInterface;

class SimpleEnvVarProcessor implements EnvVarProcessorInterface
{
    private $map = [];

    public function __construct(array $map)
    {
        $this->map = $map;
    }

    public function getEnv($prefix, $name, \Closure $getEnv)
    {
        return $this->map[$name];
    }

    public static function getProvidedTypes()
    {
        return [];
    }
}
```

At the end, to use the `SoapClientContainer`:

```
// instantiate our variable processor and set the values for our custom variables
$varProcessor = new SimpleEnvVarProcessor([
    'ENDPOINT_SERVICE1_PORT1' => 'http://localhost:8080/service'
]);

// create an empty symfony container and set into it the $varProcessor namined as 'custom_vars'
$varContainer = new \Symfony\Component\DependencyInjection\Container();
$varContainer->set('custom_vars', $varProcessor);

// create the soap container and use $varContainer "env()" style variables resolution
$container = new SoapClientContainer();
$container->set('container.env_var_processors_locator', $varContainer);

// now $container can be used as explained in the section "Using the client"
```

In this way the endpoint for the `MyServiceName`.`MySoapPortName` will be dynamically resolved to `http://localhost:8080/service`even if the WSDL stats something else.

Note
----

[](#note)

The code in this project is provided under the [MIT](https://opensource.org/licenses/MIT) license. For professional support contact or visit

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance81

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~135 days

Recently: every ~306 days

Total

27

Last Release

50d ago

PHP version history (4 changes)v0.1.0PHP ^5.5|^7.0

v0.2.3PHP ^5.6|^7.0

v0.4PHP ^7.1

v0.4.2PHP ^7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a189b7f3f5ada446af477e5edb60083200353e8e7709e7813df137d673c25445?d=identicon)[tomasz-kusy](/maintainers/tomasz-kusy)

---

Top Contributors

[![goetas](https://avatars.githubusercontent.com/u/776743?v=4)](https://github.com/goetas "goetas (80 commits)")[![riccardonar](https://avatars.githubusercontent.com/u/5285820?v=4)](https://github.com/riccardonar "riccardonar (12 commits)")[![Toilal](https://avatars.githubusercontent.com/u/1165758?v=4)](https://github.com/Toilal "Toilal (5 commits)")[![bcremer](https://avatars.githubusercontent.com/u/55820?v=4)](https://github.com/bcremer "bcremer (1 commits)")[![chr-hertel](https://avatars.githubusercontent.com/u/2852185?v=4)](https://github.com/chr-hertel "chr-hertel (1 commits)")[![giansalex](https://avatars.githubusercontent.com/u/14926587?v=4)](https://github.com/giansalex "giansalex (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tomasz-kusy-soap-client/health.svg)

```
[![Health](https://phpackages.com/badges/tomasz-kusy-soap-client/health.svg)](https://phpackages.com/packages/tomasz-kusy-soap-client)
```

###  Alternatives

[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k28.0M318](/packages/openai-php-client)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[anthropic-ai/sdk

Anthropic PHP SDK

163583.3k17](/packages/anthropic-ai-sdk)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28150.5k](/packages/phpro-http-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
