Serializer
+ Inheritance diagram for Serializer:

Description

Converts an entity's values to/from storage types.

Protected Properties

string[] $dehydrate
 Maps complex types to storage types. More...
 
string[] $foreign = []
 Properties that are foreign keys to other entities. More...
 
string[] $hydrate = []
 The specific classes used to hydrate classed properties, like DateTime. More...
 
string[] $storageTypes = []
 Scalar storage types, after any dehydration is done. More...
 
DateTimeZone $utc
 
- Protected Properties inherited from Reflection
ReflectionClass $class
 
string[] $columns
 
DB $db
 
array $defaults = []
 
ReflectionProperty[] $properties = []
 
const RX_EAV = '/\*\h*@eav\h+(?<table>\w+)/i'
 
const RX_EAV_VAR = '/\*\h*@var\h+(?<type>\w+)\[\]/i'
 
const RX_FOREIGN = '/\*\h*@foreign\h+(?<column>\w+)\h+(?<class>\S+)/i'
 
const RX_IS_COLUMN = '/\*\h*@col(umn)?\b/i'
 
const RX_JUNCTION = '/\*\h*@junction\h+(?<table>\w+)/i'
 
const RX_NULL = '/(\bnull\|)|(\|null\b)/i'
 
const RX_RECORD = '/\*\h*@record\h+(?<table>\w+)/i'
 
const RX_UNIQUE = '/^\h*\*\h*@unique\h*$/im'
 
const RX_UNIQUE_GROUP = '/^\h*\*\h*@unique\h+(?<ident>[a-z_]+)\h*$/im'
 
const RX_VAR = '/\*\h*@var\h+(?<type>\S+)/i'
 

Public Methods

 __construct (DB $db, $class)
 
array export (EntityInterface $entity)
 Returns an entity's property values, dehydrating if needed. More...
 
string[] getForeign ()
 
string[] getStorageTypes ()
 Returns the scalar storage types of all properties. More...
 
void import (EntityInterface $entity, array $values)
 Sets values from storage on an entity, hydrating if needed. More...
 
- Public Methods inherited from Reflection
string[] getColumns ()
 
EAV[] getEav ()
 
string[] getForeignClasses ()
 Classes keyed by column. More...
 
string getJunctionTable ()
 
string getRecordTable ()
 
string getType (string $property)
 Scalar storage type, or FQN of a complex type. More...
 
string[] getUnique ()
 Columns with their own individual unique constraints. More...
 
string[][] getUniqueGroups ()
 Table-level (multi-column) constraints are grouped under an arbitrary shared identifier. More...
 
mixed getValue (object $object, string $property)
 Gets and returns a value through reflection. More...
 
bool isColumn (string $property)
 
bool isNullable (string $property)
 Whether a property allows NULL as a value. More...
 
bool isUnique (string $column)
 
bool isUniqueMulti (string $column, &$ident=null)
 
object newProto ()
 
void setValue (object $object, string $property, $value)
 Sets a value through reflection. More...
 

Protected Methods

null scalar dehydrate (string $to, string $from, $hydrated)
 Dehydrates a complex property's value for storage in a scalar column. More...
 
array object hydrate (string $to, string $from, $dehydrated)
 Hydrates a complex value from scalar storage. More...
 

Additional Inherited Members

- Public Properties inherited from Reflection
const SCALARS
 Maps annotated/native scalar types to storage types acceptable for settype() More...
 
- Public Static Methods inherited from Reflection
magic static self factory (DB $db, string|object $class)
 

Properties

◆ $dehydrate

string [] $dehydrate
protected
Initial value:
= [
'array' => 'STRING',
'object' => 'STRING',
stdClass::class => 'STRING',
DateTime::class => 'DateTime',
DateTimeImmutable::class => 'DateTime',
]

Maps complex types to storage types.

Foreign EntityInterface columns are automatically added as "int"

See also
Serializer::dehydrate()
Serializer::hydrate()
Schema::T_CONST_NAMES

◆ $foreign

string [] $foreign = []
protected

Properties that are foreign keys to other entities.

[ property => foreign entity class ]

◆ $hydrate

string [] $hydrate = []
protected

The specific classes used to hydrate classed properties, like DateTime.

[ property => class ]

◆ $storageTypes

string [] $storageTypes = []
protected

Scalar storage types, after any dehydration is done.

[property => type]

Constructor

◆ __construct()

__construct ( DB  $db,
  $class 
)
Parameters
DB$db
string | object$class

Reimplemented from Reflection.

Methods

◆ dehydrate()

null scalar dehydrate ( string  $to,
string  $from,
  $hydrated 
)
protected

Dehydrates a complex property's value for storage in a scalar column.

See also
Serializer::hydrate() inverse
Parameters
string$toThe storage type.
string$fromThe strict type from the class definition.
array | object$hydrated
Returns
null|scalar

◆ export()

array export ( EntityInterface  $entity)

Returns an entity's property values, dehydrating if needed.

Parameters
EntityInterface$entity
Returns
array

◆ getForeign()

string [] getForeign ( )
final
Returns
string[]

◆ getStorageTypes()

string [] getStorageTypes ( )
final

Returns the scalar storage types of all properties.

This doesn't include whether the properties are nullable. Use Serializer::isNullable() for that.

Returns
string[]

◆ hydrate()

array object hydrate ( string  $to,
string  $from,
  $dehydrated 
)
protected

Hydrates a complex value from scalar storage.

See also
Serializer::dehydrate() inverse
Parameters
string$toThe strict type from the class definition.
string$fromThe storage type.
scalar$dehydrated
Returns
array|object

◆ import()

void import ( EntityInterface  $entity,
array  $values 
)

Sets values from storage on an entity, hydrating if needed.

Parameters
EntityInterface$entity
array$values