Skip to content

Instantly share code, notes, and snippets.

@merk
Created June 1, 2012 03:45
Show Gist options
  • Save merk/2848557 to your computer and use it in GitHub Desktop.
Save merk/2848557 to your computer and use it in GitHub Desktop.
<?php
namespace Ibms\SearchBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use InvalidArgumentException;
/**
* Registers the transformers into our Modal class.
*
* @author Tim Nagel <[email protected]>
*/
class ModalFinderPass implements CompilerPassInterface
{
/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
$transformers = array();
foreach ($container->findTaggedServiceIds('foq_elastica.elastica_to_model_transformer') as $id => $tags) {
foreach ($tags as $tag) {
$transformers[$tag['type']] = $container->getDefinition($id)->getArgument(1);
}
}
$loaders = array();
foreach ($container->findTaggedServiceIds('ibms_search.modal_finder') as $id => $tags) {
foreach ($tags as $tag) {
if (empty($tag['class']) || empty($tag['method'])) {
throw new InvalidArgumentException('The Loader must have both a class and a method defined.');
}
$loaders[$tag['class']] = array($id, $tag['method']);
}
}
$finder = $container->getDefinition('ibms_search.modal_finder');
$finder->replaceArgument(1, $transformers);
$finder->replaceArgument(2, $loaders);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment