定制 bradfeehan/guzzle-modular-service-descriptions 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bradfeehan/guzzle-modular-service-descriptions

Composer 安装命令:

composer require bradfeehan/guzzle-modular-service-descriptions

包简介

A better ServiceDescriptionLoader for Guzzle 3.x

README 文档

README

Build Status Code Coverage Scrutinizer Code Quality

A better ServiceDescriptionLoader for Guzzle 3.x

Features

Guzzle's service descriptions make it easy to describe APIs. A service description takes the form of a JSON object (or PHP associative array) that describes all the available operations and data models supported by the API. However, for large or poorly-designed APIs, the service description can quickly become hard to manage.

This project offers a replacement ServiceDescriptionLoader implementation, which allows for much more flexibility when writing service descriptions. It supports:

  • Separating the service description arbitrarily into many files ("modular" service descriptions)
  • Alternative formats (plain text and YAML)

Installation

To get this library in to an existing project, the best way is to use Composer.

  1. Add bradfeehan/guzzle-modular-service-descriptions as a Composer dependency in your project's composer.json file:

    {
        "require": {
            "bradfeehan/guzzle-modular-service-descriptions": "~1.0"
        }
    }
  2. If you haven't already, download and install Composer:

    $ curl -sS https://getcomposer.org/installer | php
  3. Install your Composer dependencies:

    $ php composer.phar install
  4. Set up Composer's autoloader:

    require_once 'vendor/autoload.php';

Usage

In contrast to typical Guzzle service descriptions, a modular service description is implemented as a directory. The format of the directory is very flexible. The directory structure is reflected in the heirarchy of the service description data.

Format

A file in the root of a modular service description directory defines the key with the name of the file. The content of the file defines the value of that key. As an example, consider the following directory structure:

my_service_description/
├── name.txt
└── operations.json

The my_service_description directory can be loaded as a modular service description. The content inside name.txt will be put into the key name at the top level of the service description. The content of operations.json will be the value for the operations key in the service description. (So, to be a valid service description, operations.json should contain a JSON object, defining all the operations).

Nested directories

Another, more complex example:

complicated_service_description/
├── name.txt
└── operations/
    ├── ComplexOperation/
    │   └── parameters.yml
    └── ComplexOperation.json

Again, name.txt will contain the value for the name key. However, this time, the operations key is represented by a directory. The files inside are converted to nested keys in the resulting service description. So this example will result in the following representation:

{
    "name": "[content of name.txt]",
    "operations": {
        "ComplexOperation": {
            // The keys defined in ComplexOperation.json
            // will be inserted here
            // ...
            "parameters": "[parsed content of parameters.yml]"
        }
    }
}
__index files

Any files named __index.[ext] define the contents of the directory the file is in, rather than the name of the file. It's essentially an "empty" name. This concept is similar to Python's __init__.py, which makes the directory the package, rather than the file.

Groups

Files can also be grouped without causing the contents to be nested. This is useful for organising a large service description. For example, if there are thousands of operations, you'd have to have that many files in the operations directory. Using groups, the operations can be grouped logically inside the operations directory.

A group is implemented as a directory ending with .group. So you could have Users.group containing all the operations relating to users, etc.

Note that this could cause problems if you wanted to have a key ending with .group. Please let me know by filing a GitHub issue if this causes you any issues, and we can work out a way to compromise.

Loading the service description

To load a modular service description, load it using the included loader, and add it to the web service client instance:

use BradFeehan\GuzzleModularServiceDescriptions\ServiceDescriptionLoader;
use Guzzle\Service\Client;

// Create a client somehow
$client = Client::factory();

// Instantiate the modular service description loader
$loader = new ServiceDescriptionLoader();

// Point the loader at the modular service description directory
$description = $loader->load('/path/to/service_description');

// Add the service description to the client
$client->setDescription($description);

// Done!
$command = $client->getCommand('MyCommand');

// ...

bradfeehan/guzzle-modular-service-descriptions 适用场景与选型建议

bradfeehan/guzzle-modular-service-descriptions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 111.58k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2014 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 bradfeehan/guzzle-modular-service-descriptions 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 111.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 6
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-05