1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Silverback\ApiComponentBundle\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Silverback\ApiComponentBundle\DataModifier\DataModifierInterface; |
8
|
|
|
use Silverback\ApiComponentBundle\Filter\Doctrine\PublishableFilter; |
9
|
|
|
use Silverback\ApiComponentBundle\Form\FormTypeInterface; |
10
|
|
|
use Silverback\ApiComponentBundle\Form\Handler\FormHandlerInterface; |
11
|
|
|
use Symfony\Component\Config\FileLocator; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
13
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
14
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
15
|
|
|
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; |
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): void |
25
|
|
|
{ |
26
|
|
|
$this->loadServiceConfig($container); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param ContainerBuilder $container |
31
|
|
|
* @throws \Exception |
32
|
|
|
*/ |
33
|
|
|
private function loadServiceConfig(ContainerBuilder $container) |
34
|
|
|
{ |
35
|
|
|
$container->registerForAutoconfiguration(FormHandlerInterface::class) |
36
|
|
|
->addTag('silverback_api_component.form_handler') |
37
|
|
|
->setLazy(true); |
38
|
|
|
|
39
|
|
|
$container->registerForAutoconfiguration(DataModifierInterface::class) |
40
|
|
|
->addTag('silverback_api_component.serializer_middleware'); |
41
|
|
|
|
42
|
|
|
$container->registerForAutoconfiguration(FormTypeInterface::class) |
43
|
|
|
->addTag('silverback_api_component.form_type'); |
44
|
|
|
|
45
|
|
|
$loader = new PhpFileLoader( |
46
|
|
|
$container, |
47
|
|
|
new FileLocator(__DIR__ . '/../Resources/config') |
48
|
|
|
); |
49
|
|
|
$loader->load('services.php'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ContainerBuilder $container |
54
|
|
|
*/ |
55
|
|
|
public function prepend(ContainerBuilder $container): void |
56
|
|
|
{ |
57
|
|
|
$container->prependExtensionConfig( |
58
|
|
|
'api_platform', |
59
|
|
|
[ |
60
|
|
|
'eager_loading' => [ |
61
|
|
|
'force_eager' => false |
62
|
|
|
] |
63
|
|
|
] |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
67
|
|
|
if (isset($bundles['DoctrineBundle'])) { |
68
|
|
|
$container->prependExtensionConfig( |
69
|
|
|
'doctrine', |
70
|
|
|
[ |
71
|
|
|
'orm' => [ |
72
|
|
|
'filters' => [ |
73
|
|
|
'publishable_filter' => [ |
74
|
|
|
'class' => PublishableFilter::class, |
75
|
|
|
'enabled' => false |
76
|
|
|
] |
77
|
|
|
] |
78
|
|
|
] |
79
|
|
|
] |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (isset($bundles['LiipImagineBundle'])) { |
84
|
|
|
$uploadsDir = $container->getParameter('kernel.project_dir') . '/var/uploads'; |
85
|
|
|
if (!@mkdir($uploadsDir) && !is_dir($uploadsDir)) { |
86
|
|
|
throw new \RuntimeException(sprintf('Directory "%s" was not created', $uploadsDir)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$container->prependExtensionConfig( |
90
|
|
|
'liip_imagine', |
91
|
|
|
[ |
92
|
|
|
'loaders' => [ |
93
|
|
|
'default' => [ |
94
|
|
|
'filesystem' => [ |
95
|
|
|
'data_root' => [ |
96
|
|
|
'uploads' => $uploadsDir, |
97
|
|
|
'default' => $container->getParameter('kernel.project_dir') . '/public' |
98
|
|
|
] |
99
|
|
|
] |
100
|
|
|
] |
101
|
|
|
], |
102
|
|
|
'filter_sets' => [ |
103
|
|
|
'placeholder_square' => [ |
104
|
|
|
'jpeg_quality' => 10, |
105
|
|
|
'png_compression_level' => 9, |
106
|
|
|
'filters' => [ |
107
|
|
|
'thumbnail' => [ |
108
|
|
|
'size' => [80, 80], |
109
|
|
|
'mode' => 'outbound' |
110
|
|
|
] |
111
|
|
|
] |
112
|
|
|
], |
113
|
|
|
'placeholder' => [ |
114
|
|
|
'jpeg_quality' => 10, |
115
|
|
|
'png_compression_level' => 9, |
116
|
|
|
'filters' => [ |
117
|
|
|
'thumbnail' => [ |
118
|
|
|
'size' => [100, 100], |
119
|
|
|
'mode' => 'inset' |
120
|
|
|
] |
121
|
|
|
] |
122
|
|
|
], |
123
|
|
|
'thumbnail' => [ |
124
|
|
|
'jpeg_quality' => 95, |
125
|
|
|
'filters' => [ |
126
|
|
|
'upscale' => [ |
127
|
|
|
'min' => [636, 636] |
128
|
|
|
], |
129
|
|
|
'thumbnail' => [ |
130
|
|
|
'size' => [636, 636], |
131
|
|
|
'mode' => 'inset', |
132
|
|
|
'allow_upscale' => true |
133
|
|
|
] |
134
|
|
|
] |
135
|
|
|
] |
136
|
|
|
] |
137
|
|
|
] |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|