定制 jelix/webservice-helper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

jelix/webservice-helper

Composer 安装命令:

composer require jelix/webservice-helper

包简介

To generate a WSDL content from classes

README 文档

README

This is a fork of Webservice helper from David Kingma. Original sources come from www.jool.nl/webservicehelper/. Original author : David Kingma davidjoolnl

Maintainer of this fork: Laurent Jouanneau web site: https://github.com/jelix/webservice-helper

What does the webservice helper?

The webservice helper does what the name says: helping you making a php class available as webservice. It generates the documentation, the webservice description file (WSDL) and handles errorhandling. It consists of three parts:

  • extension of the PHP reflection classes to also parse the comments for information on parameter info and return values. The documentation and WSDL are generated from these classes.(see also documentation.php as an example)
  • extension to the PHP SOAP implementation. It catches all normal exceptions and allows typehints in the webservice methods. (ie. saveContact(contact $contact))

Installation

Use Composer to install the library. Package name: jelix/webservice-helper.

If you don't want to use Composer, you can copy the content of the source code (all needed classes are into lib/), and you must create an autoloader (like in example/common.php or you must include all classes.

Manual

So how do you create your own webservice. As an example we create a webservice to add and show contacts. First you create a class called contactManager in the /example/data_objects with the public functions getContacts(), saveContact(contact $contact) and newContact(). To let the Webservice helper know what the parameters and return values of each method are we put a comment in front of each method specifying the parameters and return types. For example:

/**
 * This method saves the given contact
 * @return contact[] Array with all the contacts
 */
 public function getContacts(){}

/**
 * This method saves the given contact
 * @param contact The contact to save
 * @return void
 */
 public function saveContact(contact $contact){}

/**
 * This method saves the given contact
 * @return contact A new contact template
 */
 public function newContact(){}

/**
 * Gets the current contact list as associative array
 * @return contact[=>]  keys are contact name
 */
public function	getContactsAsAssoc() {}

We used the contact type as a return value for newContact() and getContacts() so we need to define what a contact looks like. For that we create a class called contact:

class contact{
	/** @var string */
	public $name;
	/** @var string */
	public $address;
}

Since string is (just as boolean and int) a known datatype we don't need to specify it any further.

The last thing we need to do to finish our webservice is to tell the webservice that de contactManager class is an allowed webservice and that contact is an allowed data- structure (for documentation purpose and classmap). In the config.php you add "contactmanager" to the WSClasses array and add "contact" to the WSStructures array.

You can now view the service documentation at /doc/documentation.php and the wsdl at /example/service.php?class=contactManager&wsdl

Note about associative array containing objects: if the soap server defines a classmap ('classmap' option to SoapServer in PHP), objects are wrapped into SoapVal objects, else they are simple stdClass objects.

FAQ

  • My function doesn't showup in the documentation nor the WSDL file? Please check if it's a public function and it doesn't start with __

  • It doesn't work!

    • Do you see any warnings in the generated documentation? Fix them
    • Check case sensitivity of class names
    • Did you check the javascript console to see if anything goes wrong?
    • Tried cleaning the wsdl cache in the WSDL cache directory?
    • Did you check the WSDL url in the client?
  • Can I use the webservice helper in my own project? Yes you can use it under the terms of LGPL 2.1

  • Can I contribute?

Yes, open an issue and/or a PR on https://github.com/jelix/webservice-helper

Example and unit tests

See tests/README.md

jelix/webservice-helper 适用场景与选型建议

jelix/webservice-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.84k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2014 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 jelix/webservice-helper 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1
  • 更新时间: 2014-11-03