1 | <?php |
||
2 | |||
3 | namespace Locastic\Loggastic\DependencyInjection; |
||
4 | |||
5 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
||
6 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
7 | |||
8 | final class Configuration implements ConfigurationInterface |
||
9 | { |
||
10 | public function getConfigTreeBuilder(): TreeBuilder |
||
11 | { |
||
12 | $treeBuilder = new TreeBuilder('locastic_activity_log'); |
||
13 | |||
14 | $rootNode = $treeBuilder->getRootNode(); |
||
15 | |||
16 | $rootNode |
||
17 | ->children() |
||
18 | ->booleanNode('default_doctrine_subscriber') |
||
19 | ->defaultTrue() |
||
20 | ->end() |
||
21 | ->booleanNode('identifier_extractor') |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
22 | ->defaultTrue() |
||
23 | ->end() |
||
24 | ->arrayNode('loggable_classes') |
||
25 | ->arrayPrototype() |
||
26 | ->children() |
||
27 | ->scalarNode('class')->end() |
||
28 | ->arrayNode('groups') |
||
29 | ->prototype('scalar')->end() |
||
30 | ->end() |
||
31 | ->end() |
||
32 | ->end() |
||
33 | ->end() |
||
34 | ->scalarNode('elastic_host') |
||
35 | ->cannotBeEmpty() |
||
36 | ->defaultValue('http://localhost:9200') |
||
37 | ->end() |
||
38 | ->arrayNode('loggable_paths') |
||
39 | ->prototype('scalar')->end() |
||
40 | ->end() |
||
41 | ->booleanNode('elastic_date_detection') |
||
42 | ->defaultValue(true) |
||
43 | ->end() |
||
44 | ->scalarNode('elastic_dynamic_date_formats') |
||
45 | ->cannotBeEmpty() |
||
46 | ->defaultValue('strict_date_optional_time||epoch_millis||strict_time') |
||
47 | ->end() |
||
48 | ->arrayNode('activity_log') |
||
49 | ->addDefaultsIfNotSet() |
||
50 | ->children() |
||
51 | ->arrayNode('elastic_properties') |
||
52 | ->arrayPrototype() |
||
53 | ->validate() |
||
54 | ->always(function($v){ |
||
55 | if (empty($v['properties'])) { |
||
56 | unset($v['properties']); |
||
57 | } |
||
58 | return $v; |
||
59 | }) |
||
60 | ->end() |
||
61 | ->children() |
||
62 | ->scalarNode('type')->end() |
||
63 | ->arrayNode('properties') |
||
64 | ->arrayPrototype()->scalarPrototype()->end()->end() |
||
65 | ->end() |
||
66 | ->end() |
||
67 | ->end() |
||
68 | ->defaultValue($this->getActivityLogProperties()) |
||
69 | ->end() |
||
70 | ->end() |
||
71 | ->end() |
||
72 | ->arrayNode('current_data_tracker') |
||
73 | ->addDefaultsIfNotSet() |
||
74 | ->children() |
||
75 | ->arrayNode('elastic_properties') |
||
76 | ->arrayPrototype() |
||
77 | ->validate() |
||
78 | ->always(function($v){ |
||
79 | if (empty($v['properties'])) { |
||
80 | unset($v['properties']); |
||
81 | } |
||
82 | return $v; |
||
83 | }) |
||
84 | ->end() |
||
85 | ->children() |
||
86 | ->scalarNode('type')->end() |
||
87 | ->arrayNode('properties') |
||
88 | ->arrayPrototype()->scalarPrototype()->end()->end() |
||
89 | ->end() |
||
90 | ->end() |
||
91 | ->end() |
||
92 | ->defaultValue($this->getCurrentDataTrackerProperties()) |
||
93 | ->end() |
||
94 | ->end() |
||
95 | ->end() |
||
96 | ->end() |
||
97 | ; |
||
98 | |||
99 | return $treeBuilder; |
||
100 | } |
||
101 | |||
102 | private function getActivityLogProperties(): array |
||
103 | { |
||
104 | return [ |
||
105 | 'action' => ['type' => 'text'], |
||
106 | 'loggedAt' => ['type' => 'date'], |
||
107 | 'objectId' => ['type' => 'text'], |
||
108 | 'objectType' => ['type' => 'text'], |
||
109 | 'objectClass' => ['type' => 'text'], |
||
110 | 'dataChanges' => ['type' => 'text'], |
||
111 | 'user' => [ |
||
112 | 'type' => 'object', |
||
113 | 'properties' => [ |
||
114 | 'username' => ['type' => 'text'], |
||
115 | ], |
||
116 | ], |
||
117 | ]; |
||
118 | } |
||
119 | |||
120 | public function getCurrentDataTrackerProperties(): array |
||
121 | { |
||
122 | return [ |
||
123 | 'dateTime' => ['type' => 'date'], |
||
124 | 'objectId' => ['type' => 'text'], |
||
125 | 'objectType' => ['type' => 'text'], |
||
126 | 'objectClass' => ['type' => 'text'], |
||
127 | 'data' => ['type' => 'text'], |
||
128 | ]; |
||
129 | } |
||
130 | } |
||
131 |