goetas-webservices/soap-server
Composer 安装命令:
composer require goetas-webservices/soap-server
包简介
Pure PHP implementation of SOAP 1.1 and 1.2 server
README 文档
README
PHP implementation of SOAP 1.1 and 1.2 server specifications.
Strengths:
- Pure PHP, no dependencies on
ext-soap - Extensible (JMS event listeners support)
- PSR-7 HTTP messaging
- PSR-15 HTTP server handlers
- No WSDL/XSD parsing on production
- IDE type hinting support
Only document/literal style is supported and the webservice should follow the WS-I guidelines.
There are no plans to support the deprecated rpc and encoded styles. Webservices not following the WS-I specifications might work, but they are officially not supported.
Demo
goetas-webservices/soap-server-demo is a demo project that shows how to produce a SOAP server in a generic PHP web application.
Installation
The recommended way to install goetas-webservices / soap-server is using Composer:
Add this packages to your composer.json file.
{
"require": {
"goetas-webservices/soap-server": "^0.1",
},
"require-dev": {
"goetas-webservices/wsdl2php": "^0.5.1",
},
}
How to
To improve performance, this library is based on the concept that all the SOAP/WSDL metadata has to be compiled into PHP compatible metadata (in reality is a big plain PHP array, so is really fast).
To do this we have to define a configuration file (in this case called config.yml) that
holds some important information.
Here is an example:
# config.yml soap_server: namespaces: 'http://www.example.org/test/': 'TestNs/MyApp' destinations_php: 'TestNs/MyApp': soap/src destinations_jms: 'TestNs/MyApp': soap/metadata aliases: 'http://www.example.org/test/': MyCustomXSDType: 'MyCustomMappedPHPType' metadata: 'test.wsdl': ~
This file has some important sections:
WSDL Specific
metadataspecifies where are placed WSDL files that will be used to generate al the required PHP metadata.
XML/XSD Specific
-
namespaces(required) defines the mapping between XML namespaces and PHP namespaces. (in the example we have thehttp://www.example.org/test/XML namespace mapped toTestNs\MyApp) -
destinations_php(required) specifies the directory where to save the PHP classes that belongs toTestNs\MyAppPHP namespace. (in this exampleTestNs\MyAppclasses will ne saved intosoap/srcdirectory. -
destinations_jms(required) specifies the directory where to save JMS Serializer metadata files that belongs toTestNs\MyAppPHP namespace. (in this exampleTestNs\MyAppmetadata will ne saved intosoap/metadatadirectory. -
aliases(optional) specifies some mappings that are handled by custom JMS serializer handlers. Allows to specify to do not generate metadata for some XML types, and assign them directly a PHP class. For that PHP class is necessary to create a custom JMS serialize/deserialize handler.
Metadata generation
In order to be able to use the SOAP server we have to generate some metadata and PHP classes.
To do it we can run:
bin/soap-server generate \ tests/config.yml \ --dest-class=GlobalWeather/Container/SoapServerContainer \ soap/src-gw/Container
bin/soap-server generateis the command we are runningtests/config.ymlis a path to our configuration file--dest-class=GlobalWeather/Container/SoapServerContainerallows to specify the fully qualified class name of the container class that will hold all the webservice metadata.soap/src/Containeris the path where to save the container class that holds all the webservice metadata (you will have to configure the auto loader to load it)
Using the server
Once all the metadata are generated we can use our SOAP server.
Let's see a minimal example:
// composer auto loader require __DIR__ . '/vendor/autoload.php'; // instantiate the main container class // the name was defined by --dest-class=GlobalWeather/Container/SoapServerContainer // parameter during the generation process $container = new SoapServerContainer(); // create a JMS serializer instance $serializer = SoapContainerBuilder::createSerializerBuilderFromContainer($container)->build(); // get the metadata from the container $metadata = $container->get('goetas_webservices.soap.metadata_reader'); $handler = new class() { function anAction($someParam) { return 'OK 123'; } function someAction($someParam, HeadersIncoming $headersIncoming) { $headers = $headersIncoming->getRawheader(); // perform some checks on $headers here return 'OK 123'; } function anotherAction($someParam, HeadersOutgoing $headersOutgoing) { // reply with custom headers $headersOutgoing->addHeader(new Header(new SomeHeaderData())); // reply with custom headers in pure xml $dom = new DOMDocument(); $dom->appendChild($dom->createElement('foo', 'bar')); $headersOutgoing->addHeader(new Header($dom->documentElement)); return 'OK 456'; } function someErrAction($someParam) { throw new CustomExcpetion(); // converted in a soap fault } }; $router = new DefaultRouter(new ConfiguredRoute($handler)); $factory = new ServerFactory($metadata, $serializer, $router); // get the soap server $server = $factory->getServer('test.wsdl'); // create psr7 request $request = \Laminas\Diactoros\ServerRequestFactory::fromGlobals(); // let the server handle the request $response = $server->handle($request); // send the response to the client (using laminas/laminas-httphandlerrunner) $emitter = new \Laminas\HttpHandlerRunner\Emitter\SapiEmitter(); $emitter->emit($response);
Note
The code in this project is provided under the MIT license. For professional support contact goetas@gmail.com or visit https://www.goetas.com
goetas-webservices/soap-server 适用场景与选型建议
goetas-webservices/soap-server 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.62k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2016 年 09 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 goetas-webservices/soap-server 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 goetas-webservices/soap-server 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-07