PHP Класс Mongolid\DataMapper\SchemaMapper

When instantiating a SchemaMapper you should provide a Schema. When calling 'map' the Schema provided will be used to format the data to the correct format. This class is meant to do the opposite of the EntityAssembler
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$schema Mongolid\Schema\Schema The actual schema to maps the data.

Защищенные свойства (Protected)

Свойство Тип Описание
$castableTypes string[] Types that can be casted.

Открытые методы

Метод Описание
__construct ( Schema $schema )
map ( array | object $data ) : array Maps the input $data to the schema specified in the $schema property.
parseField ( mixed $value, string $fieldType ) : mixed Parse a value based on a field yype of the schema.

Защищенные методы

Метод Описание
cast ( mixed $value, string $type ) : mixed Uses PHP's settype to cast a value to a type.
clearDynamic ( array &$data ) : void If the schema is not dynamic, remove all non specified fields.
mapToSchema ( mixed $value, string $schemaClass ) : mixed Instantiate another SchemaMapper with the given $schemaClass and maps the given $value.
parseToArray ( mixed $object ) : array Parses an object to an array before sending it to the SchemaMapper.

Описание методов

__construct() публичный Метод

public __construct ( Schema $schema )
$schema Mongolid\Schema\Schema Schema that will be used to map each field.

cast() защищенный Метод

Uses PHP's settype to cast a value to a type.
См. также: http://php.net/manual/pt_BR/function.settype.php
protected cast ( mixed $value, string $type ) : mixed
$value mixed Value to be casted.
$type string Type to which the $value should be casted to.
Результат mixed

clearDynamic() защищенный Метод

If the schema is not dynamic, remove all non specified fields.
protected clearDynamic ( array &$data ) : void
$data array Reference of the fields. The passed array will be modified.
Результат void

map() публичный Метод

Maps the input $data to the schema specified in the $schema property.
public map ( array | object $data ) : array
$data array | object Array or object with the fields that should be mapped to $this->schema specifications.
Результат array

mapToSchema() защищенный Метод

Instantiate another SchemaMapper with the given $schemaClass and maps the given $value.
protected mapToSchema ( mixed $value, string $schemaClass ) : mixed
$value mixed Value that will be mapped.
$schemaClass string Class that will be passed to the new SchemaMapper constructor.
Результат mixed

parseField() публичный Метод

Parse a value based on a field yype of the schema.
public parseField ( mixed $value, string $fieldType ) : mixed
$value mixed Value to be parsed.
$fieldType string Description of how the field should be treated.
Результат mixed $value Value parsed to match $type

parseToArray() защищенный Метод

Parses an object to an array before sending it to the SchemaMapper.
protected parseToArray ( mixed $object ) : array
$object mixed The object that will be transformed into an array.
Результат array

Описание свойств

$castableTypes защищенное свойство

Types that can be casted.
См. также: http://php.net/manual/en/language.types.type-juggling.php
protected string[] $castableTypes
Результат string[]

$schema публичное свойство

The actual schema to maps the data.
public Schema,Mongolid\Schema $schema
Результат Mongolid\Schema\Schema