| @@ 21-57 (lines=37) @@ | ||
| 18 | * Pass to add tagged tasks to the TaskFactory |
|
| 19 | * |
|
| 20 | */ |
|
| 21 | class TaskCompilerPass implements CompilerPassInterface |
|
| 22 | { |
|
| 23 | public function process(ContainerBuilder $container) |
|
| 24 | { |
|
| 25 | if (!$container->hasDefinition('task.factory')) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $definition = $container->getDefinition('task.factory'); |
|
| 30 | $taggedServices = $container->findTaggedServiceIds('task'); |
|
| 31 | ||
| 32 | foreach ($taggedServices as $id => $tagsAttributes) { |
|
| 33 | foreach ($tagsAttributes as $attributes) { |
|
| 34 | $taskDefinition = $container->getDefinition($id); |
|
| 35 | $taskDefinition->setScope('prototype'); |
|
| 36 | ||
| 37 | $attributes += array( |
|
| 38 | 'alias' => $id, |
|
| 39 | 'configuration' => false, |
|
| 40 | ); |
|
| 41 | ||
| 42 | // validate configuration attribute |
|
| 43 | if (false !== $attributes['configuration']) { |
|
| 44 | $ref = new \ReflectionClass($attributes['configuration']); |
|
| 45 | if (!$ref->implementsInterface('Symfony\Component\Config\Definition\ConfigurationInterface')) { |
|
| 46 | throw new \Exception(sprintf('The tag attribute "configuration" for service "%s" must implement "Symfony\Component\Config\Definition\ConfigurationInterface"', $id)); |
|
| 47 | } |
|
| 48 | } |
|
| 49 | ||
| 50 | $definition->addMethodCall( |
|
| 51 | 'addTask', |
|
| 52 | array($id, $attributes['alias'], $attributes['configuration']) |
|
| 53 | ); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | } |
|
| 57 | } |
|
| 58 | ||
| @@ 21-58 (lines=38) @@ | ||
| 18 | * Pass to add tagged transporters to the TransporterFactory |
|
| 19 | * |
|
| 20 | */ |
|
| 21 | class TransporterCompilerPass implements CompilerPassInterface |
|
| 22 | { |
|
| 23 | public function process(ContainerBuilder $container) |
|
| 24 | { |
|
| 25 | if (!$container->hasDefinition('transporter.factory')) { |
|
| 26 | return; |
|
| 27 | } |
|
| 28 | ||
| 29 | $definition = $container->getDefinition('transporter.factory'); |
|
| 30 | $taggedServices = $container->findTaggedServiceIds('transporter'); |
|
| 31 | ||
| 32 | foreach ($taggedServices as $id => $tagsAttributes) { |
|
| 33 | foreach ($tagsAttributes as $attributes) { |
|
| 34 | $taskDefinition = $container->getDefinition($id); |
|
| 35 | ||
| 36 | $attributes += array( |
|
| 37 | 'alias' => $id, |
|
| 38 | 'configuration' => false, |
|
| 39 | ); |
|
| 40 | ||
| 41 | // validate configuration attribute |
|
| 42 | if (false === $attributes['configuration']) { |
|
| 43 | $attributes['configuration'] = 'Webcreate\Conveyor\Transporter\Configuration\DefaultTransporterConfiguration'; |
|
| 44 | } |
|
| 45 | ||
| 46 | $ref = new \ReflectionClass($attributes['configuration']); |
|
| 47 | if (!$ref->implementsInterface('Symfony\Component\Config\Definition\ConfigurationInterface')) { |
|
| 48 | throw new \Exception(sprintf('The tag attribute "configuration" for service "%s" must implement "Symfony\Component\Config\Definition\ConfigurationInterface"', $id)); |
|
| 49 | } |
|
| 50 | ||
| 51 | $definition->addMethodCall( |
|
| 52 | 'addTransporter', |
|
| 53 | array($id, $attributes['alias'], $attributes['configuration']) |
|
| 54 | ); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||