Skip to content

Commit eaa3684

Browse files
committed
Adding autowiring for providers
1 parent 8be6400 commit eaa3684

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/CacheAdapterBundle.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,22 @@
1111

1212
namespace Cache\AdapterBundle;
1313

14+
use Cache\AdapterBundle\DependencyInjection\CompilerPass\ServiceAliasCompilerPass;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1416
use Symfony\Component\HttpKernel\Bundle\Bundle;
1517

1618
/**
1719
* @author Tobias Nyholm <[email protected]>
1820
*/
1921
class CacheAdapterBundle extends Bundle
2022
{
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
public function build(ContainerBuilder $container)
27+
{
28+
parent::build($container);
29+
30+
$container->addCompilerPass(new ServiceAliasCompilerPass());
31+
}
2132
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of cache-bundle.
5+
*
6+
* (c) Aaron Scherer <[email protected]>
7+
*
8+
* This source file is subject to the license that is bundled
9+
* with this source code in the file LICENSE
10+
*/
11+
12+
namespace Cache\AdapterBundle\DependencyInjection\CompilerPass;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
17+
/**
18+
* @author Aaron Scherer <[email protected]>
19+
*
20+
* ServiceAliasCompilerPass Class
21+
*/
22+
class ServiceAliasCompilerPass implements CompilerPassInterface
23+
{
24+
25+
/**
26+
* You can modify the container here before it is dumped to PHP code.
27+
*
28+
* @param ContainerBuilder $container
29+
*/
30+
public function process(ContainerBuilder $container)
31+
{
32+
$serviceIds = array_keys($container->findTaggedServiceIds('cache.provider'));
33+
foreach ($serviceIds as $serviceId) {
34+
$cleanName = str_replace('.inner', '', $serviceId);
35+
$instance = $container->get($serviceId);
36+
$class = get_class($instance);
37+
38+
$container->setAlias($cleanName, $serviceId);
39+
$container->setAlias($class, $cleanName);
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)