Skip to content
/ ypd Public

Ypd Php Decorator implements \"decorators/annotations and meta-programming\" in PHP, via doc comments.

Notifications You must be signed in to change notification settings

Kyserbyte/ypd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

/**
* 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.

About

Ypd Php Decorator implements \"decorators/annotations and meta-programming\" in PHP, via doc comments.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages