@@ -10,13 +10,10 @@ position: 1
1010
1111## Main features
1212
13- - 🚀 Retrieve values from Array (JSON) / XML with correct return type
14- - 🏆 Makes PHPStan / IDE happy due the return types
15- - 🤹 Validation: Ensures that desired value is in correct type (without additional loop validation. Validation is always
16- on
17- while calling get* method).
18- - 🛠 Transformers: Ensures that values are in expected type (ensures that string is trimmed and empty string converted to
19- null, accepts bool as string, can be changed.)
13+ - 🚀 Retrieve values from Array (JSON) / XML with correct return type with ** safe dot notation** support.
14+ - 🏆 ** Makes PHPStan / IDE** happy due the type strict return types.
15+ - 🤹 ** Validation:** Ensures that desired value is in correct type (without additional loop validation).
16+ - 🛠 ** Transformers:** Ensures that values are in expected type
2017
2118## Installation
2219
@@ -54,6 +51,42 @@ $simpleXMLElement = new SimpleXMLElement('<root><title>test</title><test attribu
5451$data = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\XMLData($simpleXMLElement));
5552```
5653
54+ ## Dot notation
55+
56+ Dot notation is implemented in safe manner (may differ from Laravel and other implementations when edge cases occurs).
57+
58+ String that is separated by '.' will always be converted to path of exact path keys. If you '.' in your array key / XML
59+ node name
60+ then you need to use array as a key. Examples below:
61+
62+ ``` php
63+ $getValue = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\ArrayData([
64+ 'get.key' => 'test',
65+ 'get' => [
66+ 'key' => 'child'
67+ ],
68+ 'co.uk' => 'domain',
69+ ]));
70+ $getValue->getString('get.key') // Returns: child
71+ $getValue->getString('co.uk') // Returns: null
72+ $getValue->getString(['get.key']) // Returns: test
73+ $getValue->getString(['co.uk']) // Returns: domain
74+ ```
75+
76+ This implementation ensures.
77+
78+ You can instead of dot notation use array path:
79+
80+ ``` php
81+ $getValue = new \Wrkflow\GetValue\GetValue(new \Wrkflow\GetValue\DataHolders\ArrayData([
82+ 'get' => [
83+ 'key' => 'child'
84+ ],
85+ ]));
86+ $getValue->getString(['get', 'key']) // Returns: test
87+ $getValue->getString(['get', 'no_value']) // Returns: null
88+ ```
89+
5790## Values
5891
5992> All values are validated within its type definition (int will be checked by IntegerRule, string by StringRule, etc).
@@ -73,7 +106,7 @@ Check [Validation documentation](/validation) for more.
73106Get nullable int.
74107
75108``` php
76- $value = $data->getInt('key', rules: [new \Wrkflow\GetValue\Rules\MinRule(0)] );
109+ $value = $data->getInt('key');
77110```
78111
79112Get required int value. Throws ` MissingValueForKeyException ` exception if missing.
@@ -100,7 +133,8 @@ $value = $data->getRequiredFloat('key');
100133
101134### Bool
102135
103- > Throws ` ValidationFailedException ` if value is not bool (only on non-null values).
136+ > ** In default strategy string [ bool variants] ( https://php-get-typed-value.wrk-flow.com/transformers/#transformtobool )
137+ are converted to bool** . Throws ` ValidationFailedException ` if value is not bool (only on non-null values).
104138
105139Get nullable bool value.
106140
@@ -116,8 +150,8 @@ $value = $data->getRequiredBool('key');
116150
117151### String
118152
119- > Throws ` ValidationFailedException ` if value is not string (only on non-null values). In default strategy empty string
120- > is treated as null.
153+ > ** In default strategy string is trimmed and empty string is transformed to null ** . Throws ` ValidationFailedException `
154+ > if value is not string (only on non- null values) .
121155
122156Get nullable string value.
123157
@@ -209,3 +243,20 @@ missing.
209243``` php
210244$value = $data->getRequiredArrayGetter('key');
211245```
246+
247+ ## Exceptions
248+
249+ > All exceptions receive full key that was used for getting data. You can receive it by using ` $exception->getKey() `
250+
251+ - ArrayIsEmptyException
252+ - MissingValueForKeyException
253+ - NotAnArrayException
254+ - ValidationFailedException
255+
256+ ## Notes
257+
258+ - ** Full key format** :
259+ - Parent full key is prepended to the key with '.' separator (if the GetValue instance was constructed from parent
260+ data).
261+ - Array notation is converted to dot notation string.
262+
0 commit comments