webair-srl/phpwsdl2
Composer 安装命令:
composer require webair-srl/phpwsdl2
包简介
PhpWSDL2 - Modern PHP WSDL/SOAP WebService Library with Multiple Protocol Support
README 文档
README
PhpWSDL2 is a modern PHP library for creating WSDL/SOAP web services with support for multiple protocols including SOAP, JSON, REST, XML-RPC, and HTTP. It provides automatic service description generation, client code generation, and comprehensive documentation features.
Features
- 🚀 Multiple Protocol Support: SOAP, JSON, REST, XML-RPC, HTTP
- 📝 Automatic Documentation: HTML service descriptors and PDF generation
- 🔧 Client Code Generation: Generate clients for PHP, JavaScript, and more
- 🎯 Modern PHP: Built for PHP 8.2+ with strict typing
- 📦 Framework Independent: Works with any PHP application
- 🔍 Reflection-Based: Automatic service discovery using PHP reflection
- 🎨 Professional Output: Clean, well-formatted documentation and clients
Installation
Install PhpWSDL2 via Composer:
composer require webair-srl/phpwsdl2
TCPDF 7 generates its font assets in the consuming project. Because Composer does not
execute scripts declared by dependencies, add the following script to the root
composer.json of the application that installs PhpWSDL2:
{
"scripts": {
"tcpdf-fonts": [
"[ ! -d vendor/tecnickcom/tc-lib-pdf-font ] || [ -f vendor/tecnickcom/tc-lib-pdf-font/target/fonts/core/helvetica.json ] || make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts"
],
"post-install-cmd": ["@tcpdf-fonts"],
"post-update-cmd": ["@tcpdf-fonts"]
}
}
For an existing installation, initialize the fonts once with:
make -C vendor/tecnickcom/tc-lib-pdf-font deps fonts
Quick Start
1. Create Your Service Class
<?php class MyWebService { /** * Add two numbers * * @param int $a First number * @param int $b Second number * @return int Sum of the numbers */ public function add(int $a, int $b): int { return $a + $b; } /** * Get user information * * @param string $username Username to lookup * @return string JSON encoded user data */ public function getUser(string $username): string { return json_encode([ 'username' => $username, 'email' => $username . '@example.com', 'created' => date('Y-m-d H:i:s') ]); } }
2. Create Your Service Endpoint
<?php // service.php require_once 'vendor/autoload.php'; use PhpWSDL2\PhpWSDL2; // Create and configure the service $service = PhpWSDL2::create( MyWebService::class, 'https://example.com/service.php', 'MyWebService' ); // Handle all incoming requests $service->handleRequest();
3. Access Your Service
- Service Description:
https://example.com/service.php - WSDL:
https://example.com/service.php?WSDL - PDF Documentation:
https://example.com/service.php?PDF - REST Call:
https://example.com/service.php/add/5/3/
Client Downloads
PhpWSDL2 automatically generates client code for multiple languages and protocols:
| Client Type | URL Parameter | Description |
|---|---|---|
| PHP SOAP | ?PHPSOAPCLIENT |
PHP SOAP client class |
| PHP JSON | ?PHPJSONCLIENT |
PHP JSON client class |
| JavaScript JSON | ?JSJSONCLIENT |
JavaScript JSON client |
| JavaScript (Minified) | ?JSJSONCLIENT&min |
Minified JavaScript client |
| PHP XML-RPC | ?PHPRPCCLIENT |
PHP XML-RPC client class |
| PHP HTTP | ?PHPHTTPCLIENT |
PHP HTTP client class |
| PHP REST | ?PHPRESTCLIENT |
PHP REST client class |
Usage Examples
Using Generated PHP SOAP Client
<?php require_once 'MyWebService_SOAP_Client.php'; try { $client = new MyWebService_SOAP_Client(); $result = $client->add(5, 3); echo "Result: " . $result; // Result: 8 } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
Using Generated JavaScript Client
var client = new MyWebService_JSON_Client(); // Synchronous call try { var result = client.add(5, 3); console.log("Result:", result); } catch (e) { console.error("Error:", e.message); } // Asynchronous call client.add(5, 3, function(result, data) { if (result.error) { console.error("Error:", result.error); } else { console.log("Success:", result); } });
REST API Calls
# GET request curl "https://example.com/service.php/add/5/3/" # Returns JSON response {"result": 8}
JSON API Calls
# POST request with JSON data curl -X POST "https://example.com/service.php" \ -d "json={\"call\":\"add\",\"param\":[5,3]}" # Returns JSON response {"result": 8}
Advanced Configuration
Custom SOAP Options
<?php use PhpWSDL2\PhpWSDL2; $service = new PhpWSDL2(MyWebService::class, 'https://example.com/service.php'); // Configure SOAP options $service->getServer()->setSoapOptions([ 'cache_wsdl' => WSDL_CACHE_MEMORY, 'soap_version' => SOAP_1_2 ]); $service->handleRequest();
Programmatic Usage
<?php use PhpWSDL2\PhpWSDL2; $service = new PhpWSDL2(MyWebService::class, 'https://example.com/service.php'); // Generate service descriptor HTML $html = $service->getServiceDescriptor(); // Generate WSDL $wsdl = $service->generateWsdl(); // Get service methods $methods = $service->getServiceMethods(); // Generate specific client $soapClient = $service->getClientGenerator()->generate('soap', 'php');
Documentation Features
HTML Service Descriptor
PhpWSDL2 automatically generates professional HTML documentation that includes:
- Service endpoint and WSDL URLs
- Complete method listings with parameters and return types
- REST endpoint URLs for each method
- Download links for all client types
- Professional styling similar to phpWSDL
PDF Documentation
Generate PDF documentation with:
- Complete service description
- Method signatures and documentation
- Parameter details and return types
- REST endpoint information
Protocol Support
SOAP
- Full WSDL 1.1 and 2.0 support
- Automatic WSDL generation
- Complex type support via reflection
REST
- Clean URL routing (
/method/param1/param2/) - JSON response format
- GET request support
JSON
- POST parameter:
json={"call":"method","param":["arg1","arg2"]} - Structured JSON responses
- Error handling with proper HTTP status codes
XML-RPC
- Standard XML-RPC protocol support
- Automatic method registration
- Fault handling
HTTP
- Simple POST/GET parameter support
callparameter for method nameparamarray for arguments
Requirements
- PHP 8.2 or higher
- ext-soap
- ext-json
- ext-reflection
- tecnickcom/tcpdf ^7.0 (for PDF generation)
makeand outbound network access during font asset initialization
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Credits
PhpWSDL2 is developed by tQuadra and is inspired by the original phpWSDL library, modernized for PHP 8+ with additional features and improved architecture.
Support
webair-srl/phpwsdl2 适用场景与选型建议
webair-srl/phpwsdl2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rpc」 「json」 「http」 「rest」 「client」 「soap」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webair-srl/phpwsdl2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webair-srl/phpwsdl2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webair-srl/phpwsdl2 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Microservice RPC through message queues.
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 52
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-31