georgo/wsdl-creator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

georgo/wsdl-creator

Composer 安装命令:

composer require georgo/wsdl-creator

包简介

PHP WSDL creator using PHPdoc (annotations, reflections).

README 文档

README

Build Status Scrutinizer Quality Score Coverage Status Dependency Status

Introduction

WSDL creator allows generating WSDL documents based on PHP classes using annotations and reflection mechanism. This generator also give possibilty to generating overview methods and parameters with SOAP examples used in WSDL.

Support: >= PHP5.5.

Installation

To install wsdl-creator at your project use composer.

###Create new project:

composer.phar create-project georgo/wsdl-creator myproject

###or add to the composer.json file:

require: {
	"georgo/wsdl-creator": "1.*"
}

Configuration

To start working with creator you must create new WSDLCreator object and define for him:

  • class to generate WSDL
  • SOAP server location
  • documnet namespace.
$wsdl = new WSDL\WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
$wsdl->setNamespace("http://foo.bar/");

SOAP server must be created in location specified in WSDLCreator.

$server = new SoapServer(null, array(
    'uri' => 'http://localhost/wsdl-creator/ClassName.php'
));
$server->setClass('ClassName');
$server->handle();

To render XML use method renderWSDL. To properly load generator classes use composer loader which is in vendor/autoload.php.

Full configutaion listing:

require_once 'vendor/autoload.php';

use WSDL\WSDLCreator;

if (isset($_GET['wsdl'])) {
    $wsdl = new WSDL\WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
    $wsdl->setNamespace("http://foo.bar/");
    $wsdl->renderWSDL();
    exit;
}

$server = new SoapServer(null, array(
    'uri' => 'http://localhost/wsdl-creator/ClassName.php'
));
$server->setClass('ClassName');
$server->handle();

Now if we try call address http://localhost/wsdl-creator/ClassName.php?wsdl you recive WSDL document.

Define web service method

To define is a web service method you must use @WebMethod annotation.

Simple type

Simple types are described here.

###Usage

/**
* @param string $name
*/

So you type @param next type one of simple types (string) after name of variable ($name).

You can also use arrays of the simple types.

###Usage

/**
* @param string[] $names
*/

In input parameter now you must define what type of array you pass (string[]).

###Example

SimpleTypeExample

###Annotations

  • @desc Method description
  • @param type $varialbe_name
  • @return type $return

Wrapper type

Wrapper types are user defined clases which you can generate WSDL complex types.

###Usage

/**
* @param wrapper $user @className=User
*/

You must define class User with public fields and doc comments which contains field type as example:

class User
{
	/**
	* @type string
	*/
	public $name;
	/**
	* @type int
	*/
	public $age;
}

This mechanism use reflection, i.e. User class must be visible to the generated class - possible use namespaces (\Namespace\To\User).

You can define arrays of wrappers.

###Usage

/**
* @return wrapper[] $users @className=User
*/

This annotation will generate array of users.

###Example

WrapperTypeExample

###Annotations

  • @desc Method description
  • @param wrapper[] @className=ClassName
  • @return wrapper @className=\Namespace\To\ClassName

Object type

You can dynamically create object at runtime. Use object parameter type.

###Usage

/**
* @param object $info @string=$name @int=$age
*/

This annotation create complex type with name and age elements.

Also you can wrapp classes in object.

###Usage

/**
* @return object $userNameWithId @(wrapper $user @className=User) @int=$id
*/

Above example will return UserNameWithId object which contains pointer to User complex type and int type.

Another option is creating array of objects.

###Usage

/**
* @param object[] $payments @float=$payment @string=$user
*/

This annotation creata array of objects with payment and user on each element of array.

###Example

ObjectTypeExample

###Additional info

In object you can use array of wrappers and array of simple types.

###Annotations

  • @desc Method description
  • @param object $object @type1=$name1 @type2=$name2
  • @param object $object @(wrapper $nameWrapper @className=User) @type1=$name1
  • @param object[] $object @type1[]=$name1
  • @return

Service overview

You can generate service overview through renderWSDLService method. This show all infos about method and parameters used in service with sample SOAP request.

###Example

Wrapper image

Styles

By default, the WSDLCreator will generate WSDLs using the rpc/literal binding style.

To specify rpc/encoded or a wrapped document/literal binding style, set the binding style on the WSDLCreator object.

$wsdl = new WSDL\WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
@wsdl->setBindingStyle(new WSDL\XML\Styles\RpcEncoded());
$wsdl->setNamespace("http://foo.bar/");

When specifying the wrapped document/literal binding style, you can use WSDL\DocumentLiteralWrapper to automatically wrap the returning value in an appropriate wrapped object.

require_once 'vendor/autoload.php';

use WSDL\DocumentLiteralWrapper;
use WSDL\WSDLCreator;
use WSDL\XML\Styles\DocumentLiteralWrapped;

if (isset($_GET['wsdl'])) {
    $wsdl = new WSDLCreator('ClassName', 'http://localhost/wsdl-creator/ClassName.php');
    @wsdl->setBindingStyle(new DocumentLiteralWrapped());
    $wsdl->setNamespace("http://foo.bar/");
    $wsdl->renderWSDL();
    exit;
}

ini_set('soap.wsdl_cache_enabled', '0');
$server = new SoapServer('http://localhost/wsdl-creator/ClassName.php?wsdl', array(
	'style' => SOAP_DOCUMENT,
	'use' => SOAP_LITERAL,
));
$server->setObject(new DocumentLiteralWrapped(new ClassName()));
$server->handle();

georgo/wsdl-creator 适用场景与选型建议

georgo/wsdl-creator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.8k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「annotations」 「generator」 「php」 「soap」 「wsdl」 「creator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 georgo/wsdl-creator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 georgo/wsdl-creator 我们能提供哪些服务?
定制开发 / 二次开发

基于 georgo/wsdl-creator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 50
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-14