Created
August 13, 2022 15:32
-
-
Save benr77/ccd83565dc47197aa24624da8da4f4d6 to your computer and use it in GitHub Desktop.
Auto-registering Doctrine mappings in a Symfony bundle
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
<?php | |
declare(strict_types=1); | |
namespace Acme\DemoBundle; | |
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\HttpKernel\Bundle\Bundle; | |
class AcmeDemoBundle extends Bundle | |
{ | |
public function build(ContainerBuilder $container) | |
{ | |
parent::build($container); | |
$mappingFileLocation = '/Doctrine/Mapping'; | |
$modelDir = realpath(__DIR__ . $mappingFileLocation); | |
$mappings = [ | |
$modelDir => 'Demo', | |
]; | |
if (class_exists(DoctrineOrmMappingsPass::class)) { | |
$container->addCompilerPass( | |
DoctrineOrmMappingsPass::createXmlMappingDriver( | |
$mappings, | |
['doctrine.orm.entity_manager'], | |
false | |
) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment