eleven-labs/api-service-bundle

将API服务集成到Symfony中

安装: 225

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 5

分支: 1

开放问题: 0

类型:symfony-bundle

0.3.1 2018-11-11 22:19 UTC

This package is auto-updated.

Last update: 2024-08-29 04:31:07 UTC


README

Build Status Code Coverage Scrutinizer Quality Score

此包将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组织提供的许多缓存池实现之一。