Completed
Push — master ( aaeda7...30c0e6 )
by Olivier
02:00
created

ContainerConfig::normalize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\Binding\SymfonyDependencyInjection;
13
14
class ContainerConfig
15
{
16
	/**
17
	 * Fragment name for the container configuration.
18
	 */
19
	const FRAGMENT_FOR_CONTAINER = 'container';
20
21
	/**
22
	 * Whether the compiled container should be cached.
23
	 *
24
	 * **Note:** Changes to services won't apply until the compiled container is re-created.
25
	 * You can use `icanboogie clear cache` or delete the file for the compiled container to
26
	 * be updated.
27
	 */
28
	const USE_CACHING = 'use_caching';
29
30
	/**
31
	 * Define container extensions using an array of key/value pairs, where _key_ is an identifier
32
	 * and _value_ a callable with the following signature:
33
	 *
34
	 *     \Symfony\Component\DependencyInjection\Extension\ExtensionInterface (\ICanBoogie\Application $app)
35
	 */
36
	const EXTENSIONS = 'extensions';
37
38
	/**
39
	 * @param array $fragments
40
	 *
41
	 * @return array
42
	 */
43
	static public function synthesize(array $fragments)
44
	{
45
		$use_caching = false;
46
		$extensions = [];
47
48
		foreach ($fragments as $fragment)
49
		{
50
			if (isset($fragment[self::USE_CACHING]))
51
			{
52
				$use_caching = $fragment[self::USE_CACHING];
53
			}
54
55
			if (isset($fragment[self::EXTENSIONS]))
56
			{
57
				$extensions[] = $fragment[self::EXTENSIONS];
58
			}
59
		}
60
61
		if ($extensions)
62
		{
63
			$extensions = array_merge(...$extensions);
64
		}
65
66
		return [
67
68
			self::USE_CACHING => $use_caching,
69
			self::EXTENSIONS => $extensions
70
71
		];
72
	}
73
74
	/**
75
	 * @param array $config
76
	 *
77
	 * @return array
78
	 */
79
	static public function normalize(array $config)
80
	{
81
		return $config + [
82
83
			self::USE_CACHING => false,
84
			self::EXTENSIONS => [],
85
86
		];
87
	}
88
}
89