rogervila/laravel-soap-server
Composer 安装命令:
composer require rogervila/laravel-soap-server
包简介
PHP Laravel SOAP Server
关键字:
README 文档
README
Laravel SOAP Server
About
Laravel SOAP Server is a package that simplifies the creation of SOAP web services in Laravel. It provides a base setup for developing SOAP services, including WSDL generation and request handling.
Installation
To install the package, use Composer:
composer require rogervila/laravel-soap-server
Usage
Defining a Service
Create a service class that will handle the SOAP requests. For example, a UserService class:
namespace App\Services; use stdClass; class UserService { public function createUser(stdClass $request): array { // Handle the request and return a response } }
Creating a WSDL View
Create a Blade view for the WSDL definition. For example, resources/views/wsdl.blade.php:
<?xml version="1.0" encoding="UTF-8"?> <definitions name="UserService" targetNamespace="{{ url()->current() }}" xmlns:tns="{{ url()->current() }}" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <!-- Types definition --> <types> <xsd:schema targetNamespace="{{ url()->current() }}"> <!-- CreateUser Request Type --> <xsd:element name="CreateUserRequest"> <xsd:complexType> <xsd:sequence> <xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="email" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> <!-- CreateUser Response Type --> <xsd:element name="CreateUserResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="status" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="message" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="data" minOccurs="0" maxOccurs="1"> <xsd:complexType> <xsd:sequence> <xsd:element name="id" type="xsd:integer"/> <xsd:element name="name" type="xsd:string"/> <xsd:element name="email" type="xsd:string"/> <xsd:element name="created_at" type="xsd:dateTime"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </types> <!-- Message definitions --> <message name="CreateUserInput"> <part name="parameters" element="tns:CreateUserRequest"/> </message> <message name="CreateUserOutput"> <part name="parameters" element="tns:CreateUserResponse"/> </message> <!-- Port Type definitions --> <portType name="UserServicePortType"> <operation name="CreateUser"> <input message="tns:CreateUserInput"/> <output message="tns:CreateUserOutput"/> </operation> </portType> <!-- Binding definitions --> <binding name="UserServiceBinding" type="tns:UserServicePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="CreateUser"> <soap:operation soapAction="{{ url()->current() }}/CreateUser"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <!-- Service definition --> <service name="UserService"> <port name="UserServicePort" binding="tns:UserServiceBinding"> <soap:address location="{{ url()->current() }}"/> </port> </service> </definitions>
Defining Routes
Define a route to handle the SOAP requests. For example, in routes/web.php:
use App\Services\UserService; use LaravelSoapServer\Soap; /** * GET http://localhost:8000/user-soap-service?wsdl Returns the WSDL definition * POST http://localhost:8000/user-soap-service Handles the SOAP requests */ Route::any('/user-soap-service', function () { // Option 1 return Soap::handle(view: 'wsdl', service: UserService::class); // Option 2 return Soap::withView('wsdl') ->withService(UserService::class) ->withRequest(request()) // Optional: defaults to current request ->withOptions([]) // Optional: defaults to [] ->handle(); });
Testing the Service
You can test the service using a SOAP client or by writing tests. For example, a test case:
namespace Tests\Feature; use Tests\TestCase; class SoapTest extends TestCase { public function test_create_user() { $name = 'John Doe'; $email = 'john.doe@example.com'; $url = url('/user-soap-service'); $payload = <<<XML <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="$url"> <soapenv:Header/> <soapenv:Body> <soap:CreateUserRequest> <name>$name</name> <email>$email</email> </soap:CreateUserRequest> </soapenv:Body> </soapenv:Envelope> XML; $response = $this->call('POST', $url, [], [], [], [ 'HTTP_SOAPACTION' => 'CreateUser', 'CONTENT_TYPE' => 'text/xml;charset=utf-8', 'CONTENT_LENGTH' => strlen($payload), ], $payload); $response->assertStatus(200); $response->assertHeader('Content-Type', 'application/soap+xml;charset=utf-8'); // ... } }
License
Laravel SOAP Server is open-sourced software licensed under the MIT license.
Icons made by justicon from www.flaticon.com
rogervila/laravel-soap-server 适用场景与选型建议
rogervila/laravel-soap-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Laravel SOAP Server」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rogervila/laravel-soap-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rogervila/laravel-soap-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rogervila/laravel-soap-server 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
cURL and cURL based Soap-Client for PHP
A PHP client for the Salesforce SOAP API
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A Yii2 component for working with TurboSMS.ua SOAP service
Zend Framework 1 Soap package
NuSOAP PHP library re-packaged for Packagist/Composer
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-14