kyserbyte/ypd
Composer 安装命令:
composer require kyserbyte/ypd
包简介
Ypd Php Decorator implements "decorators/annotations and meta-programming" in PHP, via doc comments.
README 文档
README
Ypd Php Decorator implements "decorators/annotations and meta-programming" in PHP, via doc comments.
INSTALL
You can install the package with composer:
composer require kyserbyte/ypd
USAGE
At the monent is implemented only the ypd::jsonSerialize decorator.
To activate the decorator you have to implement the JsonSerializable interface in the class that you want to make json serializable via the decorator. Then you have to add the YPDJsonSerializer trait to your class. This trait has an internal implementation of the method jsonSerialize() required by the JsonSerializable interface, so you need only to declare the implements statement in you class.
Now you are able to use the decorator inside a doc comment, in order to declare what properties you want to expose to json.
The decorator works for now only with the public properties of a class.
jsonSerialize decorator
Inside a doc comment over your property, you need to declare the decorator with the syntax
/**
* ypd::jsonSerialize(name=XX,if=YY)
*/
public $propName;
with the declaration you can pass 2 arguments to the decorator.
- name: specify a custom name for the property when exported to json
- if: a Function that resolve to boolean. You can use it to implement a conditional logic for export the property. The Function must be declared in the same class of the property or in a trait used by the class and must be public.
Take a look to DemoJsonSerialize class for more info about usage.
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-30