@@ -70,7 +70,7 @@ private function getConstructorParameters(string $class): iterable
70
70
}
71
71
}
72
72
73
- public function getReadAccessor (string $ class , string $ property ): ?ReadAccessor
73
+ public function getReadAccessor (string $ class , string $ property, bool $ allowExtraProperties = false ): ?ReadAccessor
74
74
{
75
75
if ('array ' === $ class ) {
76
76
return new ReadAccessor (ReadAccessor::TYPE_ARRAY_DIMENSION , $ property );
@@ -83,6 +83,14 @@ public function getReadAccessor(string $class, string $property): ?ReadAccessor
83
83
$ readInfo = $ this ->readInfoExtractor ->getReadInfo ($ class , $ property );
84
84
85
85
if (null === $ readInfo ) {
86
+ if ($ allowExtraProperties ) {
87
+ $ implements = class_implements ($ class );
88
+
89
+ if ($ implements !== false && \in_array (\ArrayAccess::class, $ implements , true )) {
90
+ return new ReadAccessor (ReadAccessor::TYPE_ARRAY_ACCESS , $ property );
91
+ }
92
+ }
93
+
86
94
return null ;
87
95
}
88
96
@@ -101,15 +109,27 @@ public function getReadAccessor(string $class, string $property): ?ReadAccessor
101
109
);
102
110
}
103
111
104
- public function getWriteMutator (string $ source , string $ target , string $ property , array $ context = []): ?WriteMutator
112
+ public function getWriteMutator (string $ source , string $ target , string $ property , array $ context = [], bool $ allowExtraProperties = false ): ?WriteMutator
105
113
{
106
114
$ writeInfo = $ this ->writeInfoExtractor ->getWriteInfo ($ target , $ property , $ context );
107
115
108
- if (null === $ writeInfo ) {
109
- return null ;
110
- }
116
+ if (null === $ writeInfo || PropertyWriteInfo::TYPE_NONE === $ writeInfo ->getType ()) {
117
+ if ('array ' === $ target ) {
118
+ return new WriteMutator (WriteMutator::TYPE_ARRAY_DIMENSION , $ property , false );
119
+ }
120
+
121
+ if (\stdClass::class === $ target ) {
122
+ return new WriteMutator (WriteMutator::TYPE_PROPERTY , $ property , false );
123
+ }
124
+
125
+ if ($ allowExtraProperties ) {
126
+ $ implements = class_implements ($ target );
127
+
128
+ if ($ implements !== false && \in_array (\ArrayAccess::class, $ implements , true )) {
129
+ return new WriteMutator (WriteMutator::TYPE_ARRAY_DIMENSION , $ property , false );
130
+ }
131
+ }
111
132
112
- if (PropertyWriteInfo::TYPE_NONE === $ writeInfo ->getType ()) {
113
133
return null ;
114
134
}
115
135
0 commit comments