{"id":13828228,"url":"https://github.com/goetas-webservices/soap-client","last_synced_at":"2025-07-09T06:31:19.065Z","repository":{"id":55086591,"uuid":"67522808","full_name":"goetas-webservices/soap-client","owner":"goetas-webservices","description":"PHP implementation of SOAP 1.1 and 1.2 client specifications","archived":false,"fork":false,"pushed_at":"2023-07-05T07:32:41.000Z","size":287,"stargazers_count":175,"open_issues_count":23,"forks_count":28,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-06T19:55:19.904Z","etag":null,"topics":["php","soap","soap-client","webservice","wsdl"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goetas-webservices.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"goetas","patreon":"goetas","custom":"https://www.goetas.com/"}},"created_at":"2016-09-06T15:49:49.000Z","updated_at":"2024-02-02T21:04:07.000Z","dependencies_parsed_at":"2024-01-12T10:25:56.456Z","dependency_job_id":"91a7e6a1-20b7-40be-b63f-0de8488e20dc","html_url":"https://github.com/goetas-webservices/soap-client","commit_stats":{"total_commits":105,"total_committers":8,"mean_commits":13.125,"dds":0.2761904761904762,"last_synced_commit":"04cb405f869418c6b745a468b34a114364ebba37"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas-webservices%2Fsoap-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas-webservices%2Fsoap-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas-webservices%2Fsoap-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goetas-webservices%2Fsoap-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goetas-webservices","download_url":"https://codeload.github.com/goetas-webservices/soap-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","soap","soap-client","webservice","wsdl"],"created_at":"2024-08-04T09:02:37.486Z","updated_at":"2024-11-20T08:30:21.431Z","avatar_url":"https://github.com/goetas-webservices.png","language":"PHP","funding_links":["https://github.com/sponsors/goetas","https://patreon.com/goetas","https://www.goetas.com/"],"categories":["PHP","SOAP"],"sub_categories":[],"readme":"# goetas-webservices / soap-client\n\n[![Build Status](https://travis-ci.org/goetas-webservices/soap-client.svg?branch=master)](https://travis-ci.org/goetas-webservices/soap-client)\n\nPHP implementation of SOAP 1.1 and 1.2 client specifications.\n\nStrengths: \n\n- Pure PHP, no dependencies on `ext-soap`\n- Extensible (JMS event listeners support)\n- PSR-7 HTTP messaging\n- PSR-17 HTTP messaging factories\n- PSR-18 HTTP Client\n- No WSDL/XSD parsing on production\n- IDE type hinting support\n\nOnly document/literal style is supported and the webservice should follow\nthe [WS-I](https://en.wikipedia.org/wiki/WS-I_Basic_Profile) guidelines.\n\nThere are no plans to support the deprecated rpc and encoded styles.\nWebservices not following the WS-I specifications might work, but they are officially not supported.\n\n## Demo \n\n[goetas-webservices/soap-client-demo](https://github.com/goetas-webservices/soap-client-demo) is a demo project\nthat shows how to consume a SOAP api in a generic PHP web application.\n\n\nInstallation\n-----------\n\nThe recommended way to install goetas-webservices / soap-client is using [Composer](https://getcomposer.org/):\n\nAdd this packages to your `composer.json` file.\n\n```\n{\n    \"require\": {\n        \"goetas-webservices/soap-client\": \"^0.3\",\n    },\n    \"require-dev\": {\n        \"goetas-webservices/wsdl2php\": \"^0.5.1\",\n    },\n}\n```\n\n# How to\n\nTo improve performance, this library is based on the concept that all the SOAP/WSDL \nmetadata has to be compiled into PHP compatible metadata (in reality is a big plain PHP array,\nso is really fast).\n\nTo do this we have to define a configuration file (in this case called `config.yml`) that\nholds some important information. \n\nHere is an example:\n\n```yml\n# config.yml\n\nsoap_client:\n  alternative_endpoints:\n    MyServiceName:\n      MySoapPortName: http://localhost:8080/service\n\n  namespaces:\n    'http://www.example.org/test/': 'TestNs/MyApp'\n  destinations_php:\n    'TestNs/MyApp': soap/src\n  destinations_jms:\n    'TestNs/MyApp': soap/metadata\n  aliases:\n    'http://www.example.org/test/':\n      MyCustomXSDType:  'MyCustomMappedPHPType'\n\n  metadata:\n    'test.wsdl': ~\n    'http://www.webservicex.net/weather.asmx?WSDL': ~\n```\n\nThis file has some important sections: \n\n### SOAP Specific\n* `alternative_endpoints` (optional) allows you to specify alternative URLs that can be used\n when developing your integration. \n If this parameter is not present, will be used the URL defined by the WSDL file, \n but if is set, will be used the specified URL for the service called \n *MyServiceName* and on *MySoapPortName* port.\n\n\n* `unwrap_returns` (optional, default: *false*) allows to define the \"wrapped\" SOAP services mode. \n Instructs the client to \"unwrap\" all the returns.\n\n### WSDL Specific\n\n* `metadata` specifies where are placed WSDL files that will be used to generate al the required PHP metadata.\n\n \n### XML/XSD Specific\n \n* `namespaces` (required) defines the mapping between XML namespaces and PHP namespaces.\n (in the example we have the `http://www.example.org/test/` XML namespace mapped to `TestNs\\MyApp`)\n\n\n* `destinations_php` (required) specifies the directory where to save the PHP classes that belongs to \n `TestNs\\MyApp` PHP namespace. (in this example `TestNs\\MyApp` classes will ne saved into `soap/src` directory.\n \n\n* `destinations_jms` (required) specifies the directory where to save JMS Serializer metadata files \n that belongs to `TestNs\\MyApp` PHP namespace. \n (in this example `TestNs\\MyApp` metadata will ne saved into `soap/metadata` directory.\n \n \n* `aliases` (optional) specifies some mappings that are handled by custom JMS serializer handlers.\n Allows to specify to do not generate metadata for some XML types, and assign them directly a PHP class.\n For that PHP class is necessary to create a custom JMS serialize/deserialize handler.\n \n \n \n## Metadata generation\n \nIn order to be able to use the SOAP client we have to generate some metadata and PHP classes.\n \nTo do it we can run:\n\n```sh\nbin/soap-client generate \\\n tests/config.yml \\\n --dest-class=GlobalWeather/Container/SoapClientContainer \\\n soap/src-gw/Container \n```\n\n\n* `bin/soap-client generate` is the command we are running\n* `tests/config.yml` is a path to our configuration file\n* `--dest-class=GlobalWeather/Container/SoapClientContainer` allows to specify the fully qualified class name of the \n container class that will hold all the webservice metadata.\n* `soap/src/Container` is the path where to save the container class that holds all the webservice metadata\n (you will have to configure the auto loader to load  it)\n\n \n \n## Using the client\n\nOnce all the metadata are generated we can use our SOAP client.\n\nLet's see a minimal example:\n\n```php\n// composer auto loader\nrequire __DIR__ . '/vendor/autoload.php';\n\n// instantiate the main container class\n// the name was defined by --dest-class=GlobalWeather/Container/SoapClientContainer\n// parameter during the generation process\n$container = new SoapClientContainer();\n\n// create a JMS serializer instance\n$serializer = SoapContainerBuilder::createSerializerBuilderFromContainer($container)-\u003ebuild();\n// get the metadata from the container\n$metadata = $container-\u003eget('goetas_webservices.soap.metadata_reader');\n\n$factory = new ClientFactory($metadata, $serializer);\n\n/**\n * @var $client \\GlobalWeather\\SoapStubs\\WeatherSoap\n */\n // get the soap client\n$client = $factory-\u003egetClient('http://www.webservicex.net/weather.asmx?WSDL');\n\n// call the webservice\n$result = $client-\u003egetWeather(2010, \"May\", \"USA\");\n\n// call the webservice with custom headers\n$result = $client-\u003egetWeather(2010, \"May\", \"USA\", Header::asMustUnderstand(new SomeAuth('me', 'pwd')));\n\n\n```\n\n\nPlease note the `@var $client \\GlobalWeather\\SoapStubs\\WeatherSoap`. The generated metadata have also a \"stub\" class\nthat allows modern IDE to give you type hinting for parameters and return data.\n\nThis allows you to develop faster your client.\n\n### Using the client with dynamic endpoints\n\nSuppose that you have same Webservice with different endpoints (ex. for each customer), \nso you want to change endpoints dynamically and you don't want to write each new endpoint in your config \nand run the generator for each customer.\n\nWith the help of Symfony's `EnvVarProcessorInterface`, \nyou can use `alternative_endpoints` to set dynamically the webservice endpoints.\n\nHere is an example:\n\n```yml\n# config.yml\nsoap_client:\n  alternative_endpoints:\n    MyServiceName:\n      MySoapPortName: 'env(custom_vars:ENDPOINT_SERVICE1_PORT1)'\n```\n\nSo, `SoapClientContainer` will resolve at runtime the endpoint for the specific service and port and the value will be \ntaken from the `ENDPOINT_SERVICE1_PORT1` variable.\n\nExample of simple class that implements `EnvVarProcessorInterface`, responsible for providing a values for \nour custom endpoint locations (as `custom_vars:ENDPOINT_SERVICE1_PORT1`).\n\n```php\n// SimpleEnvVarProcessor.php used for the `env(custom_vars:*)` variables resolution\n\nuse Symfony\\Component\\DependencyInjection\\EnvVarProcessorInterface;\n\nclass SimpleEnvVarProcessor implements EnvVarProcessorInterface\n{\n    private $map = [];\n\n    public function __construct(array $map)\n    {\n        $this-\u003emap = $map;\n    }\n\n    public function getEnv($prefix, $name, \\Closure $getEnv)\n    {\n        return $this-\u003emap[$name];\n    }\n\n    public static function getProvidedTypes()\n    {\n        return [];\n    }\n}\n```\n\nAt the end, to use the `SoapClientContainer`:\n\n\n```php\n// instantiate our variable processor and set the values for our custom variables\n$varProcessor = new SimpleEnvVarProcessor([\n    'ENDPOINT_SERVICE1_PORT1' =\u003e 'http://localhost:8080/service'\n]);\n\n// create an empty symfony container and set into it the $varProcessor namined as 'custom_vars'\n$varContainer = new \\Symfony\\Component\\DependencyInjection\\Container(); \n$varContainer-\u003eset('custom_vars', $varProcessor);\n\n// create the soap container and use $varContainer \"env()\" style variables resolution\n$container = new SoapClientContainer();\n$container-\u003eset('container.env_var_processors_locator', $varContainer);\n\n// now $container can be used as explained in the section \"Using the client\"\n```\n\nIn this way the endpoint for the `MyServiceName`.`MySoapPortName` will be dynamically resolved to `http://localhost:8080/service`\neven if the WSDL stats something else.\n\n## Note \n\nThe code in this project is provided under the \n[MIT](https://opensource.org/licenses/MIT) license. \nFor professional support \ncontact [goetas@gmail.com](mailto:goetas@gmail.com) \nor visit [https://www.goetas.com](https://www.goetas.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoetas-webservices%2Fsoap-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoetas-webservices%2Fsoap-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoetas-webservices%2Fsoap-client/lists"}