1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Norsys\LogsBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
6
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the class that validates and merges configuration from your app/config files |
10
|
|
|
*/ |
11
|
|
|
class Configuration implements ConfigurationInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return TreeBuilder |
15
|
|
|
*/ |
16
|
|
|
public function getConfigTreeBuilder() |
17
|
|
|
{ |
18
|
|
|
$treeBuilder = new TreeBuilder(); |
19
|
|
|
$rootNode = $treeBuilder->root('norsys_logs'); |
20
|
|
|
|
21
|
|
|
$rootNode |
22
|
|
|
->children() |
23
|
|
|
->arrayNode('security') |
24
|
|
|
->info('Optional security configuration') |
25
|
|
|
->addDefaultsIfNotSet() |
26
|
|
|
->children() |
27
|
|
|
->booleanNode('enabled') |
28
|
|
|
->info('Enable security to access logs') |
29
|
|
|
->defaultValue(true) |
30
|
|
|
->end() |
31
|
|
|
->arrayNode('allowed_ips') |
32
|
|
|
->prototype('scalar') |
33
|
|
|
->end() |
34
|
|
|
->defaultValue([]) |
35
|
|
|
->end() |
36
|
|
|
->end() |
37
|
|
|
->end() |
38
|
|
|
->scalarNode('base_layout') |
39
|
|
|
->cannotBeEmpty() |
40
|
|
|
->defaultValue('NorsysLogsBundle::layout.html.twig') |
41
|
|
|
->end() |
42
|
|
|
->scalarNode('logs_per_page') |
43
|
|
|
->cannotBeEmpty() |
44
|
|
|
->defaultValue(25) |
45
|
|
|
->beforeNormalization() |
46
|
|
|
->ifString() |
47
|
|
|
->then(function ($v) { |
48
|
|
|
return (int) $v; |
49
|
|
|
}) |
50
|
|
|
->end() |
51
|
|
|
->end() |
52
|
|
|
->arrayNode('doctrine') |
53
|
|
|
->children() |
54
|
|
|
->scalarNode('table_name')->defaultValue('monolog_entries')->end() |
55
|
|
|
->scalarNode('connection_name')->end() |
56
|
|
|
->arrayNode('connection') |
57
|
|
|
->cannotBeEmpty() |
58
|
|
|
->children() |
59
|
|
|
->scalarNode('driver')->end() |
60
|
|
|
->scalarNode('driverClass')->end() |
61
|
|
|
->scalarNode('pdo')->end() |
62
|
|
|
->scalarNode('dbname')->end() |
63
|
|
|
->scalarNode('host')->defaultValue('localhost')->end() |
64
|
|
|
->scalarNode('port')->defaultNull()->end() |
65
|
|
|
->scalarNode('user')->defaultValue('root')->end() |
66
|
|
|
->scalarNode('password')->defaultNull()->end() |
67
|
|
|
->scalarNode('charset')->defaultValue('UTF8')->end() |
68
|
|
|
->scalarNode('path') |
69
|
|
|
->info(' The filesystem path to the database file for SQLite') |
70
|
|
|
->end() |
71
|
|
|
->booleanNode('memory') |
72
|
|
|
->info('True if the SQLite database should be in-memory (non-persistent)') |
73
|
|
|
->end() |
74
|
|
|
->scalarNode('unix_socket') |
75
|
|
|
->info('The unix socket to use for MySQL') |
76
|
|
|
->end() |
77
|
|
|
->end() |
78
|
|
|
->end() |
79
|
|
|
->end() |
80
|
|
|
->end() |
81
|
|
|
->end() |
82
|
|
|
->validate() |
83
|
|
|
->ifTrue(function ($v) { |
84
|
|
|
if (isset($v['doctrine']) === false) { |
85
|
|
|
return true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (isset($v['doctrine']['connection_name']) === false |
89
|
|
|
&& isset($v['doctrine']['connection']) === false |
90
|
|
|
) { |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return false; |
95
|
|
|
}) |
96
|
|
|
->thenInvalid('You must provide a valid "connection_name" or "connection" definition.') |
97
|
|
|
->end() |
98
|
|
|
->validate() |
99
|
|
|
->ifTrue(function ($v) { |
100
|
|
|
if (isset($v['doctrine']) === false) { |
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if (isset($v['doctrine']['connection_name']) === true |
105
|
|
|
&& isset($v['doctrine']['connection']) === true |
106
|
|
|
) { |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return false; |
111
|
|
|
}) |
112
|
|
|
->thenInvalid('You cannot specify both options "connection_name" and "connection".') |
113
|
|
|
->end(); |
114
|
|
|
|
115
|
|
|
return $treeBuilder; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|