RepositoryPass.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\DependencyInjection\Compiler;
  12. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * Adds VCS repository providers to the main repository_provider service
  17. *
  18. * @author Jordi Boggiano <j.boggiano@seld.be>
  19. */
  20. class RepositoryPass implements CompilerPassInterface
  21. {
  22. public function process(ContainerBuilder $container)
  23. {
  24. if (!$container->hasDefinition('packagist.repository_provider')) {
  25. return;
  26. }
  27. $provider = $container->getDefinition('packagist.repository_provider');
  28. $providers = array();
  29. foreach ($container->findTaggedServiceIds('packagist.repository_provider') as $id => $tags) {
  30. $providers[$id] = isset($tags[0]['priority']) ? (int) $tags[0]['priority'] : 0;
  31. }
  32. arsort($providers);
  33. foreach ($providers as $id => $priority) {
  34. $provider->addMethodCall('addProvider', array(new Reference($id)));
  35. }
  36. }
  37. }