Download the PHP package codememory/entity-response-control without Composer
On this page you can find all versions of the php package codememory/entity-response-control. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codememory/entity-response-control
More information about codememory/entity-response-control
Files in codememory/entity-response-control
Package entity-response-control
Short Description Controls the response from entities or other objects based on constraints
License MIT
Informations about the package entity-response-control
Codememory Entity response control
TThis library is designed for easy prototyping of API responses. Where your class participates as a prototype of the response from the objects that you give as input
Install
What will be covered in this documentation?
- How to create your ResponsePrototype ?
- What types of decorators are there?
- What decorators exist?
- How to create your own Collector?
- How to create a context factory?
- How to create your own key naming strategy?
- How to create your own prototype property provider?
Let's create our ResponsePrototype
[ ! ] Note that in the ResponsePrototype, all properties we process must have the "private" access modifier, this is the default, if you want to change the creation, write your provider's properties. How to create your providers will be received later
And this is just a small example, on real projects, you can control each property, for example, depending on the permissions of the user or on the type of request and much more
Let's take a look at the decorators
- AliasInResponse - Display different name in response
- $name: string - Property name in response
- Prefix - Change the prefix of the calling method (default is get) or change the prefix in the response
- $prototypeObject: string | null - Prefix of the getter method from the prototype object from which the value will be obtained
- $responsePrefix: string | null - Prefix in response
- Custom - Custom property, call to get method will be ignored
- $methodName: string - Method name
- HiddenNullable - Hide properties from response that have null values
- $ignoreEmptyString (default: true): bool - If set to false then properties that have an empty string will also be hidden from the response
- Count - If the property is an array or implements the Countable interface, the count method will be called, if the value is a string, the length of the string will be counted, the response type is always integer
- ArrayValues - Converts a multi array or an array of objects to an array of values
- $key: string - The name of the array key or the name of the method to be called
- Callback - Creating your own callback, this method must be created inside your ResponseControl and the public access modifier
- $methodName: string - Method name
- NestedPrototype - The value of the property will be passed through another ResponseControl. Be careful to use one of the last arguments so you don't end up with a circular dependency
- $prototype: string - Namespace of the ResponseControl class
- $skipProperties: array
- Ignore some properties from $prototype - $skipAllPropertiesExpect: array
- Ignore all properties from $prototype except those listed
- DateTime - Expects the property value to be the DateTimeInterface interface, if so, the given object will be converted to the default format or to the format you specify
- $format: string - default(Y-m-d H:i:s) - Format date
- $full: bool - default(false) - If true instead of a string, a DateTime array with full information will be returned
- XSS - Protecting input strings or strings in an array from XSS attack
- FromEnum - Returns an array consisting of key and label from Enum
- $enum: string|null - Namespace Enum if the value is a string, or leave null if the value is already an enum object
- CropString - Trims a string to its maximum length
- $maxlength: INT - Maximum string length
- $end: string - default(...) - Character at the end of a string if the string was truncated
- PrototypeObjectGetterMethod - Set a new name getter name for the prototype object from which the value will be obtained
- $name: string - Method name
Creating your own decorators
Registration decorators
Consider creating your own Collector
How to create a context factory?
How to create your own key naming strategy?
This strategy will look for values in data which was passed to collect as "_{prototype property name}"
How to create your own ResponsePrototype property provider?
The provider must return the dto properties that are allowed to be processed by the collector! Don't forget to ignore AbstractResponsePrototype properties, otherwise these properties will be processed too