vasildakov/speedy 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

vasildakov/speedy

Composer 安装命令:

composer require vasildakov/speedy

包简介

Speedy API Client

README 文档

README

An easy to use PHP client for Speedy REST API

build Scrutinizer Code Quality Code Coverage Build Status Packagist License Packagist Dependency Version Packagist Downloads

Speedy client is a PSR-7 and PSR-18 compliant HTTP client that implements Speedy communication protocol. It has clean and consistent API, is fully unit tested and even comes with an example application to get you started.

Features

This library is compliant with PSR-7: HTTP message interfaces, PSR-17: HTTP Factories and PSR-18: HTTP Client

Installation

Using Composer:

$ composer require vasildakov/speedy

Usage

The Configuration

Let's presume that you are using PHP dotenv to load environment variables from a file named .env. In this case, you need to add the following variables:

SPEEDY_USERNAME="username"
SPEEDY_PASSWORD="password"
SPEEDY_LANGUAGE="EN"

The next step is to create a new Configuration instance like in the example bellow:

<?php

// configuration
$configuration = new Configuration(
    username: $_ENV['SPEEDY_USERNAME'],
    password: $_ENV['SPEEDY_PASSWORD'],
    language: $_ENV['SPEEDY_LANGUAGE']
);

Configuring Speedy Client

The final step is to configure the Speedy client. The client can be configured with any PSR-18 HTTP Client and PSR-17 HTTP Factory:

Example with Guzzle and Laminas Diactoros

<?php

use GuzzleHttp\Client;
use Laminas\Diactoros\RequestFactory;

$client  = new Client(); // PSR-18 HTTP Client
$factory = new RequestFactory(); // PSR-17 HTTP Factory
$speedy  = new Speedy($configuration, $client, $factory);

Example with Symfony HTTP Client and Nyholm HTTP Factory

<?php

use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\Psr18Client;

$client  = new Psr18Client(); // PSR-18 HTTP Client
$factory = new Psr17Factory(); // PSR-17 HTTP Factory
$speedy  = new Speedy($configuration, $client, $factory);

Making a Request

Once you have configured the client, you can proceed to make your first request. By default, each method returns the data in JSON, which can then be utilized as a simple PHP array or deserialized into the PHP model.

<?php

// use an array
$request = new GetContractClientsRequest(clientSystemId: "1234567");
$json = $speedy->getContractClient($request);
$array = json_decode($json, true);

Processing the Response

The client API always returns the raw JSON response received from the endpoint. The JSON can be used as it is, decoded into a PHP associative array, or deserialized into a model object.

Deserialization can be achieved in two different ways: 1) by using the serializer, or 2) by decorating the original Speedy client with the SpeedyModelDecorator.

Using serializer:

<?php

$json = $speedy->getContractClient($request); # json

$serializer = (new SerializerFactory())(); # JMS\Serializer\SerializerInterface

$response = $serializer->deserialize(
    data: $json, 
    type: GetContractClientsResponse::class, 
    format: 'json'
); # GetContractClientsResponse

Instead of calling the serializer every time, you can enhance the original Speedy client by decorating it with the SpeedyModelDecorator. This enhancement makes the responses more convenient, predictable and easy to use.

<?php

$decorator = new SpeedyModelDecorator(
    new Speedy($configuration, $client, $factory)
);

/** @var GetContractClientsResponse $response */
$response = $decorator->getContractClient(new GetContractClientsRequest());

Using the model

<?php

// @var ArrayCollection $collection
$collection = $response->getClients();
foreach ($collection as $client) {
    dump($client); # Model\Client
    dump($client->getClientName());
    dump($client->getAddress()); # Model\Address
    dump($client->getAddress()->getSiteName()); # string
    dump($client->getAddress()->getPostcode()); # string 
}

Documentation

TBC

License

Code released under the MIT license

Speedy REST API examples

Speedy Web API Integration

vasildakov/speedy 适用场景与选型建议

vasildakov/speedy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 vasildakov/speedy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-29