php-soap / wsdl-reader
A WSDL reader in PHP
Fund package maintenance!
Open Collective
Installs: 708 447
Dependents: 4
Suggesters: 0
Security: 0
Stars: 18
Watchers: 1
Forks: 4
Open Issues: 0
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-dom: *
- azjezz/psl: ^3.0
- goetas-webservices/xsd-reader: ^0.4.8
- php-soap/engine: ^2.13
- php-soap/wsdl: ^1.10
- php-soap/xml: ^1.8.0
- symfony/console: ^5.4 || ^6.0 || ^7.0
- veewee/xml: ^3.0
- webmozart/assert: ^1.11
Requires (Dev)
- php-soap/engine-integration-tests: ^1.5.0
- php-standard-library/psalm-plugin: ^2.2
- phpunit/phpunit: ^10.1
- psalm/plugin-symfony: ^5.0
- symfony/var-dumper: ^6.1 || ^7.0
- vimeo/psalm: ^5.26
README
This package provides tools for reading WSDL files and to converting them to metadata that will be used in other parts of the php-soap packages.
Want to help out? 💚
Want more information about the future of this project? Check out this list of the next big projects we'll be working on.
Installation
composer require php-soap/wsdl-reader
Example usage
use Soap\Engine\Metadata\Model\Method; use Soap\Engine\Metadata\Model\Type; use Soap\Wsdl\Loader\FlatteningLoader; use Soap\Wsdl\Loader\StreamWrapperLoader; use Soap\WsdlReader\Formatter\ShortMethodFormatter; use Soap\WsdlReader\Formatter\ShortTypeFormatter; use Soap\WsdlReader\Metadata\Wsdl1MetadataProvider; use Soap\WsdlReader\Wsdl1Reader; // Reading WSDL $loader = new FlatteningLoader(new StreamWrapperLoader()); $wsdl = (new Wsdl1Reader($loader))($wsdlLocation); // Parsing metadata $metadataProvider = new Wsdl1MetadataProvider($wsdl); $metadata = $metadataProvider->getMetadata(); // Processing collected info: var_dump($metadata->getMethods(), $metadata->getTypes());
As shown above, parsing the WSDL is done in phases:
- Select any loader to load the content of the WSDL. Tip: make sure to flatten it!
- Reading raw WSDL XML into value objects and XSD schema.
- Converting this WSDL to usable metadata
This gives you the flexibility in all different layers:
- You can specify how a WSDL will be loaded.
- You can use the WSDL classes of this package to run your own data lookups/manipulations.
- You can use the provided metadata to run your own data lookups/manipulations.
- ...
Readers
This package provides some configurable WSDL readers. This gives you some flexibility in what version of WSDL is being parsed, what SOAP version you want to use, ...
WSDL1 and 1.1
use Soap\WsdlReader\Locator\ServiceSelectionCriteria; use Soap\WsdlReader\Metadata\Wsdl1MetadataProvider; use Soap\WsdlReader\Model\Definitions\SoapVersion; use Soap\WsdlReader\Wsdl1Reader; $wsdl = (new Wsdl1Reader($loader))($wsdlLocation); $criteria = ServiceSelectionCriteria::defaults() ->withPreferredSoapVersion(SoapVersion::SOAP_12); $metadataProvider = new Wsdl1MetadataProvider($wsdl, $criteria);
The WSDL1Reader accepts a ParserContext
. You don't have to configure it since it falls back to defaults.
But if you want to configure things like known XSD schema locations, that would be the place to go!
Once the WSDL1 file has been read, it will try to find a SOAP 1.2 service from your WSDL file. This service will be converted into metadata you, as a human, can understand.
You can apply additional service selection criteria that will be used to find the SOAP service you prefer. By default,
- The selection criteria allows any SOAP service. You can disable e.g. the HTTP-based SOAP services.
- No SOAP version is preferred. The first SOAP service the system detects, will be selected. But you can specify a specific soap version as well.
- You can specify a specific service name. If you don't, the first service will be selected.
- You can specify a specific port name. If you don't, the first port will be selected.
WSDL2
Not implemented yet!
Console
This package extends the WSDL CLI Tools that are provided by the WSDL package. It provides these additional commands:
$ ./vendor/bin/wsdl Available commands: inspect Inspects WSDL file. inspect:method Inspects a method of a WSDL file. inspect:type Inspects types from WSDL file.
Listing all contents
./vendor/bin/wsdl inspect your.wsdl
Method details
./vendor/bin/wsdl inspect:method your.wsdl SomeMethodName
Type details
./vendor/bin/wsdl inspect:type your.wsdl SomeType
Custom WSDL Loader
By default, all CLI tools use the StreamWrapperLoader.
All CLI tools have a --loader=file.php
option that can be used to apply a custom WSDL loader.
This can be handy if your WSDL is located behind authentication or if you want to get control over the HTTP level.
Example custom PHP loader:
<?php use Soap\Wsdl\Loader\FlatteningLoader; use Soap\Wsdl\Loader\StreamWrapperLoader; return new FlatteningLoader( StreamWrapperLoader( stream_context_create([ 'http' => [ 'method' => 'GET', 'header'=> sprintf('Authorization: Basic %s', base64_encode('username:password')), ], ]) ) );