承接 unicon/yaml 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

unicon/yaml

最新稳定版本:1.0.0

Composer 安装命令:

composer require unicon/yaml

包简介

Validates YAML file using given class and, if matches, creates an object. Understands PhpDoc, converts values if necessary. Works recursively, so the YAML file may have complicated structure, and the given class may have properties of other classes.

README 文档

README

Validates YAML file using given class and, if matches, creates an object. Understands PhpDoc, converts values if necessary. Works recursively, so the YAML file may have complicated structure, and the given class may have properties of other classes.

Installation

composer require unicon/yarn

Usage

$reader = new Yaml(MyClass::class);
$object = $reader->read('my_yaml.yml');

Example

class Simple
{
    public int $integerParameter = 1;
    /** @var positive-int */
    public int $positiveIntegerParameter;
    public ?bool $booleanOrNullParameter;
    public string $stringParameter = 'default';
}

Success example

integer_parameter: '777'
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888

Failures

YamlException is thrown if the YAML file doesn't match the class:

Yaml parameter positive_integer_parameter must be greater or equal to 1, "-1" given

integer_parameter: '777'
positive_integer_parameter: '-1'
boolean_or_null_parameter: null
string_parameter: 888

Can't convert integer_parameter 777.777 to int

integer_parameter: 777.777
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888

Can't convert integer_parameter "xxx" to int

integer_parameter: 'xxx'
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888

Yaml parameter positive_integer_parameter is missed

(integer_parameter and boolean_or_null_parameter are missed too, but one has default values, another is nullable)

string_parameter: 'aaa'

Yaml parameter extra_parameter with value true is unexpected

(this exception is never thrown for stdClass or \AllowDynamicProperties classes)

extra_parameter: true
integer_parameter: '777'
positive_integer_parameter: 666
boolean_or_null_parameter: null
string_parameter: 888

You can find more examples in the test directory including dates, complicated structures and trees (classes with array<self> properties).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2024-01-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固