Download the PHP package kyserbyte/ypd without Composer
On this page you can find all versions of the php package kyserbyte/ypd. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kyserbyte/ypd
More information about kyserbyte/ypd
Files in kyserbyte/ypd
Package ypd
Short Description Ypd Php Decorator implements "decorators/annotations and meta-programming" in PHP, via doc comments.
License MIT
Informations about the package ypd
YPD - Ypd Php Decorator
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
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.