~tsep-dev/tsep/tsep2

« back to all changes in this revision

Viewing changes to src/TSEP/Packagist/WebBundle/DependencyInjection/Compiler/RepositoryPass.php

  • Committer: xaav
  • Date: 2011-09-27 01:31:36 UTC
  • Revision ID: git-v1:3c3f2e8d21ccd506f3cd12b2650591f6532368fb
First commit'

Show diffs side-by-side

added added

removed removed

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