src/DependencyInjection/Compiler/RegisterPersistersPass.php
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('fos_elastica.persister_registry')) {
            return;
        }

        $defaultIndex = $container->getParameter('fos_elastica.default_index');
        $registry = $container->getDefinition('fos_elastica.persister_registry');

        $registeredPersisters = [];
        foreach ($container->findTaggedServiceIds('fos_elastica.persister', true) as $id => $attributes) {
            foreach ($attributes as $attribute) {
                if (!isset($attribute['type'])) {
                    throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must specify the "type" attribute.', $id));
                }

                $index = isset($attribute['index']) ? $attribute['index'] : $defaultIndex;
                $type = $attribute['type'];

                if (isset($registeredPersisters[$index][$type])) {
                    throw new \InvalidArgumentException(sprintf(
                        'Cannot register persister "%s". The persister "%s" has been registered for same index "%s" and type "%s"',
                        $id,
                        $registeredPersisters[$index][$type],
                        $index,
                        $type
                    ));
                }

                $persisterDef = $container->getDefinition($id);
                if (!$persisterDef->getFactory() && $persisterDef->getClass()) {
                    // You are on your own if you use a factory to create a persister.
                    // It would fail in runtime if the factory does not return a proper persister.
                    $this->assertClassImplementsPersisterInterface($id, $container->getParameterBag()->resolveValue($persisterDef->getClass()));
                }

                if (!$persisterDef->isPublic()) {
                    throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must be a public service', $id));
                }

                $registeredPersisters[$index][$type] = $id;
            }
        }

        $registry->replaceArgument(0, $registeredPersisters);
    }
public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('fos_elastica.persister_registry')) {
            return;
        }

        $defaultIndex = $container->getParameter('fos_elastica.default_index');
        $registry = $container->getDefinition('fos_elastica.persister_registry');

        $registeredPersisters = [];
        foreach ($container->findTaggedServiceIds('fos_elastica.persister', true) as $id => $attributes) {
            foreach ($attributes as $attribute) {
                if (!isset($attribute['type'])) {
                    throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must specify the "type" attribute.', $id));
                }

                $index = isset($attribute['index']) ? $attribute['index'] : $defaultIndex;
                $type = $attribute['type'];

                if (isset($registeredPersisters[$index][$type])) {
                    throw new \InvalidArgumentException(sprintf(
                        'Cannot register persister "%s". The persister "%s" has been registered for same index "%s" and type "%s"',
                        $id,
                        $registeredPersisters[$index][$type],
                        $index,
                        $type
                    ));
                }

                $persisterDef = $container->getDefinition($id);
                if (!$persisterDef->getFactory() && $persisterDef->getClass()) {
                    // You are on your own if you use a factory to create a persister.
                    // It would fail in runtime if the factory does not return a proper persister.
                    $this->assertClassImplementsPersisterInterface($id, $container->getParameterBag()->resolveValue($persisterDef->getClass()));
                }

                if (!$persisterDef->isPublic()) {
                    throw new \InvalidArgumentException(sprintf('Elastica persister "%s" must be a public service', $id));
                }

                $registeredPersisters[$index][$type] = $id;
            }
        }

        $registry->replaceArgument(0, $registeredPersisters);
    }
{@inheritdoc}