@@ -11,7 +11,7 @@ position: 1
1111
1212- 🚀 Retrieve values from Array (JSON) / XML with correct return type
1313- 🏆 Makes PHPStan / IDE happy due the return types
14- - 🤹 Basic type without additional looping .
14+ - 🤹 Ensures that desired value is in correct type ( without additional loop validation. Validates always on get) .
1515
1616## Installation
1717
@@ -33,7 +33,10 @@ Simple build **GetValue** class with **ArrayData** class that will expose the da
3333``` php
3434$data = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\ArrayData([
3535 'page' => 1,
36- 'items' => [['name' => 'test', 'tags' => null, 'label' => 'yes'], ['name' => 'test 2', 'tags' => ['test']]]
36+ 'items' => [
37+ ['name' => 'test', 'tags' => null, 'label' => 'yes'],
38+ ['name' => 'test 2', 'tags' => ['test'],]
39+ ],
3740]));
3841```
3942
@@ -42,22 +45,28 @@ $data = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\ArrayDa
4245Simple build ** GetValue** class with ** XMLData** class that will expose the data.
4346
4447``` php
45- $data = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\XMLData(new SimpleXMLElement('<root ><title >test</title ><test attribute =" test" /></root >')));
48+ $simpleXMLElement = new SimpleXMLElement('<root ><title >test</title ><test attribute =" test" /></root >');
49+ $data = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\XMLData($simpleXMLElement));
4650```
4751
4852## Values
4953
54+ > All values are validated within its type definition (int will be checked by IntegerRule, string by StringRule, etc).
55+
5056For getting values there are always 2 methods:
5157
5258- get nullable value
5359- get required value
5460
61+ You can additionally add validation rules (as second parameter) to ensure you will get correct value.
62+ Check [ Validation documentation] ( /validation ) for more.
63+
5564### Int
5665
5766Get nullable int.
5867
5968``` php
60- $value = $data->getInt('key');
69+ $value = $data->getInt('key', rules: [new \Wrkflow\GetValue\Rules\MinRule(0)] );
6170```
6271
6372Get required int value. Throws ` MissingValueForKeyException ` exception if missing.
0 commit comments