ExtensionCompilerPass.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
  17. /**
  18. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  19. */
  20. class ExtensionCompilerPass implements CompilerPassInterface
  21. {
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function process(ContainerBuilder $container)
  26. {
  27. foreach ($container->findTaggedServiceIds('sonata.admin.extension') as $id => $attributes) {
  28. $target = false;
  29. if (isset($attributes[0]['target'])) {
  30. $target = $attributes[0]['target'];
  31. }
  32. if (!$target || !$container->hasDefinition($target)) {
  33. continue;
  34. }
  35. $container->getDefinition($target)
  36. ->addMethodCall('addExtension', array(new Reference($id)));
  37. }
  38. }
  39. }