I'm finding myself dealing with the same problem in multiple bundles I've wrote.
The problem is that in my BundleNameBundle class I have to create the path to then load the mappings of Doctrine.
To do this I do something like:
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$modelDir = realpath(__DIR__ . '/Resources/config/doctrine/mappings');
$mappings = [
$modelDir => 'SerendipityHQ\Bundle\QueuesBundle\Model',
];
$ormCompilerClass = DoctrineOrmMappingsPass::class;
if (class_exists($ormCompilerClass)) {
$container->addCompilerPass(
$this->getYamlMappingDriver($mappings)
);
}
$container->addCompilerPass(new DaemonDependenciesPass());
}
Complete code here.
As you can see I use __DIR__ to get the path to the folder where the mappings are.
Now, Sensio Insights is alerting me that "Absolute path constants DIR and FILE should not be used".
Ok, but how can I solve this problem? Is there some alternative way to build the path to the mappings?