ConfigManager::getDefault()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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