| Total Complexity | 7 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class AlphaTwigBundle extends Bundle |
||
| 12 | { |
||
| 13 | private const PARAM_TEMPLATE_MAPPING_DIR = 'alpha_twig.entity.template.mapping_dir'; |
||
| 14 | private const PARAM_TEMPLATE_MAPPING_NAMESPACE = 'alpha_twig.entity.template.class'; |
||
| 15 | private const DEFAULT_TEMPLATE_MAPPING_NAMESPACE = 'Alpha\TwigBundle\Entity'; |
||
| 16 | |||
| 17 | public function build(ContainerBuilder $container): void |
||
| 18 | { |
||
| 19 | $this->addRegisterMappingsPass($container); |
||
| 20 | } |
||
| 21 | |||
| 22 | private function addRegisterMappingsPass(ContainerBuilder $container): void |
||
| 23 | { |
||
| 24 | $mappings = [ |
||
| 25 | $this->deriveMappingDir($container) => $this->deriveMappingNamespace($container), |
||
| 26 | ]; |
||
| 27 | |||
| 28 | $container->addCompilerPass(DoctrineOrmMappingsPass::createYamlMappingDriver($mappings)); |
||
| 29 | } |
||
| 30 | |||
| 31 | private function deriveMappingDir(ContainerBuilder $container): string |
||
| 32 | { |
||
| 33 | if ($container->hasParameter(self::PARAM_TEMPLATE_MAPPING_DIR)) { |
||
| 34 | return $container->getParameter(self::PARAM_TEMPLATE_MAPPING_DIR); |
||
| 35 | } |
||
| 36 | |||
| 37 | return realpath(__DIR__.'/Resources/config/doctrine'); |
||
| 38 | } |
||
| 39 | |||
| 40 | private function deriveMappingNamespace(ContainerBuilder $container): string |
||
| 53 | } |
||
| 54 | } |
||
| 55 |