@@ -311,6 +311,8 @@ $value = $data->getRequiredArrayGetter('key');
311
311
312
312
### Get SimpleXMLElement
313
313
314
+ > Since v0.6.0
315
+
314
316
Return SimpleXMLElement for given key. Uses ` xml ` transformer strategy.
315
317
316
318
``` php
@@ -319,7 +321,8 @@ $xml = $data->getNullableXML('child');
319
321
320
322
### GetValue with XMLData
321
323
322
- > Throws always ` NotXMLException ` exception if value is not a SimpleXMLElement. XML transformer strategy is applied.
324
+ > Since v0.6.0. Throws always ` NotXMLException ` exception if value is not a SimpleXMLElement. XML transformer strategy
325
+ > is applied.
323
326
324
327
Get always ` GetValue ` instance even if provided data is missing or if null.
325
328
@@ -342,7 +345,8 @@ $value = $data->getRequiredXMLGetter('key');
342
345
343
346
### GetValue XML attributes
344
347
345
- > Throws always ` NotXMLException ` exception if value is not a SimpleXMLElement. XML transformer strategy is applied.
348
+ > Since v0.6.0. Throws always ` NotXMLException ` exception if value is not a SimpleXMLElement. XML transformer strategy
349
+ > is applied.
346
350
347
351
Wraps XML element attributes in GetValue instance (even if attributes are not set in element).
348
352
@@ -358,6 +362,51 @@ $attributes = $data->getXMLAttributesGetter('node');
358
362
$attributes->getString('attributeName');
359
363
```
360
364
365
+ ### GetObject
366
+
367
+ > Since v0.6.1
368
+
369
+ - Allows getting object of specified type.
370
+ - You can transform raw value to expected object by using transformers (with ` GetterTransformer ` )
371
+
372
+ ``` php
373
+ use Wrkflow\GetValue\Contracts\GetValueTransformerContract;
374
+ use Wrkflow\GetValue\GetValue;
375
+ use Wrkflow\GetValue\DataHolders\ArrayData;
376
+ use Wrkflow\GetValue\Transformers\GetterTransformer;
377
+
378
+ $data = new GetValue(new ArrayData([
379
+ 'person' => ['name' => 'Marco', 'surname' => 'Polo'],
380
+ ]));
381
+
382
+ class PersonEntity
383
+ {
384
+ public function __construct(
385
+ public readonly string $firstName,
386
+ public readonly string $lastName,
387
+ ) {
388
+ }
389
+ }
390
+
391
+ class TestEntityTransformer implements GetValueTransformerContract
392
+ {
393
+ public function transform(GetValue $value, string $key): PersonEntity
394
+ {
395
+ return new PersonEntity(
396
+ firstName: $value->getRequiredString('name'),
397
+ lastName: $value->getRequiredString('surname'),
398
+ );
399
+ }
400
+ }
401
+
402
+ $person = $this->data->getObject(
403
+ Person::class,
404
+ 'person',
405
+ new PersonTransformer()
406
+ );
407
+ // PersonEntity{firstName=Marco,lastName=Polo}
408
+ ```
409
+
361
410
## Exceptions
362
411
363
412
> All exceptions receive full key that was used for getting data. You can receive it by using ` $exception->getKey() `
0 commit comments