Reflection
+ Inheritance diagram for Reflection:

Description

Interprets classes and annotations, and manipulates objects.

Programmer's Note: Manipulating subclasses through a parent's reflection is allowed.

@TODO Allow column aliasing.

Public Properties

const SCALARS
 Maps annotated/native scalar types to storage types acceptable for settype() More...
 

Protected Properties

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 Static Methods

magic static self factory (DB $db, string|object $class)
 

Public Methods

 __construct (DB $db, $class)
 
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...
 

Properties

◆ SCALARS

const SCALARS
Initial value:
= [
'bool' => 'bool',
'boolean' => 'bool',
'double' => 'float',
'false' => 'bool',
'float' => 'float',
'int' => 'int',
'integer' => 'int',
'NULL' => 'string',
'number' => 'string',
'scalar' => 'string',
'string' => 'string',
'String' => 'String',
'STRING' => 'STRING',
'true' => 'bool',
]

Maps annotated/native scalar types to storage types acceptable for settype()

See also
Schema::T_CONST_NAMES keys

Constructor

◆ __construct()

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

Reimplemented in Serializer.

Methods

◆ factory()

magic static self factory ( DB  $db,
string|object  $class 
)
static
Returns
self

◆ getColumns()

string [] getColumns ( )
final
Returns
string[]

◆ getEav()

EAV [] getEav ( )
Returns
EAV[]

◆ getForeignClasses()

string [] getForeignClasses ( )

Classes keyed by column.

Returns
string[]

◆ getJunctionTable()

string getJunctionTable ( )
Returns
string

◆ getRecordTable()

string getRecordTable ( )
Returns
string

◆ getType()

string getType ( string  $property)

Scalar storage type, or FQN of a complex type.

Parameters
string$property
Returns
string

◆ getUnique()

string [] getUnique ( )

Columns with their own individual unique constraints.

Returns
string[]

◆ getUniqueGroups()

string [][] getUniqueGroups ( )

Table-level (multi-column) constraints are grouped under an arbitrary shared identifier.

[ shared identifier => [ col, ... ], ... ]

Returns
string[][]

◆ getValue()

mixed getValue ( object  $object,
string  $property 
)

Gets and returns a value through reflection.

Parameters
object$object
string$property
Returns
mixed

◆ isColumn()

bool isColumn ( string  $property)
Parameters
string$property
Returns
bool

◆ isNullable()

bool isNullable ( string  $property)

Whether a property allows NULL as a value.

Parameters
string$property
Returns
bool

◆ isUnique()

bool isUnique ( string  $column)
Parameters
string$column
Returns
bool

◆ isUniqueMulti()

bool isUniqueMulti ( string  $column,
$ident = null 
)
Parameters
string$column
void$identUpdated to the group identifier.
Returns
bool

◆ newProto()

object newProto ( )
Returns
object

◆ setValue()

void setValue ( object  $object,
string  $property,
  $value 
)

Sets a value through reflection.

Parameters
object$object
string$property
mixed$value