PHP Class 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
Exibir arquivo Open project: leroy-merlin-br/mongolid Class Usage Examples

Public Properties

Property Type Description
$schema Mongolid\Schema\Schema The actual schema to maps the data.

Protected Properties

Property Type Description
$castableTypes string[] Types that can be casted.

Public Methods

Method Description
__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.

Protected Methods

Method Description
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.

Method Details

__construct() public method

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

cast() protected method

Uses PHP's settype to cast a value to a type.
See also: 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.
return mixed

clearDynamic() protected method

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.
return void

map() public method

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.
return array

mapToSchema() protected method

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.
return mixed

parseField() public method

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.
return mixed $value Value parsed to match $type

parseToArray() protected method

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.
return array

Property Details

$castableTypes protected_oe property

Types that can be casted.
See also: http://php.net/manual/en/language.types.type-juggling.php
protected string[] $castableTypes
return string[]

$schema public_oe property

The actual schema to maps the data.
public Schema,Mongolid\Schema $schema
return Mongolid\Schema\Schema