1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaliop\eZMigrationBundle\DependencyInjection\CompilerPass; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
8
|
|
|
|
9
|
|
|
class TaggedServicesCompilerPass implements CompilerPassInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param ContainerBuilder $container |
13
|
|
|
*/ |
14
|
|
|
public function process(ContainerBuilder $container) |
15
|
|
|
{ |
16
|
|
|
if ($container->has('ez_migration_bundle.migration_service')) { |
17
|
|
|
$migrationService = $container->findDefinition('ez_migration_bundle.migration_service'); |
18
|
|
|
|
19
|
|
|
$DefinitionParsers = $container->findTaggedServiceIds('ez_migration_bundle.definition_parser'); |
20
|
|
|
foreach ($DefinitionParsers as $id => $tags) { |
21
|
|
|
$migrationService->addMethodCall('addDefinitionParser', array( |
22
|
|
|
new Reference($id) |
23
|
|
|
)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$executors = $container->findTaggedServiceIds('ez_migration_bundle.executor'); |
27
|
|
|
foreach ($executors as $id => $tags) { |
28
|
|
|
$migrationService->addMethodCall('addExecutor', array( |
29
|
|
|
new Reference($id) |
30
|
|
|
)); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if ($container->has('ez_migration_bundle.complex_field_manager')) { |
35
|
|
|
$migrationService = $container->findDefinition('ez_migration_bundle.complex_field_manager'); |
36
|
|
|
|
37
|
|
|
$DefinitionParsers = $container->findTaggedServiceIds('ez_migration_bundle.complex_field'); |
38
|
|
|
|
39
|
|
|
// allow for prioritization of tagged services |
40
|
|
|
$handlers = array(); |
41
|
|
|
$priorities = array(); |
42
|
|
|
|
43
|
|
|
foreach ($DefinitionParsers as $id => $tags) { |
44
|
|
|
foreach ($tags as $attributes) { |
45
|
|
|
$priorities[] = isset($attributes['priority']) ? $attributes['priority'] : 0; |
46
|
|
|
$handlers[] = array( |
47
|
|
|
new Reference($id), |
48
|
|
|
$attributes['fieldtype'], |
49
|
|
|
isset($attributes['contenttype']) ? $attributes['contenttype'] : null |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
asort($priorities); |
55
|
|
|
|
56
|
|
|
foreach ($priorities as $id => $priority) { |
57
|
|
|
$migrationService->addMethodCall('addFieldHandler', $handlers[$id]); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($container->has('ez_migration_bundle.reference_resolver.customreference.flexible')) { |
62
|
|
|
$customReferenceResolver = $container->findDefinition('ez_migration_bundle.reference_resolver.customreference.flexible'); |
63
|
|
|
$extraResolvers = $container->findTaggedServiceIds('ez_migration_bundle.reference_resolver.customreference'); |
64
|
|
|
|
65
|
|
|
foreach ($extraResolvers as $id => $tags) { |
66
|
|
|
$customReferenceResolver->addMethodCall('addResolver', array( |
67
|
|
|
new Reference($id) |
68
|
|
|
)); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if ($container->has('ez_migration_bundle.context_handler')) { |
73
|
|
|
$contextHandlerService = $container->findDefinition('ez_migration_bundle.context_handler'); |
74
|
|
|
$ContextProviders = $container->findTaggedServiceIds('ez_migration_bundle.context_provider'); |
75
|
|
|
|
76
|
|
|
foreach ($ContextProviders as $id => $tags) { |
77
|
|
|
foreach ($tags as $attributes) { |
78
|
|
|
$contextHandlerService->addMethodCall('addProvider', array(new Reference($id), $attributes['label'])); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|