Completed
Push — master ( 616fda...ede5da )
by Peter
06:14
created

ConfigManager::getDefault()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/manganel
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link http://maslosoft.com/manganel/
12
 */
13
14
namespace Maslosoft\Manganel;
15
16
use Maslosoft\Mangan\Signals\ConfigInit;
17
18
/**
19
 * Config Manager can be used to customize configuration of mangan without copying
20
 * whole configuration file. This allows to merge user defined parts with original
21
 * configuration. Proper configuration of sanitizers, decorators, filters is
22
 * crucial for proper mangan operation.
23
 * 
24
 * Example of recommended usage:
25
 * ```php
26
 * $config = array_replace_recursive(ConfigManager::getDefault(), [
27
 * 	'filters' => [
28
 * 		RawArray::class => [
29
 * 			MyCustomFilter::class,
30
 * 		],
31
 * 	],
32
 * 	'sanitizersMap' => [
33
 * 		RawArray::class => [
34
 * 			StringSanitizer::class => HtmlSanitizer::class
35
 * 		]
36
 * 	]
37
 * ]);
38
 * ```
39
 *
40
 * Above example snippet will add MyCustomFilter class to RawArray transformer
41
 * and remap one sanitizer also for RawArray, while keeping all other configuration
42
 * as it should be.
43
 *
44
 * See also `ConfigInit` signal.
45
 *
46
 * @see ConfigInit
47
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
48
 */
49
class ConfigManager
50
{
51
52
	private static $config = null;
53
54
	/**
55
	 * Get mangan built-in configuration as array.
56
	 * @return array Default mangan configuration
57
	 */
58
	public static function getDefault()
59
	{
60
		if (null === self::$config)
61
		{
62
			self::$config = require __DIR__ . '/config/mangan.cfg.php';
63
		}
64
		return self::$config;
65
	}
66
67
}
68