@@ -8,7 +8,7 @@ title: Denormalize a Tabular Data record into an object
8
8
<p class =" message-notice " >New in version <code >9.12.0</code ></p >
9
9
10
10
If you are working with a class which implements the ` TabularDataReader ` interface you can now deserialize
11
- your data using the ` TabularDataReader::getObjects ` method. The method will convert your document records
11
+ your data using the ` TabularDataReader::getRecordsAsObject ` method. The method will convert your document records
12
12
into objects using PHP's powerful Reflection API.
13
13
14
14
Here's an example using the ` Reader ` class which implements the ` TabularDataReader ` interface:
@@ -18,7 +18,7 @@ use League\Csv\Reader;
18
18
19
19
$csv = Reader::createFromString($document);
20
20
$csv->setHeaderOffset(0);
21
- foreach ($csv->getObjects (ClimaticRecord::class) as $weather) {
21
+ foreach ($csv->getRecordsAsObject (ClimaticRecord::class) as $weather) {
22
22
// each $weather entry will be an instance of the ClimaticRecord class;
23
23
}
24
24
```
@@ -89,14 +89,14 @@ enum Place
89
89
}
90
90
```
91
91
92
- To get instances of your object, you now can call ` TabularDataReader::getObjects ` which returns
92
+ To get instances of your object, you now can call ` TabularDataReader::getRecordsAsObject ` which returns
93
93
an ` Iterator ` containing only instances of your specified class.
94
94
95
95
``` php
96
96
use League\Csv\Reader;
97
97
98
98
$csv = Reader::createFromString($document);
99
- foreach ($csv->getObjects (ClimaticRecord::class) as $instance) {
99
+ foreach ($csv->getRecordsAsObject (ClimaticRecord::class) as $instance) {
100
100
// each $instance entry will be an instance of the ClimaticRecord class;
101
101
}
102
102
```
@@ -166,7 +166,7 @@ The attribute can take up to four (4) arguments which are all optional:
166
166
<p class =" message-info " >The <code >ignore</code > argument was added in version <code >9.13.0</code ></p >
167
167
<p class =" message-info " >You can use the mechanism on a CSV without a header row but it requires
168
168
adding a <code >MapCell</code > attribute on each property or method needed for the conversion. Or you
169
- can use the optional second argument of <code >TabularDataReader::getObjects </code > to specify the
169
+ can use the optional second argument of <code >TabularDataReader::getRecordsAsObject </code > to specify the
170
170
header value, just like with <code >TabularDataReader::getRecords</code ></p >
171
171
172
172
In any case, if type casting fails, an exception will be thrown.
@@ -228,15 +228,15 @@ use League\Csv\Serializer\Denormalizer;
228
228
229
229
$csv = Reader::createFromString($document);
230
230
$csv->setHeaderOffset(0);
231
- foreach ($csv->getObjects (ClimaticRecord::class) {
231
+ foreach ($csv->getRecordsAsObject (ClimaticRecord::class) {
232
232
// the first record contains an empty string for temperature
233
233
// it is converted into the null value and handle by the
234
234
// default conversion type casting;
235
235
}
236
236
237
237
Denormalizer::disallowEmptyStringAsNull();
238
238
239
- foreach ($csv->getObjects (ClimaticRecord::class) {
239
+ foreach ($csv->getRecordsAsObject (ClimaticRecord::class) {
240
240
// a TypeCastingFailed exception is thrown because we
241
241
// can not convert the empty string into a valid
242
242
// temperature property value
0 commit comments