|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
6
|
|
|
use Silverback\ApiComponentBundle\Factory\Fixtures\Component\AbstractComponentFactory; |
|
7
|
|
|
use Silverback\ApiComponentBundle\Factory\Fixtures\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
|
|
|
if (isset($bundles['LiipImagineBundle'])) { |
|
65
|
|
|
$container->prependExtensionConfig('liip_imagine', [ |
|
66
|
|
|
'loaders' => [ |
|
67
|
|
|
'default' => [ |
|
68
|
|
|
'filesystem' => [ |
|
69
|
|
|
'data_root' => '%kernel.project_dir%/public' |
|
70
|
|
|
] |
|
71
|
|
|
] |
|
72
|
|
|
], |
|
73
|
|
|
'filter_sets' => [ |
|
74
|
|
|
'placeholder_square' => [ |
|
75
|
|
|
'jpeg_quality' => 10, |
|
76
|
|
|
'png_compression_level' => 9, |
|
77
|
|
|
'filters' => [ |
|
78
|
|
|
'thumbnail' => [ |
|
79
|
|
|
'size' => [80, 80], |
|
80
|
|
|
'mode' => 'outbound' |
|
81
|
|
|
] |
|
82
|
|
|
] |
|
83
|
|
|
], |
|
84
|
|
|
'placeholder' => [ |
|
85
|
|
|
'jpeg_quality' => 10, |
|
86
|
|
|
'png_compression_level' => 9, |
|
87
|
|
|
'filters' => [ |
|
88
|
|
|
'thumbnail' => [ |
|
89
|
|
|
'size' => [100, 100], |
|
90
|
|
|
'mode' => 'inset' |
|
91
|
|
|
] |
|
92
|
|
|
] |
|
93
|
|
|
], |
|
94
|
|
|
'thumbnail' => [ |
|
95
|
|
|
'jpeg_quality' => 95, |
|
96
|
|
|
'filters' => [ |
|
97
|
|
|
'upscale' => [ |
|
98
|
|
|
'min' => [636, 636] |
|
99
|
|
|
], |
|
100
|
|
|
'thumbnail' => [ |
|
101
|
|
|
'size' => [636, 636], |
|
102
|
|
|
'mode' => 'inset', |
|
103
|
|
|
'allow_upscale' => true |
|
104
|
|
|
] |
|
105
|
|
|
] |
|
106
|
|
|
] |
|
107
|
|
|
] |
|
108
|
|
|
]); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|