@@ -93,11 +93,37 @@ public function evaluate(array $data)
93
93
if (!isset ($ arguments ['class ' ])) {
94
94
throw new \InvalidArgumentException ('Node "argument" with name "class" is required for this type. ' );
95
95
}
96
+
96
97
$ className = $ arguments ['class ' ];
97
98
unset($ arguments ['class ' ]);
99
+
100
+ $ type = $ this ->objectManagerConfig ->getInstanceType (
101
+ $ this ->objectManagerConfig ->getPreference ($ className )
102
+ );
103
+
104
+ $ classParents = $ this ->getParents ($ type );
105
+
106
+ $ whitelistIntersection = array_intersect ($ classParents , $ this ->classWhitelist );
107
+
108
+ if (empty ($ whitelistIntersection )) {
109
+ throw new \InvalidArgumentException (
110
+ sprintf ('Class argument is invalid: %s ' , $ className )
111
+ );
112
+ }
98
113
}
99
114
100
- $ this ->isValid ($ className );
115
+ $ type = $ this ->objectManagerConfig ->getInstanceType (
116
+ $ this ->objectManagerConfig ->getPreference ($ className )
117
+ );
118
+ $ classParents = $ this ->getParents ($ type );
119
+
120
+ $ deniedIntersection = array_intersect ($ classParents , $ this ->deniedClassList );
121
+
122
+ if (!empty ($ deniedIntersection )) {
123
+ throw new \InvalidArgumentException (
124
+ sprintf ('Class argument is invalid: %s ' , $ className )
125
+ );
126
+ }
101
127
102
128
return $ this ->objectManager ->create ($ className , $ arguments );
103
129
}
@@ -120,30 +146,4 @@ private function getParents(string $type)
120
146
121
147
return $ classParents ;
122
148
}
123
-
124
- /**
125
- * Check that provided class could be evaluated like an argument.
126
- *
127
- * @param string $className
128
- * @throws \InvalidArgumentException
129
- */
130
- private function isValid (string $ className ): void
131
- {
132
- $ type = $ this ->objectManagerConfig ->getInstanceType (
133
- $ this ->objectManagerConfig ->getPreference ($ className )
134
- );
135
-
136
- $ classParents = $ this ->getParents ($ type );
137
-
138
- if (!empty ($ classParents )) {
139
- $ whitelistIntersection = array_intersect ($ classParents , $ this ->classWhitelist );
140
- $ deniedIntersection = array_intersect ($ classParents , $ this ->deniedClassList );
141
-
142
- if (empty ($ whitelistIntersection ) || !empty ($ deniedIntersection )) {
143
- throw new \InvalidArgumentException (
144
- sprintf ('Class argument is invalid: %s ' , $ className )
145
- );
146
- }
147
- }
148
- }
149
149
}
0 commit comments