Documentation

Encoder
in package

Apply Property definitions to an object to generate a simplified stdClass object suitable for encoding into JSON/YAML/etc.

Table of Contents

__construct()  : mixed
Construct the encoder, optionally initialize with properties.
addProperties()  : Encoder
Add a list of properties to be coded.
addProperty()  : Encoder
Add a property to be coded.
bind()  : $this
Bind an object instance or class name.
encode()  : stdClass
Encode an object to a generic class using the defined properties.
encodeProperty()  : bool
Apply encoding rules to a standalone value or object property.
getProperties()  : array<string|int, Property>
Get the current property definitions (indexed by target name).

Methods

__construct()

Construct the encoder, optionally initialize with properties.

public __construct([array<string|int, Property$properties = [] ]) : mixed
Parameters
$properties : array<string|int, Property> = []
Tags
throws
HydrationException
Return values
mixed

addProperties()

Add a list of properties to be coded.

public addProperties(array<string|int, mixed> $properties[, array<string|int, mixed> $options = [] ]) : Encoder
Parameters
$properties : array<string|int, mixed>

Elements are any of 'propertyName', ['sourceName', 'targetName'] or a Property object.

$options : array<string|int, mixed> = []

Common attributes to apply to the new properties. Options are any public method of the Property class, except __construct, as, assign, make, and reflects. Use an array to pass multiple arguments.

Tags
throws
HydrationException
Return values
Encoder

bind()

Bind an object instance or class name.

public bind(class-string|object $subject) : $this
Parameters
$subject : class-string|object

Name or instance of the class to bind the hydrator to.

Tags
throws
HydrationException
throws
ReflectionException
Return values
$this

encode()

Encode an object to a generic class using the defined properties.

public encode(object $source) : stdClass
Parameters
$source : object

The object containing the information to be encoded.

Tags
throws
HydrationException
throws
ReflectionException
Return values
stdClass

encodeProperty()

Apply encoding rules to a standalone value or object property.

public encodeProperty(mixed &$value, array<string|int, EncoderRule$rules[, object|null $source = null ]) : bool
Parameters
$value : mixed

The value to be encoded. Passed by reference.

$rules : array<string|int, EncoderRule>

A list of encoder rules to be applied to the value.

$source : object|null = null

The object this value belongs to.

Tags
throws
HydrationException
throws
ReflectionException
Return values
bool

True if the resulting value should be included in the encoded result.

getProperties()

Get the current property definitions (indexed by target name).

public getProperties() : array<string|int, Property>
Return values
array<string|int, Property>

Search results