eleven-labs / api-service-bundle
将API服务集成到Symfony中
0.3.1
2018-11-11 22:19 UTC
Requires
- php: ^5.6 || ^7.0
- ext-json: *
- eleven-labs/api-service: ^0.3
- symfony/framework-bundle: ^2.7 || ^3.4
- symfony/serializer: ^2.7 || ^3.4
Requires (Dev)
- cache/adapter-bundle: ^0.3.5
- cache/void-adapter: ^0.3.1
- matthiasnoback/symfony-dependency-injection-test: ^1.0 || ^3.0
- php-http/guzzle6-adapter: ^1.1.1
- php-http/httplug-bundle: ^1.0
- php-http/mock-client: ^0.3.2
- phpunit/phpunit: ^5.4 || ^7.4
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- squizlabs/php_codesniffer: ^3.3
Suggests
- cache/adapter-bundle: Integrate cache pool providers in Symfony <3.1
- php-http/guzzle6-adapter: HttpClient adapter using Guzzle6
- php-http/httplug-bundle: Integrate HTTP Clients into Symfony
README
此包将API Service组件集成到Symfony。
安装
打开命令行,进入您的项目目录,然后执行以下命令以下载此包的最新稳定版本
composer require eleven-labs/api-service-bundle
然后,通过在您的项目的app/AppKernel.php文件中添加以下行来启用该包
<?php // app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new ElevenLabs\ApiServiceBundle\ApiServiceBundle(), ); // ... } }
配置
包提供的完整配置
api_service: # (optional) default_services: client: httplug.client message_factory: httplug.message_factory uri_factory: httplug.uri_factory # (optional) cache schema files cache: # provide the Id of any PSR-6 cache service service: 'my_app.cache' # (optional) configure supported pagination providers pagination: # extract pagination from response headers header: page: X-Page perPage: X-Per-Page totalPages: X-Total-Pages totalItems: X-Total-Items # configure api services apis: my_service: # the schema describing your api schema: 'file://%kernel.root_dir%/config/schema/foo.yml' # (optional) use a specific http client implementation client: httplug.client.foo # (optional) fine tune your api service config: # provide a base url baseUri: https://bar.com # validate request validateRequest: true # validate response validateResponse: false # return a psr-7 response # by default it return a `Resource` class returnResponse: false
依赖项
HTTP客户端
API服务组件使用由HttPlug提供的Http\Client\HttpClient
接口发送请求。
您可以在Symfony中使用自己的HTTP客户端服务,但我们强烈建议您使用HttplugBundle。
composer require php-http/httplug-bundle
然后,您可以选择许多由HTTPlug支持的HTTP客户端适配器之一。列表可在此处找到。
# for example, here we choose the Guzzle 6 adapter
composer require php-http/guzzle6-adapter
缓存
此包具有缓存您API服务使用的模式文件的能力。
它使用PSR-6: Caching Interface来实现这一点。
出于性能原因,缓存在生产环境中应该启用。
从Symfony 3.1及以上版本
Symfony 3.1提供了PSR-6缓存接口的实现。您不需要额外的组件即可将缓存功能集成到框架中。
从Symfony 2.7到3.1
我们建议您使用PSR-6缓存适配器包。
然后,您可以选择由php-cache组织提供的许多缓存池实现之一。