hasDefinition('fos_elastica.provider_registry')) { return; } // Infer the default index name from the service alias $defaultIndex = substr($container->getAlias('fos_elastica.index'), 19); $registry = $container->getDefinition('fos_elastica.provider_registry'); $providers = $container->findTaggedServiceIds('fos_elastica.provider'); foreach ($providers as $providerId => $tags) { $index = $type = null; $class = $container->getDefinition($providerId)->getClass(); if (!$class || !$this->isProviderImplementation($class)) { throw new \InvalidArgumentException(sprintf('Elastica provider "%s" with class "%s" must implement ProviderInterface.', $providerId, $class)); } foreach ($tags as $tag) { if (!isset($tag['type'])) { throw new \InvalidArgumentException(sprintf('Elastica provider "%s" must specify the "type" attribute.', $providerId)); } $index = isset($tag['index']) ? $tag['index'] : $defaultIndex; $type = $tag['type']; } $registry->addMethodCall('addProvider', array($index, $type, $providerId)); } } /** * Returns whether the class implements ProviderInterface. * * @param string $class * * @return boolean */ private function isProviderImplementation($class) { if (!isset($this->implementations[$class])) { $refl = new \ReflectionClass($class); $this->implementations[$class] = $refl->implementsInterface('FOS\ElasticaBundle\Provider\ProviderInterface'); } return $this->implementations[$class]; } }