api-clients/resource-generator

由 YAML 生成工具生成的资源


README

Linux Build Status Windows Build status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready

目标

  • 用于轻松创建基于 wyrihaximus/api-client 的 API 客户端资源线框的工具

安装

要使用 Composer 安装,请使用以下命令,它将自动检测最新版本并将其绑定到 ^

composer require api-clients/resource-generator 

使用方法

传递一个 definition YAML 文件。

./vendor/bin/api-client-resource-generator [definition]

例如

./vendor/bin/api-client-resource-generator ./yaml/project.yml

YAML

YAML 格式允许快速轻松地生成资源、空资源以及资源测试。规范由两个或更多文件组成。

resource.yaml

首先是包含所有资源元数据的 resource.yml 文件

yaml_location: yaml                        # The location where the YAML files for the Resources are 
api_settings: Example\Client\ApiSettings   # API Settings file location
src:                                       # SRC 
  path: src/Resources                      # Path where the resources should be placed
  namespace: Example\Client\Resource       # The namespace for the resources
tests:                                     # TESTS
  path: tests/Resources                    # Path where the resources tests should be placed
  namespace: Example\Tests\Client\Resource # The namespace for the tests

yaml/project.yaml

以下 YAML 是一个示例资源文件

class: Project                             # Resource classname
properties:                                # The resource's properties
  id: int                                  # Simple id field with type int
  name: string                             # Any scalar types or classes work
  plugins: SplObjectStorage                #
  builds:                                  # But differet types `special` properties are supported.
    type: array                            # For example the collection expects the type to be an array
    annotations:                           # and it uses an annotation name `collection` to     
      collection: Project\Build            # transform all items in the array to the specified resource.
  latestBuild:                             # Another supported annotation is `nested`, `nested` allows you to
    type: Project\Build                    # turn a properties that would otherwise be an array into a
    annotations:                           # resource. With it's own properties and methods
      nested: Project\Build                #
  updated:                                 # Normally all methods are generated to their camelCase property name
    method: updatedAt                      # but with `method` you can specify a custom method
    type: DateTimeInterface                # When for example dealing with time, you can specify to return an interface
    wrap: DateTimeImmutable                # while wrapping the value in a concrete class

许可证

MIT 许可证 (MIT)

版权所有 © 2016 Cees-Jan Kiewiet

特此授予任何获得此软件及其相关文档副本(“软件”)的人免费使用权,不受限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件的副本,并允许向提供该软件的人提供这样做,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论该责任是基于合同、侵权或其他原因,无论该责任是否与软件或软件的使用或其他方式有关。