ExtensionCompilerPass.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\DependencyInjection\Compiler;
  11. use Symfony\Component\DependencyInjection\Definition;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  17. */
  18. class ExtensionCompilerPass implements CompilerPassInterface
  19. {
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function process(ContainerBuilder $container)
  24. {
  25. foreach ($container->findTaggedServiceIds('sonata.admin.extension') as $id => $attributes) {
  26. $target = false;
  27. if (isset($attributes[0]['target'])) {
  28. $target = $attributes[0]['target'];
  29. }
  30. if (!$target || !$container->hasDefinition($target)) {
  31. continue;
  32. }
  33. $container->getDefinition($target)
  34. ->addMethodCall('addExtension', array(new Reference($id)));
  35. }
  36. }
  37. }