承接 php-soap/encoding 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

php-soap/encoding

Composer 安装命令:

composer require php-soap/encoding

包简介

SOAP encoding and decoding package

README 文档

README

This package provides a pure PHP drop-in replacement for the ext-soap encoding logic. It can be used as a driver so that you don't have to install PHP's soap extension on your machine anymore.

Thanks

This project was funded by the sponsorship of buhta.com.

buhta.com

Want to help out? 💚

Want more information about the future of this project? Check out this list of the next big projects we'll be working on.

Installation

composer require php-soap/encoding

Example usage

use Soap\Encoding\Driver;
use Soap\Encoding\EncoderRegistry;
use Soap\Engine\SimpleEngine;
use Soap\Psr18Transport\Psr18Transport;
use Soap\Wsdl\Loader\StreamWrapperLoader;
use Soap\WsdlReader\Locator\ServiceSelectionCriteria;
use Soap\WsdlReader\Model\Definitions\SoapVersion;
use Soap\WsdlReader\Wsdl1Reader;

// Loads the WSDL with the php-soap/wsdl-reader package:
$wsdl = (new Wsdl1Reader(new StreamWrapperLoader()))($wsdlLocation);

// Create an engine based on the encoding system that is provided by this package:
$engine = new SimpleEngine(
    Driver::createFromWsdl1(
        $wsdl,
        ServiceSelectionCriteria::defaults()
            ->withPreferredSoapVersion(SoapVersion::SOAP_12),
        EncoderRegistry::default(),
    ),
    Psr18Transport::createForClient($httpClient)
);

// Perform requests:
$decodedResult = $engine->request('Add', [
    [
        'a' => 1,
        'b' => 2
    ]
]);

/*
RESULT :

class stdClass#2135 (1) {
  public $AddResult =>
  int(3)
}
 */

EncoderRegistry

The EncoderRegistry is a collection of encoders that can be used to encode and decode data. By default, we provide a broad set of encoders to perform the basic soap encoding logic. However, you can configure how the encoding should be done by adding your own encoders to the registry.

Some examples:

use Soap\Encoding\ClassMap\ClassMap;
use Soap\Encoding\ClassMap\ClassMapCollection;
use Soap\Encoding\Encoder\SimpleType\DateTimeTypeEncoder;
use Soap\Encoding\EncoderRegistry;
use Soap\Xml\Xmlns;

EncoderRegistry::default()
    ->addClassMap('urn:namespace', 'TypeA', TypeA::class)
    ->addClassMap('urn:namespace', 'TypeB', TypeB::class)
    ->addClassMapCollection(new ClassMapCollection(
        new ClassMap('urn:namespace', 'TypeC', TypeC::class),
    ))
    ->addBackedEnum('urn:namespace', 'EnumA', EnumA::class)
    ->addSimpleTypeConverter(Xmlns::xsd()->value(), 'dateTime', new DateTimeTypeEncoder('Y-m-d\TH:i:s'))
    ->addComplexTypeConverter('urn:namespace', 'TypeC', MySpecificTypeCEncoder::class);

Encoder

Encoding and decoding is based on small XmlEncoder classes that are responsible for encoding and decoding a specific type of data. You can either use one of the provided encoders or create your own.

Building a custom encoder can look like this:

use Soap\Encoding\Encoder\Context;
use Soap\Encoding\Encoder\XmlEncoder;
use VeeWee\Reflecta\Iso\Iso;

/**
 * @implements XmlEncoder<MyClass, string> 
 */
class MySpecificTypeCEncoder implements XmlEncoder
{
    /**
     * @return Iso<MyClass, string>
     */
    public function iso(Context $context) : Iso
    {
        return new Iso(
            to: static fn (MyClass $value): string => $myClass->toXmlString(),
            from: static fn (string $value) => MyClass::fromXmlString($value),
        );
    }
}

Note: An encoder is considered to be isomorphic : When calling from and to on the Iso object, the data should be the same. More information about the concept can be found here.

For a full list of available encoders, you can check the Soap\Encoding\Encoder namespace. There are also some examples of common problems you can solve with these encoders in the examples/encoders directory.

php-soap/encoding 适用场景与选型建议

php-soap/encoding 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 408.9k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2024 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 php-soap/encoding 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 3
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-10