8
8
use Magento \Framework \Code \Generator \DefinedClasses ;
9
9
use Magento \Framework \Code \Generator \EntityAbstract ;
10
10
use Magento \Framework \Code \Generator \Io ;
11
+ use Magento \Framework \ObjectManager \ConfigInterface ;
11
12
use Magento \Framework \ObjectManagerInterface ;
12
13
use Magento \Framework \Phrase ;
13
14
use Magento \Framework \Filesystem \Driver \File ;
@@ -232,7 +233,21 @@ protected function shouldSkipGeneration($resultEntityType, $sourceClassName, $re
232
233
{
233
234
if (!$ resultEntityType || !$ sourceClassName ) {
234
235
return self ::GENERATION_ERROR ;
235
- } elseif ($ this ->definedClasses ->isClassLoadableFromDisk ($ resultClass )) {
236
+ }
237
+
238
+ /** @var ConfigInterface $omConfig */
239
+ $ omConfig = $ this ->objectManager ->get (ConfigInterface::class);
240
+ $ virtualTypes = $ omConfig ->getVirtualTypes ();
241
+
242
+ /**
243
+ * Do not try to autogenerate virtual types
244
+ * For example virtual types with names overlapping autogenerated suffixes
245
+ */
246
+ if (isset ($ virtualTypes [$ resultClass ])) {
247
+ return self ::GENERATION_SKIP ;
248
+ }
249
+
250
+ if ($ this ->definedClasses ->isClassLoadableFromDisk ($ resultClass )) {
236
251
$ generatedFileName = $ this ->_ioObject ->generateResultFileName ($ resultClass );
237
252
/**
238
253
* Must handle two edge cases: a competing process has generated the class and written it to disc already,
@@ -244,9 +259,12 @@ protected function shouldSkipGeneration($resultEntityType, $sourceClassName, $re
244
259
$ this ->_ioObject ->includeFile ($ generatedFileName );
245
260
}
246
261
return self ::GENERATION_SKIP ;
247
- } elseif (!isset ($ this ->_generatedEntities [$ resultEntityType ])) {
262
+ }
263
+
264
+ if (!isset ($ this ->_generatedEntities [$ resultEntityType ])) {
248
265
throw new \InvalidArgumentException ('Unknown generation entity. ' );
249
266
}
267
+
250
268
return false ;
251
269
}
252
270
}
0 commit comments