eZ\Bundle\EzPublishRestBundle\DependencyInjection\Compiler\FieldTypeProcessorPass::process PHP Method

process() public method

public process ( ContainerBuilder $container )
$container Symfony\Component\DependencyInjection\ContainerBuilder
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('ezpublish_rest.field_type_processor_registry')) {
            return;
        }
        $definition = $container->getDefinition('ezpublish_rest.field_type_processor_registry');
        foreach ($container->findTaggedServiceIds('ezpublish_rest.field_type_processor') as $id => $attributes) {
            foreach ($attributes as $attribute) {
                if (!isset($attribute['alias'])) {
                    throw new \LogicException('ezpublish_rest.field_type_processor service tag needs an "alias" attribute to identify the field type. None given.');
                }
                $definition->addMethodCall('registerProcessor', array($attribute['alias'], new Reference($id)));
            }
        }
    }

Usage Example

 public function testProcess()
 {
     $processorDefinition = new Definition();
     $processorDefinition->addTag('ezpublish_rest.field_type_processor', array('alias' => 'test'));
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions(array('ezpublish_rest.field_type_processor_registry' => new Definition(), 'ezpublish_rest.field_type_processor.test' => $processorDefinition));
     $compilerPass = new FieldTypeProcessorPass();
     $compilerPass->process($containerBuilder);
     $dispatcherMethodCalls = $containerBuilder->getDefinition('ezpublish_rest.field_type_processor_registry')->getMethodCalls();
     self::assertTrue(isset($dispatcherMethodCalls[0][0]), 'Failed asserting that dispatcher has a method call');
     self::assertEquals('registerProcessor', $dispatcherMethodCalls[0][0], "Failed asserting that called method is 'addVisitor'");
     self::assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $dispatcherMethodCalls[0][1][1], 'Failed asserting that method call is to a Reference object');
     self::assertEquals('ezpublish_rest.field_type_processor.test', $dispatcherMethodCalls[0][1][1]->__toString(), "Failed asserting that Referenced service is 'ezpublish_rest.output.value_object_visitor.test'");
 }
FieldTypeProcessorPass