new-inventor/data-structure
Composer 安装命令:
composer require new-inventor/data-structure
包简介
Data structure transformers and validators config
README 文档
README
This utility provide to you data structure metadata and some useful classes.
With this packet you can transform arrays to needed format and load it to objects recursive.
Objects to load MUST implement Loadable or DataStructureInterface interface.
Installation
composer require new-inventor/data-structure
Examples
Metadata config
namespace: DataStructure\Namespace validation: constraints: - Callback: ['Some\Existing\Class', 'GetTrue'] getters: prop1: - GreaterThan: 0 properties: prop0: - GreaterThan: 0 properties: prop1: NewInventor\DataStructure\Transformer\ToInt prop2: transformers: - ToInt: ~ validation: - GreaterThan: 5 - LessThanOrEqual: 1000 prop3: transformers: - ToBool: - ['Some\Existing\Class', 'GetTrue'] prop4: transformers: - ToBool: - groups: forward - BoolToMixed: - static: ['Some\Existing\Class', 'bbb'] - const: ['Some\Existing\Class', 'AAA'] - groups: backward prop5: ~ prop6: transformers: - ChainTransformer: - ToString: ~ - CsvStringToArray: ~ - NewInventor\DataStructure\Transformer\InnerTransformer: - ToInt: ~ - groups: forward - ArrayToCsvString: - groups: backward prop7: default: 2222 transformers: - ToString: ~ - StringToDateTime: - 'd.m.Y' - groups: forward prop8: transformers: - ToArray: - groups: forward prop9: nested: class: DataStructure\Namespace\Structure
Recursive loading
You can load properties recursive by using RecursiveConstructor.
To use this you shoul add nested parameter to property like this
prop: nested: class: DataStructure\Namespace\Structure
or
prop: nested: metadata: path: some/config baseNamespace: Some\Namespace class: DataStructure\Namespace\Structure
or
prop: nested: metadata: path: some/config/path.yml class: DataStructure\Namespace\Structure
Namespace
It is the namespace for data structure class for recursive loading.
Validation
It is the symfony class validation config. You can pass it directly into property
Properties
It is properties of your data structure.
Property has this parameters:
- default
- transformers
- validation
- nested
If property === null(~) then default = null and no transformers and validators If property is string then default = null and default transformers = this string
transformers
Transformers is array of arrays.
In yml like this:
key: - name: value
So you can set transformer like this:
transformers: - ToInt: ~
By default transformer is inner transformer, but you can create you own and pass full class name to transformer config
Transformer can receive array or parameters and parameter can be array(1) with reserved word as key; Reserved words:
- static - interpret as static property of class
['class', 'propertyName'] - const - interpret as constant can be array like static or string
- groups - transformer groups, by default
groups = ['default'].
If in transformers section more than 1 transformer in same group then this transformers will be wrapped by ChainTransformer, so this identical:
transformers: - ToInt: - groups: group1 - ToRange: - 1 - 10 - groups: group1
and
transformers: - ChainTransformer: - groups: group1 - ToInt: - ToRange: - 1 - 10
Validation
It is the getters part of symfony validation config for given property
Default
Default can be any value and have same reserved keys as transformer parameters, but group.
Nested
It is described in Recursive loading section.
PropertiesTransformer
$metadata = (new Metadata\Loader($path))->loadMetadata(); $transformer = $metadata->getTransformer($groupName); $resArray = $transformer->transform($someArray);
or you can compose PropertiesTransformer by yourself
RecursiveConstructor
This constructor construct class with metadata by recursive loading it nested classes.
Links
- To use only transformers use https://github.com/new-inventor/transformers
- To implement property bags use https://github.com/new-inventor/property-bag
new-inventor/data-structure 适用场景与选型建议
new-inventor/data-structure 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 359 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 new-inventor/data-structure 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 new-inventor/data-structure 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 359
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-10