Last active
December 7, 2020 13:49
-
-
Save pyrech/f880c67e5419dcff8bc9c6e24330f8e5 to your computer and use it in GitHub Desktop.
Force Doctrine schema validation and update to ignore some entities ("schema_filter" does not work here).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Doctrine/ClassMetadataFactory.php b/src/Doctrine/ClassMetadataFactory.php | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..f56ca274e79b3f93da587985b71260ea58ba5f76 | |
--- /dev/null | |
+++ b/src/Doctrine/ClassMetadataFactory.php | |
@@ -0,0 +1,25 @@ | |
+<?php | |
+ | |
+namespace App\Doctrine; | |
+ | |
+use App\Entity\MyEntityToIgnore; | |
+ | |
+class ClassMetadataFactory extends \Doctrine\ORM\Mapping\ClassMetadataFactory | |
+{ | |
+ const IGNORED_ENTITIES = [ | |
+ MyEntityToIgnore::class, | |
+ ]; | |
+ | |
+ public function getAllMetadata() | |
+ { | |
+ $allMetadata = parent::getAllMetadata(); | |
+ | |
+ foreach ($allMetadata as $key => $metadata) { | |
+ if (in_array($metadata->getName(), self::IGNORED_ENTITIES)) { | |
+ unset($allMetadata[$key]); | |
+ } | |
+ } | |
+ | |
+ return $allMetadata; | |
+ } | |
+} | |
diff --git a/src/Kernel.php b/src/Kernel.php | |
index a1c686ee1367421a393bfd954be59c9f78b39eef..91b40d9a805d0b02e7e280a958642fcf7f52f223 100644 | |
--- a/src/Kernel.php | |
+++ b/src/Kernel.php | |
@@ -2,6 +2,7 @@ | |
namespace App; | |
+use App\Doctrine\ClassMetadataFactory; | |
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | |
use Symfony\Component\Config\Loader\LoaderInterface; | |
use Symfony\Component\Config\Resource\FileResource; | |
@@ -56,4 +57,21 @@ class Kernel extends BaseKernel | |
$routes->import($confDir . '/{routes}/*' . self::CONFIG_EXTS, '/', 'glob'); | |
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob'); | |
} | |
+ | |
+ protected function build(ContainerBuilder $container) | |
+ { | |
+ parent::build($container); | |
+ | |
+ $container->addCompilerPass(new class() implements \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface { | |
+ public function process(\Symfony\Component\DependencyInjection\ContainerBuilder $container) | |
+ { | |
+ $container | |
+ ->getDefinition('doctrine.orm.default_configuration') | |
+ ->addMethodCall('setClassMetadataFactoryName', [ | |
+ ClassMetadataFactory::class, | |
+ ]) | |
+ ; | |
+ } | |
+ }); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not really sure if that would be fixed by doctrine/orm#7875