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
Afficher le fichier Open project: leroy-merlin-br/mongolid Class Usage Examples

Méthodes publiques

Свойство Type Description
$schema Mongolid\Schema\Schema The actual schema to maps the data.

Protected Properties

Свойство Type Description
$castableTypes string[] Types that can be casted.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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

cast() protected méthode

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.
Résultat mixed

clearDynamic() protected méthode

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.
Résultat void

map() public méthode

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.
Résultat array

mapToSchema() protected méthode

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.
Résultat mixed

parseField() public méthode

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

parseToArray() protected méthode

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.
Résultat 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
Résultat string[]

$schema public_oe property

The actual schema to maps the data.
public Schema,Mongolid\Schema $schema
Résultat Mongolid\Schema\Schema