gemorroj/wsdltophp

此包已被废弃且不再维护。未建议替代包。

根据WSDL生成分层PHP类

dev-master 2013-09-06 10:28 UTC

This package is auto-updated.

Last update: 2022-02-01 12:28:46 UTC


README

根据WSDL生成PHP类

此包允许使用PHP类编程式发送请求到SOAP服务。为此,此类为每个请求、每个请求参数和每个请求响应生成每个类。每个类都存储在分层文件夹/子文件夹系统中。然后抽象SOAP客户端,您只需处理代表WSDL类型的对象。

生成的类根据phpDocumentor完全文档化,并带有php doc块。它从WSDL及其模式检索文档标签,并定义使用的方法、返回类型、参数类型等。

在此处在线测试此库:http://www.wsdltophp.com/

在此处在线阅读PHPDoc:http://phpdoc.wsdltophp.com/

Donate

教程

了解如何使用此代码的最好方法是首先查看位于根目录的samples-generator.php文件。此文件显示了如何基本实例化WsdlToPhpGenerator类。此类有选项可以改变其行为。

让我们看看如何基本使用它

/* Create an instance of the generator with the WSDL from which to generate the package */
$w = new WsdlToPhpGenerator('https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl');
/* Call after the instanciation or before a new generation in order the modify the generator behaviour */
// Activate the autoload file generation
WsdlToPhpGenerator::setOptionGenerateAutoloadFile(true);
// Activate the generation and the use of the generic WsdlClass from which each generated class will inherit
WsdlToPhpGenerator::setOptionGenerateWsdlClassFile(true);
// Allows to get the SOAP response as a parameter of the generated PHP response class or not
// It depends on the SOAP Web service, some returns the Response object, others return the the data of the response object
WsdlToPhpGenerator::setOptionResponseAsWsdlObject(false);
// Very usefull if you're not familiartr with SOAP, it generates a sample file that contains all the possible
// methods provided by the SOAP Web service and first parameters level
WsdlToPhpGenerator::setOptionGenerateTutorialFile(true);
// Depending on the SOAP Web service, you may have to send an array, mySoapMethod(array('param_1'=>'value_1','param_2'=>'value_2')),
// or send parameters as the method parameters, mySoapMethod('value_1','value_2')
WsdlToPhpGenerator::setOptionSendArrayAsParameter(true);
// Used for certain SOAP Web service such as certain Microsoft Application Web service, you may have to send the parameter as
// mySoapMethod(array('parameters'=>array('param_1'=>'value_1','param_2'=>'value_2')))->parameters and get the response in the parameters response property
WsdlToPhpGenerator::setOptionSendParametersAsArray(false);
// Depending on your preferences, classes are generated under folders according to their name. The name is splitted at each upper character
// so each classes is contained by folders or not if you choose WsdlToPhpGenerator::OPT_CAT_NONE_NAME
WsdlToPhpGenerator::setOptionCategory(WsdlToPhpGenerator::OPT_CAT_START_NAME);
// Depending on your preferences, classes are generated under subfolders according to their name. The name is splitted at each upper character
// so each classes is contained by sub folders or not if you choose WsdlToPhpGenerator::OPT_SUB_CAT_NONE_NAME
WsdlToPhpGenerator::setOptionSubCategory(WsdlToPhpGenerator::OPT_SUB_CAT_END_NAME);
// Depending on your preferences, SOAP operations are gathered in mutliple classes as methods according to their name. The name is splitted at each upper character
// so each operation is contained by classes named with the start of the operation name (WsdlToPhpGenerator::OPT_GATH_METH_START_NAME) or the end (WsdlToPhpGenerator::OPT_GATH_METH_END_NAME)
WsdlToPhpGenerator::setOptionGatherMethods(WsdlToPhpGenerator::OPT_GATH_METH_START_NAME);
// Add comment to each generated file to retrieve them in the PHP Documentation
WsdlToPhpGenerator::setOptionAddComments(array(
													'date'=>date('Y-m-d'),
													'author'=>'Mikaël DELSOL',
													'version'=>1));
// Launch the generation indicating the name to use to generated the classes and the destination directory
$w->generateClasses('PayPal',dirname(__FILE__) . '/PayPal/');
// After the generation, you can analyse the audit data collected during the generation by calling the method getAudit() as below
// It returns an array with lots of informations about time spent at each generation step
print_r($w->getAudit());

欢迎提出改进建议。