-
Notifications
You must be signed in to change notification settings - Fork 0
ExampleUsage
This page describes how to use the wsdl2php cli executable and the wsdl2phpgenerator class library.
The cli client is a shell script that uses #!/usr/bin/php.
If you are on windows remove that first line and call the program using php wsdl2php instead of ./wsdl2php. I’m going to use ./wsdl2php through this text.
The code have been changed to use a stand alone php file(generate.php) for the generation. The ./wsdl2php shortcut does still work, but if you are on windows or have installed PHP somewhere else use:
/path/to/php generate.php -i file -o dir
The client takes some parameters, two of them are required. The input file and output directory.
All parameters can be submitted using the “real” flag and a alias, if it exists. All paramers can be boolean (just the flag) or strings (if you pass something along). Parameters can be written both -f param and -f=param.
Boolean parameters can be grouped like -xyz.
Reqiured parameters
- -i, —input The input file, must be a valid wsdl file
- -o, —output The output directory, is created if it does not exist and permission exists
Optional parameters
- -e, —classExists, —exists This flag tells the generator to surround all classes with if(!class_exists()) statements
- -t, —noTypeConstructor Tells the generator that no type constructor should be generated. Without this a standard constructor with all variables is generated.
- -s, —singeFile Tells the generator to put all classes in the same file. The file is named after the service.
- -n, —namespace The name of the namespace to use if any. Requires php 5.3(or greater) on the server you are going to run this on.
- -c This flag should be a comma separated list of class names to generate. Used to only generate selected classes from the wsdl.
- -p, —prefix The prefix to use for the generated classes
- -q, —suffix The suffix to use for the generated classes
- -h, —help, —h Show the help section
- —singleElementArrays This flag tells the generator to insert the feature for single element arrays in the options array in the constructor of the service
- —xsiArrayType This flag tells the generator to insert the feature for the xsi array type in the options array in the constructor of the service
- —waitOneWayCalls This flag tells the generator to insert the feature for wait one way calls in the options array in the constructor of the service
- —cacheNone This flag tells the generator to insert the no cache flag in the options array in the constructor of the service
- —cacheDisk This flag tells the generator to insert the cache to disk flag in the options array in the constructor of the service
- —cacheMemory This flag tells the generator to insert the cache to memory flag in the options array in the constructor of the service
- —cacheBoth This flag tells the generator to insert the cache to disk and memory flag in the options array in the constructor of the service
- —gzip Enables gzip compression of the wsdl file
More information about the soap class http://se2.php.net/manual/en/soapclient.soapclient.php.
Here are some examples:
- :~/wsdl2php$ ./wsdl2php -i http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl -o /tmp/NDFD
- :~/wsdl2php$ ./wsdl2php —input http://www.ncbi.nlm.nih.gov/entrez/eutils/soap/v2.0/eutils.wsdl —output /tmp/ncbi/
- :~/wsdl2php$ ./wsdl2php -i http://soap.genome.jp/KEGG.wsdl -o /tmp/kegg —namespace kegg
- :~/wsdl2php$ ./wsdl2php -se -i http://soap.bind.ca/wsdl/bind.wsdl -o /tmp/bind
The class library is pretty straight forward to use, the class Wsdl2PhpGenerator (\Wsdl2Php\Generator in php5.3) is the class that does the heavy lifting of loading, parsing the wsdl file, generating the source code for the classes and saving the generated code when generation is complete.
It has a couple of classes to help with this.
The phpSource folder/namespace contains functionality for loading data about classes, functions, variables and phpdoc comments. They do also contain the functionality to render the data as source code. Should be pretty straight forward.
The Wsdl2PhpConfig class is a class used to normalize the input to the Generator class. Contains all variables the Generator can use.
The Wsdl2PhpValidator class contains functions for validating the generated php code.
There are also two Exception classes used to group exceptions.
This is the php 5.2 version, for php 5.3 use Wsdl2Php\Generator and Wsdl2Php\Config instead.
Example code for one of the examples from the cli Example:
include_once('Wsdl2PhpGenerator.php');
-
$classExists = false;
$noTypeConstructor = false;
$singleFile = false;
$inputFile = 'http://soap.genome.jp/KEGG.wsdl';
$classNames = 'SSDBRelation,MotifResult';
$outputDir = '/tmp/kegg';
$namespaceName = 'kegg';
$prefix = 'Prefix';
$suffix = 'Suffix';
$optionsArray = array('SOAP_SINGLE_ELEMENT_ARRAYS', 'SOAP_USE_XSI_ARRAY_TYPE');
$wsdlCache = 'WSDL_CACHE_BOTH';
$gzip = 'SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP'
-
$config = new Wsdl2PhpConfig($inputFile, $outputDir, $singleFile, $classExists, $noTypeConstructor, $namespaceName, $optionsArray, $wsdlCache, $gzip, $classNames, $prefix, $suffix);
-
$generator = new Wsdl2PhpGenerator();
$generator->generate($config);
This parses the output file and puts the two classes(SSDBRelation and MotifResult) in the output dir.