1818use function array_slice ;
1919use function explode ;
2020use function is_array ;
21+ use function is_string ;
2122use function join ;
23+ use function str_contains ;
2224
2325/**
2426 * Class ExtendedArguments
3032 *
3133 * @property array $data
3234 */
35+
36+ #[\AllowDynamicProperties]
3337class ExtendedArguments extends Arguments
3438{
39+ public function __construct (protected array $ data = [])
40+ {
41+ $ this ->data = [];
42+ foreach ($ data as $ index => $ value ) {
43+ $ this ->set ($ index , $ value );
44+ }
45+ }
46+
3547 public function get (string $ index , mixed $ default = null ): mixed
3648 {
3749 return $ this ->find ($ index , $ default );
3850 }
3951
4052 public function set (mixed $ index , mixed $ value ): static
4153 {
54+ if (is_string ($ index ) && false === str_contains ($ index , '. ' )) {
55+ return parent ::set ($ index , $ value );
56+ }
4257 $ data =& $ this ->data ;
43- foreach (explode ('. ' , $ index ) as $ i ) {
44- if (false === is_array ( $ data [ $ i ] ) ||
45- false === array_key_exists ( $ i , $ data )
58+ foreach (explode ('. ' , ( string ) $ index ) as $ i ) {
59+ if (false === array_key_exists ( $ i , $ data ) ||
60+ false === is_array ( $ data[ $ i ] )
4661 ) {
4762 $ data [$ i ] = [];
4863 }
@@ -62,6 +77,9 @@ public function append(string $index, mixed $value): static
6277
6378 public function has (string $ index ): bool
6479 {
80+ if (false === str_contains ($ index , '. ' )) {
81+ return array_key_exists ($ index , $ this ->data );
82+ }
6583 $ data =& $ this ->data ;
6684 foreach (explode ('. ' , $ index ) as $ i ) {
6785 if (false === is_array ($ data ) ||
@@ -76,10 +94,13 @@ public function has(string $index): bool
7694
7795 public function delete (string $ index ): static
7896 {
97+ if (false === str_contains ($ index , '. ' )) {
98+ return parent ::delete ($ index );
99+ }
79100 $ data =& $ this ->data ;
80101 foreach (explode ('. ' , $ index ) as $ i ) {
81- if (false === is_array ( $ data [ $ i ] ) ||
82- false === array_key_exists ( $ i , $ data )
102+ if (false === array_key_exists ( $ i , $ data ) ||
103+ false === is_array ( $ data[ $ i ] )
83104 ) {
84105 continue ;
85106 }
0 commit comments