Class to wsdl php

Wsdl2phpgenerator

Simple utility and class library for generating php classes from a wsdl file.

wsdl2phpgenerator

Latest Stable Version Code Coverage Scrutinizer Quality Score Dependency Status

Simple WSDL to PHP classes converter. Takes a WSDL file and outputs class files ready to use.

New major version: 3.0

A new major version of wsdl2phpgenerator has recently been released: 3.0.

This introduces changes to both configuration and generated code. The changes makes it more flexible to use, easier to include in other projects, promotes contributions and reduces maintenance.

Contributors

Pull requests are very welcome. Please read our guidelines for contributing.

Mailing list

Installation

Add wsdl2phpgenerator to your Composer project:

composer require wsdl2phpgenerator/wsdl2phpgenerator

The project will also be available as a command line application which can be downloaded as a phar file.

Usage

To generate classes create a Generator instance and pass it a Config instance.

$generator = new \Wsdl2PhpGenerator\Generator(); $generator->generate( new \Wsdl2PhpGenerator\Config(array( 'inputFile' => 'input.wsdl', 'outputDir' => '/tmp/output' )) );

After generating the code then configure your existing autoloader accordingly. The generated code also comes with a simple autoload.php file which can be included directly. This registers a simple autoloader for the generated classes.

Example usage

The following example will generate code from a web service, load the generated classes, call the web service and return the result over the course of a single process.

$generator = new \Wsdl2PhpGenerator\Generator(); $generator->generate( new \Wsdl2PhpGenerator\Config(array( 'inputFile' => 'http://www.webservicex.net/CurrencyConvertor.asmx?WSDL', 'outputDir' => '/tmp/CurrencyConverter' )) ); require '/tmp/CurrencyConverter/autoload.php'; // A class will generated representing the service. // It is named after the element in the WSDL and has a method for each operation. $service = new \CurrencyConvertor(); $request = new \ConversionRate(\Currency::USD, \Currency::EUR); $response = $service->ConversionRate($request); echo $response->getConversionRateResult();

Note that this is not recommended usage. Normally code generation and web services calls will be two separate processes.

Options

The generator supports a range of options which can be set in the configuration.

inputFile

The path or url to the WSDL to generate classes from.

outputDir

The directory to place the generated classes in. It will be created if it does not already exist.

namespaceName

The namespace to use for the generated classes. If not set classes will be generated without a namespace.

Example usage

The following configuration will place generated code from the CDYNE Weather web service under the CDyne\Weather namespace:

$generator = new \Wsdl2PhpGenerator\Generator(); $generator->generate( new \Wsdl2PhpGenerator\Config(array( 'inputFile' => 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl', 'outputDir' => '/tmp/weather' 'namespaceName' => 'CDyne\Weather', )) );

classNames

A comma-separared list or array of class names to generate. All other classes in the WSDL will be ignored.

Example usage

The following configuration will only generate AmazonEC2 and CopyImageType classes from the Amazon EC2 webservice.

$generator = new \Wsdl2PhpGenerator\Generator(); $generator->generate( new \Wsdl2PhpGenerator\Config(array( 'inputFile' => 'https://s3.amazonaws.com/ec2-downloads/2013-10-01.ec2.wsdl', 'outputDir' => '/tmp/amazon' 'classNames' => 'AmazonEC2, CopyImageType', )) );

sharedTypes

If enabled this makes all types with the same identify use the same class and only generate it once. The default solution is to prepend numbering to avoid name clashes.

constructorParamsDefaultToNull

If enabled this sets the default value of all parameters in all constructors to null . If this is used then properties must be set using accessors.

soapClientClass

The base class to use for generated services. This should be a subclass of the PHP SoapClient .

Examples of third party SOAP client implementations which can be used:

Note that is is the responsibility of the surrounding code to ensure that the base class is available during code generation and when calling web services.

Example usage

The following configuration will use the BeSimple SOAP client as base class:

$generator = new \Wsdl2PhpGenerator\Generator(); $generator->generate( new \Wsdl2PhpGenerator\Config(array( 'inputFile' => 'input.wsdl', 'outputDir' => '/tmp/output' 'soapClientClass' => '\BeSimple\SoapClient\SoapClient' )) );

soapClientOptions

An array of configuration options to pass to the SoapClient. They will be used when accessing the WSDL to generate the code and as defaults for subsequent requests to the SOAP service. The PHP documentation has a list of supported options.

The list of options for the client can be extended by using more advanced SoapClient implementations.

Note that wsdl2phpgenerator expects the features option to contain SOAP_SINGLE_ELEMENT_ARRAYS . This ensures that type hints are consistent even if sequences only contain one element. If the features option is set explicitly in soapClientOptions the SOAP_SINGLE_ELEMENT_ARRAYS must also be added explicitly.

Example usage

The following configuration will enable basic authentication and set the connection timeout to 60 seconds.

$generator = new \Wsdl2PhpGenerator\Generator(); $generator->generate( new \Wsdl2PhpGenerator\Config(array( 'inputFile' => 'input.wsdl', 'outputDir' => '/tmp/output' 'soapClientOptions' => array( 'authentication' => SOAP_AUTHENTICATION_BASIC, 'login' => 'username', 'password' => 'secret' 'connection_timeout' => 60, )) );

Versioning

This project aims to use semantic versioning. The following constitutes the public API:

  • \Wsdl2PhpGenerator\GeneratorInterface
  • \Wsdl2PhpGenerator\ConfigInterface
  • Generated code

Backwards incompatible changes to these means that the major version will be increased. Additional features and bug fixes increate minor and patch versions.

Wsdl2phpgenerator maintained by wsdl2phpgenerator

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Generate WSDL files from PHP classes

License

dragosprotung/php2wsdl

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Create WSDL files from PHP classes.

$ composer require php2wsdl/php2wsdl
$class pl-s">Vendor\\MyClass"; $serviceURI pl-s">https://www.myservice.com/soap"; $wsdlGenerator = new PHP2WSDL\PHPClass2WSDL($class, $serviceURI); // Generate the WSDL from the class adding only the public methods that have @soap annotation. $wsdlGenerator->generateWSDL(true); // Dump as string $wsdlXML = $wsdlGenerator->dump(); // Or save as file $wsdlXML = $wsdlGenerator->save('foo/example.wsdl');

If you discover any security related issues, please email instead of using the issue tracker.

The MIT License (MIT). Please see License File for more information.

About

Generate WSDL files from PHP classes

Источник

Automatically Generating WSDL

As mentioned previously, current Web Services almost always use WSDL (Web Services Description Language) to describe the operations and parameters of your service. Writing WSDL files manually is a real pain and error-prone, but most serious Web Services implementations for PHP can automatically create WSDL.

For this tutorial, we use a library, PHP2WSDL , that can automatically generate WSDL from PHP classes and methods. To use PHP2WSDL library, you need to install it using Composer:

composer require php2wsdl/php2wsdl

Next, you need to create a PHP class that defines your web service. For example, you can create a file called Mathematics.php with the following code:

_sum($a, $b); > /** * Subtract two numbers * @soap * @param float $a * @param float $b * @return float */ public function subtract($a, $b) < return $a - $b; >/** * Multiply two numbers * @soap * @param float $a * @param float $b * @return float */ public function multiply($a, $b) < return $a * $b; >protected function _sum($a, $b) < return $a + $b; >>

The PHP2WSDL library uses the PHPDoc comments to understand the types and names of the parameters and return values of each method. You must also use annotation @soap for all public methods (required by the library).

Next, create a PHP script that will use the PHP2WSDL library to generate the WSDL file. For example, you can create a file called wsdl_maker.php with the following code:

generateWSDL(true); // Save file to the disk $wsdlGenerator->save('Mathematics.wsdl');

Running the wsdl_make.php script from the browser will create the Mathematics.wsdl file in the current directory. You can open this file with any text editor or XML viewer and see the generated WSDL.

        Add two numbers   Subtract two numbers   Multiply two numbers                                               

Communicating with Servers:

Источник

Читайте также:  Полная таблица символов html
Оцените статью