1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use ScayTrase\Api\Cruds\Adaptors\JmsSerializer\JmsValidatorSubscriber; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
11
|
|
|
|
12
|
|
|
final class JmsSerializerCompilerPass implements CompilerPassInterface |
13
|
|
|
{ |
14
|
|
|
/** {@inheritdoc} */ |
15
|
30 |
|
public function process(ContainerBuilder $container) |
16
|
|
|
{ |
17
|
30 |
|
if (!$container->has('jms_serializer')) { |
18
|
15 |
|
return; |
19
|
|
|
} |
20
|
|
|
|
21
|
15 |
|
if (!$container->has('debug.stopwatch')) { |
22
|
15 |
|
$container->removeDefinition('jms_serializer.stopwatch_subscriber'); |
23
|
|
|
} |
24
|
|
|
|
25
|
15 |
|
if (!$container->has('translator')) { |
26
|
|
|
$container->removeDefinition('jms_serializer.form_error_handler'); |
27
|
|
|
} |
28
|
|
|
|
29
|
15 |
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../../Resources/config')); |
30
|
15 |
|
$loader->load('jms_serializer.yml'); |
31
|
|
|
|
32
|
15 |
|
if ($container->has('validator')) { |
33
|
15 |
|
$definition = $container->register('cruds.api.jms_serializer.validator', JmsValidatorSubscriber::class); |
34
|
15 |
|
$definition->setArguments([new Reference('validator')]); |
35
|
15 |
|
$definition->addTag('jms_serializer.event_subscriber'); |
36
|
|
|
} |
37
|
|
|
|
38
|
15 |
|
$normalizer = $container->getDefinition('cruds.api.listener.response_normalizer'); |
39
|
15 |
|
$normalizer->replaceArgument(0, new Reference('cruds.jms_serializer')); |
40
|
|
|
|
41
|
15 |
|
$serializer = $container->getDefinition('cruds.api.listener.response_serializer'); |
42
|
15 |
|
$serializer->replaceArgument(0, new Reference('cruds.jms_serializer')); |
43
|
15 |
|
} |
44
|
|
|
} |
45
|
|
|
|