tenolo / apilyzer
一个用于轻松创建REST API客户端的库
dev-master / 1.0.x-dev
2019-08-02 07:35 UTC
Requires
- php: ^7.2
- ext-json: *
- jms/serializer: ^1.9
- nesbot/carbon: ^2.18
- php-http/client-common: ^1.7|^2.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.6
- php-http/logger-plugin: ^1.0
- php-http/promise: ^1.0
- php-http/stopwatch-plugin: ^1.1
- psr/http-client: ^1.0
- psr/http-factory-implementation: ^1.0
- psr/http-message: ^1.0
- psr/log: ^1.1
- ramsey/collection: ^1.0
- symfony/event-dispatcher: ^2.8|^3.4|^4.0
- symfony/filesystem: ^2.8|~3.4|~4.0
- symfony/finder: ^2.8|~3.4|~4.0
- symfony/options-resolver: ^2.8|~3.4|~4.0
- symfony/routing: ^2.8|~3.4|~4.0
- symfony/stopwatch: ^2.8|~3.4|~4.0
- symfony/var-dumper: ^2.8|^3.4|^4.0
- tenolo/utilities: ^1.7
Requires (Dev)
- nyholm/psr7: ^1.0
- php-http/guzzle6-adapter: ^2.0
- phpunit/phpunit: ^8.1
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-08-29 04:49:05 UTC
README
Apilyzer
一个用于轻松创建REST API客户端的库。
安装说明
Composer
首先,您需要将 tenolo/apilyzer
添加到 composer.json
文件中
手动添加
{ "require": { "tenolo/apilyzer": "~1.0" } }
或者直接执行 composer require tenolo/apilyzer
。
请注意,dev-master
是最新开发版本。当然,您也可以使用显式的版本号,例如 1.0.*
或 ^1.0
。
HTTP 客户端和工厂
第二步,您需要在生产或开发环境中添加 HTTP-Client 和 HTTP-Factory 到您的项目。
您需要一个或多个实现以下包的库
- psr/http-message
- psr/http-client
- psr/http-factory-implementation
- php-http/client-implementation
这个库故意不提供这些包,以便每个API客户端都可以实现自己的。
我们建议使用 nyholm/psr7
和 php-http/guzzle6-adapter
。
生产使用: composer require nyholm/psr7 php-http/guzzle6-adapter
开发使用: composer require --dev nyholm/psr7 php-http/guzzle6-adapter
使用说明
第一步
创建自己的 Gateway
和 Config
类。
<?php namespace App\Api\Gateway; use Tenolo\Apilyzer\Gateway\Config as BaseConfig; /** * Class Config */ class Config extends BaseConfig { /** * @inheritDoc */ public function getGatewayUrl(): string { return 'https://BASE.URL.TO.API.com/'; } }
<?php namespace App\Api\Gateway; use Tenolo\Apilyzer\Gateway\Gateway as BaseGateway; use Tenolo\Apilyzer\Manager\EndpointManager; use Tenolo\Apilyzer\Manager\EndpointManagerInterface; /** * Class Gateway */ class Gateway extends BaseGateway { /** @var EndpointManagerInterface */ protected $endpointManager; /** * @inheritDoc */ protected function getEndpointManager(): EndpointManagerInterface { if ($this->endpointManager === null) { $this->endpointManager = $this->createEndpointManager(); } return $this->endpointManager; } /** * @return EndpointManagerInterface */ protected function createEndpointManager(): EndpointManagerInterface { return new EndpointManager(__DIR__.'/../Endpoint'); } }