fnayou / zeppelin
此包已被废弃且不再维护。未建议替代包。
使用客户端配置和API描述文件简单配置Guzzle的包。
1.0.3
2016-09-07 09:10 UTC
Requires
- php: ~5.6|~7.0
- guzzlehttp/guzzle: ~5.0
- guzzlehttp/guzzle-services: ^0.5.0
- symfony/filesystem: ^3.1
- symfony/options-resolver: ^3.1
- symfony/yaml: ^3.1
Requires (Dev)
- phpunit/phpunit: ~4.0||~5.0
- squizlabs/php_codesniffer: ~2.3
- symfony/var-dumper: ^3.1
This package is auto-updated.
Last update: 2024-06-12 03:52:53 UTC
README
[已废弃且不再维护]
简单 Guzzle 配置器,使用 客户端配置 和 API描述 文件。
- 您只需要创建两个文件
- guzzle客户端配置(API URL、版本、用户代理等)
- API描述结构
- 使用
ZeppelinFactory
工厂或创建自己的 - 消费API
Zeppelin旨在通过提供简单易用的方式来消费API和Web服务,让您能够专注于主要项目。
安装
您可以使用composer安装zeppelin
$ composer require fnayou/zeppelin
用法
<?php use Fnayou\Zeppelin\Factory\ZeppelinFactory; use Fnayou\Zeppelin\Loader\YamlLoader; $yamlLoader = YamlLoader(); $configurationFilePath = '/path/to/api_configuration.yml'; $customGuzzleConfiguration = []; $client = ZeppelinFactory::build($yamlLoader, $configurationFilePath, $customGuzzleConfiguration);
- 消费您的API
<?php // you can access api as method (according to the api description file) try { $response = $client->user([ 'X-APPID' => '26041986', 'user_id' => 26, ]); } catch (\GuzzleHttp\Exception\RequestException $e) { $response = json_decode($e->getResponse()->getBody()->getContents()); } dump($response);
- 您也可以创建自己的带有自定义逻辑的
factory
,您只需要实现FactoryInterface
<?php namespace Vendor\App\Factory; use Fnayou\Zeppelin\ApiClient; use Fnayou\Zeppelin\Api\ApiDescription; use Fnayou\Zeppelin\Factory\FactoryInterface; use Fnayou\Zeppelin\Loader\LoaderInterface; use GuzzleHttp\Client; use GuzzleHttp\Command\Guzzle\GuzzleClient; class CustomFactory implements FactoryInterface { public static function build(LoaderInterface $loader, $filePath, array $config) { // load the guzzle configuration file $apiClientConfiguration = new ApiClient($loader, $filePath); // load the api description file $apiDescription = new ApiDescription( $loader, $apiClientConfiguration->getDescriptionFilePath() ); $client = new Client($apiClientConfiguration->getClientConfiguration()); // your guzzle instance using api description, and custom configuration $zeppelin = new GuzzleClient( $client, $apiDescription->getDescription(), $config ); return $zeppelin; } }
贡献
请参阅CONTRIBUTING和CONDUCT以获取详细信息。
致谢
- Aymen FNAYOU - GitLab - GitHub
许可
MIT许可(MIT)。请参阅许可文件获取更多信息。