11# Data Mapper
22
3- <primary-label ref =" mapper-component " />
3+ <primary-label ref =" mapper-component " xmlns = " " />
44<show-structure for =" chapter " depth =" 2 " />
55
66A mapper is a system that transforms internal data into external data
@@ -36,35 +36,40 @@ $mapper = new TypeLang\Mapper\Mapper();
3636```
3737
3838The mapper contains two transformation directions:
39- - ** Normalization** - the process of converting complex internal application
40- data to external data (API, database, etc.)
41- ``` php
42- $mapper = new TypeLang\Mapper\Mapper();
43-
44- $result = $mapper->normalize(new Example());
45- ```
46- - **Denormalization** - the process of converting primitive data to
47- application data types
48- ```php
39+ - <tooltip term =" normalize " >** Normalization** </tooltip > - the process of
40+ converting complex internal application data to external data (API,
41+ database, etc.)
42+ <code-block lang =" PHP " >
43+ $mapper = new TypeLang\Mapper\Mapper();
44+
45+ $result = $mapper->normalize(new Example());
46+ </code-block >
47+ - <tooltip term =" denormalize " >** Denormalization** </tooltip > - the process of
48+ converting simple external data to internal application data types
49+ <code-block lang =" PHP " >
4950 $mapper = new TypeLang\Mapper\Mapper();
5051
5152 $result = $mapper->denormalize($data, Example::class);
52- ```
53+ </ code-block >
5354
54- As you can see, the denormalization process requires information about the type
55- to which the incoming data will be converted.
55+ As you can see, the < tooltip term = " denormalize " > denormalization process</ tooltip >
56+ requires information about the type to which the incoming data will be converted.
5657
57- With normalization, the type is optional, as it can be determined automatically
58- based on the incoming data, but can also be explicitly specified as a
59- second argument.
58+ With < tooltip term = " normalize " > normalization</ tooltip > , the type is optional,
59+ as it can be [ determined automatically ] ( type-extractors.md ) based on the
60+ incoming data, but can also be explicitly specified as a second argument.
6061
6162``` php
6263$mapper->normalize(new Example(), Example::class);
6364```
6465
65- The type specified in the second argument of the normalization and
66- denormalization methods can be arbitrary, as described in the
67- [ language grammar] ( introduction.md ) section.
66+ The type specified in the second argument of the
67+ <tooltip term =" normalize " >normalization</tooltip > and
68+ <tooltip term =" denormalize " >denormalization</tooltip > methods can be arbitrary,
69+ as described in the [ language grammar] ( introduction.md ) section.
70+
71+ An example of this "type definition" is shown below. However, the capabilities
72+ (and existence) of this type depend on [ the platform] ( mapper-platforms.md ) .
6873
6974``` php
7075$result = $mapper->normalize(new Example(), <<<'PHP'
@@ -79,5 +84,36 @@ The types themselves, their availability, capabilities, functionality and
7984behavior depend on the selected platform.
8085
8186<note >
82- The general <b >standard</b > <a href =" platforms.md " >platform</a > one is used by default
83- </note >
87+ The general <a href =" standard-platform.md " ><b >standard</b > platform</a >
88+ one is used by default
89+ </note >
90+
91+
92+ ## Customization
93+
94+ The ` Mapper ` can also take several additional arguments.
95+
96+ ``` php
97+ $mapper = new TypeLang\Mapper\Mapper(
98+ [[[platform: ...,|mapper-platforms.md]]]
99+ [[[config: ...,|mapper-configuration.md]]]
100+ [[[typeExtractorFactory: ...,|type-extractors.md]]]
101+ typeParserFactory: ...,
102+ typeRepositoryFactory: ...,
103+ );
104+ ```
105+
106+ - ` platform ` - Allows to specify a set of specific types, type coercers,
107+ and syntax rules
108+ <tip >For more details, see the
109+ <a href =" mapper-platforms.md " >"platform" documentation</a ></tip >
110+ - ` config ` - Allows to specify a custom configuration
111+ <tip >For more details, see the
112+ <a href =" mapper-configuration.md " >"configuration" documentation</a ></tip >
113+ - ` typeExtractorFactory ` - Allows to specify custom rules for inferring types
114+ from values
115+ <tip >For more details, see the
116+ <a href =" type-extractors.md " >"type extractors" documentation</a ></tip >
117+ - ` typeParserFactory ` - Allows to specify custom type parsing rules
118+ - ` typeRepositoryFactory ` - Allows to specify a custom implementation of
119+ the type registry (repository)
0 commit comments