|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony framework. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* This source file is subject to the MIT license that is bundled |
|
|
9 |
* with this source code in the file LICENSE. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Bundle\AsseticBundle\DependencyInjection\Compiler; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\Reference; |
|
|
15 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
16 |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
|
17 |
|
|
|
18 |
/** |
|
|
19 |
* Adds services tagged as assets to the asset manager. |
|
|
20 |
* |
|
|
21 |
* @author Kris Wallsmith <kris@symfony.com> |
|
|
22 |
*/ |
|
|
23 |
class AssetManagerPass implements CompilerPassInterface |
|
|
24 |
{ |
|
|
25 |
public function process(ContainerBuilder $container) |
|
|
26 |
{ |
|
|
27 |
if (!$container->hasDefinition('assetic.asset_manager')) { |
|
|
28 |
return; |
|
|
29 |
} |
|
|
30 |
|
|
|
31 |
$am = $container->getDefinition('assetic.asset_manager'); |
|
|
32 |
|
|
|
33 |
// add assets |
|
|
34 |
foreach ($container->findTaggedServiceIds('assetic.asset') as $id => $attributes) { |
|
|
35 |
foreach ($attributes as $attr) { |
|
|
36 |
if (isset($attr['alias'])) { |
|
|
37 |
$am->addMethodCall('set', array($attr['alias'], new Reference($id))); |
|
|
38 |
} |
|
|
39 |
} |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
// add loaders |
|
|
43 |
$loaders = array(); |
|
|
44 |
foreach ($container->findTaggedServiceIds('assetic.formula_loader') as $id => $attributes) { |
|
|
45 |
foreach ($attributes as $attr) { |
|
|
46 |
if (isset($attr['alias'])) { |
|
|
47 |
$loaders[$attr['alias']] = new Reference($id); |
|
|
48 |
} |
|
|
49 |
} |
|
|
50 |
} |
|
|
51 |
$am->replaceArgument(1, $loaders); |
|
|
52 |
|
|
|
53 |
// add resources |
|
|
54 |
foreach ($container->findTaggedServiceIds('assetic.formula_resource') as $id => $attributes) { |
|
|
55 |
foreach ($attributes as $attr) { |
|
|
56 |
if (isset($attr['loader'])) { |
|
|
57 |
$am->addMethodCall('addResource', array(new Reference($id), $attr['loader'])); |
|
|
58 |
} |
|
|
59 |
} |
|
|
60 |
} |
|
|
61 |
} |
|
|
62 |
} |