Passed
Push — develop ( 53a66f...07e04a )
by Daniel
05:35
created

SilverbackApiComponentExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\DependencyInjection;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Silverback\ApiComponentBundle\Factory\Entity\Component\AbstractComponentFactory;
7
use Silverback\ApiComponentBundle\Factory\Entity\Component\ComponentFactoryInterface;
8
use Silverback\ApiComponentBundle\Form\FormTypeInterface;
9
use Silverback\ApiComponentBundle\Form\Handler\FormHandlerInterface;
10
use Symfony\Component\Config\FileLocator;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
use Symfony\Component\DependencyInjection\Extension\Extension;
13
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
14
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
class SilverbackApiComponentExtension extends Extension implements PrependExtensionInterface
18
{
19
    /**
20
     * @param array $configs
21
     * @param ContainerBuilder $container
22
     * @throws \Exception
23
     */
24
    public function load(array $configs, ContainerBuilder $container)
25
    {
26
        $this->loadServiceConfig($container);
27
    }
28
29
    /**
30
     * @param ContainerBuilder $container
31
     * @throws \Exception
32
     */
33
    private function loadServiceConfig(ContainerBuilder $container)
34
    {
35
        $loader = new PhpFileLoader(
36
            $container,
37
            new FileLocator(__DIR__ . '/../Resources/config')
38
        );
39
        $loader->load('services.php');
40
41
        $container->registerForAutoconfiguration(FormHandlerInterface::class)
42
            ->addTag('silverback_api_component.form_handler')
43
            ->setLazy(true)
44
        ;
45
        $container->registerForAutoconfiguration(FormTypeInterface::class)
46
            ->addTag('silverback_api_component.form_type')
47
        ;
48
        $container->registerForAutoconfiguration(ComponentFactoryInterface::class)
49
            ->setParent(AbstractComponentFactory::class)
50
        ;
51
        $container->register(AbstractComponentFactory::class)
52
            ->setAbstract(true)
53
            ->addArgument(new Reference(ObjectManager::class))
54
        ;
55
    }
56
57
    /**
58
     * @param ContainerBuilder $container
59
     * @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
60
     */
61
    public function prepend(ContainerBuilder $container)
62
    {
63
        $bundles = $container->getParameter('kernel.bundles');
64
        $container->prependExtensionConfig('api_platform', [
65
            'eager_loading' => [
66
                'force_eager' => false
67
            ]
68
        ]);
69
        if (isset($bundles['LiipImagineBundle'])) {
70
            $container->prependExtensionConfig('liip_imagine', [
71
                'loaders' => [
72
                    'default' => [
73
                        'filesystem' => [
74
                            'data_root' => '%kernel.project_dir%/public'
75
                        ]
76
                    ]
77
                ],
78
                'filter_sets' => [
79
                    'placeholder_square' => [
80
                        'jpeg_quality' => 10,
81
                        'png_compression_level' => 9,
82
                        'filters' => [
83
                            'thumbnail' => [
84
                                'size' => [80, 80],
85
                                'mode' => 'outbound'
86
                            ]
87
                        ]
88
                    ],
89
                    'placeholder' => [
90
                        'jpeg_quality' => 10,
91
                        'png_compression_level' => 9,
92
                        'filters' => [
93
                            'thumbnail' => [
94
                                'size' => [100, 100],
95
                                'mode' => 'inset'
96
                            ]
97
                        ]
98
                    ],
99
                    'thumbnail' => [
100
                        'jpeg_quality' => 95,
101
                        'filters' => [
102
                            'upscale' => [
103
                                'min' => [636, 636]
104
                            ],
105
                            'thumbnail' => [
106
                                'size' => [636, 636],
107
                                'mode' => 'inset',
108
                                'allow_upscale' => true
109
                            ]
110
                        ]
111
                    ]
112
                ]
113
            ]);
114
        }
115
    }
116
}
117