yusefauto1/service-api-components-bundle

Auto1 服务 API/客户端/处理器组件包的通用组件

安装: 85

依赖项: 1

建议者: 0

安全性: 0

星星: 0

关注者: 1

分支: 12

类型:auto1-bundle

v1.0.2 2019-11-18 08:50 UTC

This package is not auto-updated.

Last update: 2024-10-01 08:14:50 UTC


README

config.yml

framework:
    serializer: { enabled: true }
    property_info: { enabled: true }

示例 EP 提供商 symfony.service 声明

tag

{ name: 'auto1.api.endpoint_provider', priority: 0 }

services.yml

services:
    your_app.api.endpoint.provider:
        class: Auto1\ServiceAPIComponentsBundle\Service\Endpoint\EndpointProviderConfiguration
        arguments:
            - '@auto1.api.endpoint.factory'
            - '@your_app.api.endpoint_configuration.loader'
        tags:
            - { name: 'auto1.api.endpoint_provider', priority: 0 }

    your_app.api.endpoint_configuration.loader:
        class: Auto1\ServiceAPIComponentsBundle\Service\Endpoint\EndpointsConfigurationLoader
        arguments:
            - '%kernel.project_dir%/src/Resources/endpoints.yml'

快速开始指南

仅适用于证明概念等。

class YourProvider implements EndpointProviderInterface
{
    public function getEndpoints(): array
    {
        return [
            new EndpointImmutable(
                ...,
            ),
        ];
    }
}
services:
    your_app.api.endpoint.provider:
        class: YourProvider
        tags:
            - { name: 'auto1.api.endpoint_provider', priority: 0 }

EP 定义示例(yaml)

# Auth
- method:        'POST'
  baseUrl:       '%wkda.java_api.url%'
  path:          '/v1/auth/oauth/token'
  requestFormat: 'url'
  requestClass:  'Auto1\ServiceDTOCollection\Authentication\OAuth\Request\PostRefreshTokenRequest'
  responseClass: 'Auto1\ServiceDTOCollection\Authentication\OAuth\Response\Token'

- method:        'GET'
  baseUrl:       '%wkda.java_api.admin_url%'
  path:          '/v1/auth/user/admin/{userUuid}/roles'
  requestFormat: 'url'
  requestClass:  'Auto1\ServiceDTOCollection\Authentication\User\Request\GetUserRolesRequest'
  responseClass: 'Auto1\ServiceDTOCollection\Authentication\User\Response\UserRoles'

# CarLead
- method:        'GET'
  baseUrl:       '%wkda.java_api.url%'
  path:          '/v1/carlead/vin/{vin}'
  requestClass:  'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Request\GetCarDetailsByVinRequest'
  responseClass: 'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Response\CarLead[]'

替代

# Auth
refreshToken:
    method:        'POST'
    baseUrl:       '%wkda.java_api.url%'
    path:          '/v1/auth/oauth/token'
    requestFormat: 'url'
    requestClass:  'Auto1\ServiceDTOCollection\Authentication\OAuth\Request\PostRefreshTokenRequest'
    responseClass: 'Auto1\ServiceDTOCollection\Authentication\OAuth\Response\Token'

getUserRoles:
    method:        'GET'
    baseUrl:       '%wkda.java_api.admin_url%'
    path:          '/v1/auth/user/admin/{userUuid}/roles'
    requestFormat: 'url'
    requestClass:  'Auto1\ServiceDTOCollection\Authentication\User\Request\GetUserRolesRequest'
    responseClass: 'Auto1\ServiceDTOCollection\Authentication\User\Response\UserRoles'

# CarLead
getCarLeadByVin:
    method:        'GET'
    baseUrl:       '%wkda.java_api.url%'
    path:          '/v1/carlead/vin/{vin}'
    requestClass:  'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Request\GetCarDetailsByVinRequest'
    responseClass: 'Auto1\ServiceDTOCollection\CarLead\CarLeadRead\Response\CarLead[]'

ServiceRequest 实现示例

class GetCarDetailsByVinRequest implements ServiceRequestInterface
{
    private $vin;

    public function setVin(string $vin): self
    {
        $this->vin = $vin;

        return $this;
    }

    public function getVin()
    {
        return $this->vin;
    }
}

URL 解析

要更改 URL 解析的默认行为,请查看 UrlResolverCompilerPass,并使用 auto1.api.url_resolver 标签以及 priority

    # this is a default resolver
    auto1.api.url_resolver.parameter_aware:
        class: Auto1\ServiceAPIComponentsBundle\Service\UrlResolver\ParameterAwareUrlResolver
        arguments:
            - '@service_container'
        tags:
            - { name: 'auto1.api.url_resolver', priority: 0 }

调试

输出所有注册的端点

bin/console auto1.debug.endpoints