Passed
Pull Request — master (#25)
by
unknown
13:18
created

DoctrineJsonOdmExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/*
3
 * This file is part of Goodwix Doctrine JSON ODM.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Goodwix\DoctrineJsonOdm\Bridge\Symfony\DependencyInjection;
10
11
use Ramsey\Collection\CollectionInterface;
12
use Ramsey\Collection\Map\TypedMapInterface;
13
use Symfony\Component\Config\FileLocator;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Extension\Extension;
16
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
19
class DoctrineJsonOdmExtension extends Extension implements PrependExtensionInterface
20
{
21 1
    public function prepend(ContainerBuilder $container): void
22
    {
23 1
        $frameworkConfiguration = $container->getExtensionConfig('framework');
24
25 1
        if (empty($frameworkConfiguration)) {
26
            return;
27
        }
28
29 1
        if (!isset($frameworkConfiguration['serializer']['enabled'])) {
30 1
            $container->prependExtensionConfig('framework', ['serializer' => ['enabled' => true]]);
31
        }
32
    }
33
34 5
    public function load(array $configs, ContainerBuilder $container): void
35
    {
36 5
        $this->loadServices($container);
37 5
        $this->prepareConfiguration($configs, $container);
38
    }
39
40 5
    private function loadServices(ContainerBuilder $container): void
41
    {
42 5
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
43 5
        $loader->load('services.xml');
44
45
        if (
46 5
            interface_exists(CollectionInterface::class)
47 5
            && interface_exists(TypedMapInterface::class)
48
        ) {
49 5
            $loader->load('ramsey_collection_normalizers.xml');
50
        }
51
    }
52
53 5
    private function prepareConfiguration(array $configs, ContainerBuilder $container): void
54
    {
55 5
        $configuration          = new Configuration();
56 5
        $processedConfiguration = $this->processConfiguration($configuration, $configs);
57
58 2
        $container->setParameter(ODMTypeCompilerPass::ODM_PATHS, $processedConfiguration['mapping']['paths']);
59
    }
60
}
61