定制 hpatoio/jsg 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hpatoio/jsg

Composer 安装命令:

composer require hpatoio/jsg

包简介

Generate an object from a json schema definition and vice versa

README 文档

README

This package let you represent a JSON Schema as a PHP object and dump it as a JSON and vice versa.

Continuous Integration

codecov

Usage

Create a JSON from a model

  1. Define the model representing the schema.

    $myJsonSchema = new JsonSchema('foo', 'My schema', "Test schema description", ...[
            new OptionalObjectProperty(new TypeBoolean("top", "Is a top developer ?")),
            new RequiredObjectProperty(new TypeDate("birthdate", "Birthdate ?")),
            new OptionalObjectProperty(new TypeDateTime("interview_at", "Interview planned for ?")),
            new RequiredObjectProperty(new TypeEmail("email", "Email address ?")),
            new RequiredObjectProperty(TypeInteger::from(100, "minimum_salary", "Minimum salary ?")),
            new OptionalObjectProperty(TypeInteger::to(200, "max_days_in_office", "Max number of days in office ?")),
            new OptionalObjectProperty(new TypeObject("address", "Address", ...[
                new OptionalObjectProperty(TypeString::withMinLength("street", "Street", 0)),
                new OptionalObjectProperty(TypeString::withMinLength("city", "City", 0))
            ]))
        ]);
  2. Serialize the object into a JSON.

    echo JsonSchemaGenerator::generate($myJsonSchema);

    the result will be a JSON like https://github.com/hpatoio/jsg/blob/develop/test/fixtures/all-types-schema.json

Create a model from a JSON

  1. Generate the model from a JSON
    $hydratedSchema = JsonSchemaHydrator::hydrate("/path/to/the/file.json");
  2. Access elements
    $hydratedSchema->getProperties()['id_of_the_property'];

Installation

Install the package in your project with

composer require hpatoio/jsg

Create dev environment

  1. Clone the repo
git clone git@github.com:hpatoio/jsg.git
cd jsg
  1. Build the image
docker build -t jsg .docker
  1. Run composer install to get dependencies
docker run --rm -v `pwd`:/var/jsg jsg composer install

Run tests

docker run --rm -v `pwd`:/var/jsg jsg vendor/bin/phpunit

Run mutation tests

This project uses PHP Mutation.

To run mutation tests use:

docker run --rm -v `pwd`:/var/jsg jsg ./infection.phar run

Apply CS

Before push please fix apply coding standards

docker run --rm -v `pwd`:/var/jsg jsg vendor/bin/ecs check src --no-progress-bar -vvv --fix

License

This package is licensed using the MIT License.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固