Completed
Push — master ( 8a2270...44f7c9 )
by Peter
24:53
created

ConfigManager::getDefault()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan;
10
11
/**
12
 * Config Manager can be used to customize configuration of mangan without copying
13
 * whole configuration file. This allows to merge user defined parts with original
14
 * configuration. Proper configuration of sanitizers, decorators, filters is
15
 * crucial for proper mangan operation.
16
 * 
17
 * Example of recommended usage:
18
 * ```php
19
 * $config = array_replace_recursive(ConfigManager::getDefault(), [
20
 * 	'filters' => [
21
 * 		RawArray::class => [
22
 * 			MyCustomFilter::class,
23
 * 		],
24
 * 	],
25
 * 	'sanitizersMap' => [
26
 * 		RawArray::class => [
27
 * 			StringSanitizer::class => HtmlSanitizer::class
28
 * 		]
29
 * 	]
30
 * ]);
31
 * ```
32
 *
33
 * Above example snippet will add MyCustomFilter class to RawArray transformer
34
 * and remap one sanitizer also for RawArray, while keeping all other configuration
35
 * as it should be.
36
 *
37
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
38
 */
39
class ConfigManager
40
{
41
42
	private static $config = null;
43
44
	/**
45
	 * Get mangan built-in configuration as array.
46
	 * @return array Default mangan configuration
47
	 */
48
	public static function getDefault()
49
	{
50
		if (null === self::$config)
51
		{
52
			self::$config = require __DIR__ . '/config/mangan.cfg.php';
53
		}
54
		return self::$config;
55
	}
56
57
}
58