4
4
5
5
namespace AutoMapper \Generator ;
6
6
7
+ use AutoMapper \Configuration ;
7
8
use AutoMapper \Exception \CompileException ;
8
9
use AutoMapper \MapperContext ;
9
10
use AutoMapper \Metadata \GeneratorMetadata ;
10
11
use AutoMapper \Metadata \PropertyMetadata ;
11
- use MongoDB \BSON \Document ;
12
- use MongoDB \Model \BSONDocument ;
13
12
use PhpParser \Node \Arg ;
14
13
use PhpParser \Node \ArrayItem ;
15
14
use PhpParser \Node \Expr ;
@@ -35,6 +34,7 @@ class_alias(Expr\ArrayItem::class, ArrayItem::class);
35
34
private Parser $ parser ;
36
35
37
36
public function __construct (
37
+ private Configuration $ configuration ,
38
38
private ExpressionLanguage $ expressionLanguage ,
39
39
Parser $ parser = null ,
40
40
) {
@@ -47,7 +47,7 @@ public function generate(GeneratorMetadata $metadata, PropertyMetadata $property
47
47
48
48
$ conditions [] = $ this ->propertyExistsForStdClass ($ metadata , $ propertyMetadata );
49
49
$ conditions [] = $ this ->propertyExistsForArray ($ metadata , $ propertyMetadata );
50
- $ conditions [] = $ this ->propertyExistsForBSONDocument ($ metadata , $ propertyMetadata );
50
+ $ conditions [] = $ this ->propertyExistsForArrayAccess ($ metadata , $ propertyMetadata );
51
51
$ conditions [] = $ this ->isAllowedAttribute ($ metadata , $ propertyMetadata );
52
52
53
53
if (!$ propertyMetadata ->disableGroupsCheck ) {
@@ -127,15 +127,15 @@ private function propertyExistsForArray(GeneratorMetadata $metadata, PropertyMet
127
127
}
128
128
129
129
/**
130
- * In case of source is an array we ensure that the key exists .
130
+ * In case of source is an ArrayAccess implementation listed in the config .
131
131
*
132
132
* ```php
133
133
* $source->offsetExists('propertyName').
134
134
* ```
135
135
*/
136
- private function propertyExistsForBSONDocument (GeneratorMetadata $ metadata , PropertyMetadata $ propertyMetadata ): ?Expr
136
+ private function propertyExistsForArrayAccess (GeneratorMetadata $ metadata , PropertyMetadata $ propertyMetadata ): ?Expr
137
137
{
138
- if (!$ propertyMetadata ->source ->checkExists || !in_array ($ metadata ->mapperMetadata ->source , [Document::class, BSONDocument::class] , true )) {
138
+ if (!$ propertyMetadata ->source ->checkExists || !\ in_array ($ metadata ->mapperMetadata ->source , $ this -> configuration -> arrayAccessClasses , true )) {
139
139
return null ;
140
140
}
141
141
0 commit comments