Passed
Push — master ( a6591a...012b67 )
by Angel Fernando Quiroz
10:47 queued 26s
created

PluginEntityPass::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\DependencyInjection\Compiler;
8
9
use Chamilo\CoreBundle\Service\PluginEntityLoader;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Reference;
13
14
class PluginEntityPass implements CompilerPassInterface
15
{
16
    public function process(ContainerBuilder $container): void
17
    {
18
        /** @var PluginEntityLoader $pluginEntityLoader */
19
        $pluginEntityLoader = $container->get(PluginEntityLoader::class);
20
        $entityDirs = $pluginEntityLoader->getEntityDirectories();
21
22
        $metadataDriverDefinition = $container->getDefinition('doctrine.orm.default_metadata_driver');
23
24
        foreach ($entityDirs as $dir) {
25
            $pluginTitle = ucwords(basename(\dirname($dir)));
26
            $namespace = "Chamilo\\PluginBundle\\$pluginTitle";
27
28
            $driverReference = new Reference('doctrine.orm.default_attribute_metadata_driver');
29
30
            $metadataDriverDefinition->addMethodCall('addDriver', [$driverReference, $namespace]);
31
        }
32
    }
33
}
34