TaggedServicesPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveTaggedServices() 0 9 2
A process() 0 6 1
1
<?php
2
namespace kujaff\VersionsBundle\DependencyInjection\Compiler;
3
4
use Symfony\Component\DependencyInjection\ContainerBuilder;
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
7
/**
8
 * Save service tagged "bundle.install" and "bundle.update"
9
 */
10
class TaggedServicesPass implements CompilerPassInterface
11
{
12
13
	/**
14
	 * Save tagged service into a cache file
15
	 *
16
	 * @param ContainerBuilder $container
17
	 * @param string $tag
18
	 * @param string $fileName
19
	 */
20
	private function saveTaggedServices(ContainerBuilder $container, $tag, $fileName)
21
	{
22
		$services = array();
23
		foreach ($container->findTaggedServiceIds($tag) as $id => $attributes) {
24
			$services[] = $id;
25
		}
26
		$php = '<?php return ' . var_export($services, true) . ';';
27
		file_put_contents($container->getParameter('kernel.cache_dir') . DIRECTORY_SEPARATOR . $fileName, $php);
28
	}
29
30
	/**
31
	 * Process the build
32
	 *
33
	 * @param ContainerBuilder $container
34
	 */
35
	public function process(ContainerBuilder $container)
36
	{
37
		$this->saveTaggedServices($container, 'bundle.install', 'services.bundle.install.php');
38
		$this->saveTaggedServices($container, 'bundle.update', 'services.bundle.update.php');
39
		$this->saveTaggedServices($container, 'bundle.uninstall', 'services.bundle.uninstall.php');
40
	}
41
42
}
43