Skip to content

Commit 06f5399

Browse files
committed
Invalidating cached AnnotationDriver::$classNames to find new entities
1 parent 8b7c291 commit 06f5399

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Doctrine/DoctrineHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Doctrine;
1313

1414
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
15+
use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver;
1516
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
1617
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain;
1718
use Doctrine\ORM\EntityManagerInterface;
@@ -145,6 +146,19 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
145146
foreach ($loaded as $m) {
146147
$cmf->setMetadataFor($m->getName(), $m);
147148
}
149+
150+
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
151+
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();
152+
if ($metadataDriver instanceof MappingDriverChain) {
153+
foreach ($metadataDriver->getDrivers() as $driver) {
154+
if ($driver instanceof AnnotationDriver) {
155+
$classNames = (new \ReflectionObject($driver))->getProperty('classNames');
156+
$classNames->setAccessible(true);
157+
$classNames->setValue($driver, null);
158+
$classNames->setAccessible(false);
159+
}
160+
}
161+
}
148162
}
149163

150164
foreach ($cmf->getAllMetadata() as $m) {

0 commit comments

Comments
 (0)