Completed
Push — master ( c8f19a...ddbfd2 )
by Peter
72:09 queued 69:12
created

ConfigManager::getDefault()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 6
cp 0.6667
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.1481
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
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 https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan;
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 4
	public static function getDefault()
59
	{
60 4
		if (null === self::$config)
61 4
		{
62
			self::$config = require __DIR__ . '/config/mangan.cfg.php';
63
		}
64 4
		return self::$config;
65
	}
66
67
}
68