You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/9.0/reader/record-mapping.md
+35-33Lines changed: 35 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,16 @@ title: Deserializing a Tabular Data record into an object
9
9
10
10
## Assign an array to an object
11
11
12
-
To work with objects instead of arrays the `Serializer` class is introduced to expose a
12
+
To work with objects instead of arrays the `Deserializer` class is introduced to expose a
13
13
text based deserialization mechanism for tabular data.
14
14
15
15
The class exposes four (4) methods to ease `array` to `object` conversion:
16
16
17
-
-`Serializer::deserializeAll` and `Serializer::assignAll` which convert a collection of records into a collection of instances of a specified class.
18
-
-`Serializer::deserialize` and `Serializer::assign` which convert a single record into a new instance of the specified class.
17
+
-`Deserializer::deserializeAll` and `Deserializer::assignAll` which convert a collection of records into a collection of instances of a specified class.
18
+
-`Deserializer::deserialize` and `Deserializer::assign` which convert a single record into a new instance of the specified class.
19
19
20
20
```php
21
-
use League\Csv\Serializer;
21
+
use League\Csv\Deserializer;
22
22
23
23
$record = [
24
24
'date' => '2023-10-30',
@@ -29,7 +29,7 @@ $record = [
29
29
//a complete collection of records as shown below
30
30
$collection = [$record];
31
31
//we first instantiate the serializer
32
-
$serializer = new Serializer(Weather::class, ['date', 'temperature', 'place']);
32
+
$serializer = new Deserializer(Weather::class, ['date', 'temperature', 'place']);
33
33
34
34
$weather = $serializer->deserialize($record); //we convert 1 record into 1 instance
35
35
foreach ($serializer->deserializeAll($collection) as $weather) {
@@ -38,9 +38,9 @@ foreach ($serializer->deserializeAll($collection) as $weather) {
38
38
39
39
// you can use the alternate syntactic sugar methods
40
40
// if you only need the deserializing mechanism once
$propertySetters => thrownewMappingFailed('No properties or method setters were found eligible on the class `'.$this->class->getName().'` to be used for type casting.'),
229
+
default => $propertySetters,
230
+
231
+
};
215
232
}
216
233
217
234
/**
@@ -223,13 +240,11 @@ private function findPropertySettersByAttribute(array $propertyNames): array
223
240
{
224
241
$addPropertySetter = function (array$carry, ReflectionProperty|ReflectionMethod$accessor) use ($propertyNames) {
0 commit comments