1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the QueryResourcesLoaderBundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\QueryResourcesLoader\DependencyInjection\Configuration; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class TwigNodeDefinition |
16
|
|
|
* |
17
|
|
|
* Twig environment configuration. |
18
|
|
|
* |
19
|
|
|
* @package RunOpenCode\Bundle\QueryResourcesLoader\DependencyInjection\Configuration |
20
|
|
|
* @internal |
21
|
|
|
*/ |
22
|
|
|
class TwigNodeDefinition extends ArrayNodeDefinition |
23
|
|
|
{ |
24
|
2 |
|
public function __construct() |
25
|
|
|
{ |
26
|
2 |
|
parent::__construct('twig'); |
27
|
|
|
|
28
|
|
|
$this |
29
|
2 |
|
->configureTwigOptions() |
30
|
2 |
|
->configureTwigFormatOptions() |
31
|
2 |
|
->addDefaultsIfNotSet(); |
32
|
2 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Configure Twig options. |
36
|
|
|
* |
37
|
|
|
* @return TwigNodeDefinition $this |
38
|
|
|
*/ |
39
|
2 |
|
private function configureTwigOptions() |
40
|
|
|
{ |
41
|
|
|
$this |
42
|
2 |
|
->fixXmlConfig('path') |
43
|
2 |
|
->children() |
44
|
2 |
|
->variableNode('autoescape')->defaultValue(false)->end() |
45
|
2 |
|
->scalarNode('autoescape_service')->defaultNull()->end() |
46
|
2 |
|
->scalarNode('autoescape_service_method')->defaultNull()->end() |
47
|
2 |
|
->scalarNode('base_template_class')->example('Twig_Template')->cannotBeEmpty()->end() |
48
|
2 |
|
->scalarNode('cache')->defaultValue('%kernel.cache_dir%/query_resources/twig')->end() |
49
|
2 |
|
->scalarNode('charset')->defaultValue('%kernel.charset%')->end() |
50
|
2 |
|
->booleanNode('debug')->defaultValue('%kernel.debug%')->end() |
51
|
2 |
|
->booleanNode('strict_variables')->end() |
52
|
2 |
|
->scalarNode('auto_reload')->end() |
53
|
2 |
|
->integerNode('optimizations')->min(-1)->end() |
54
|
2 |
|
->arrayNode('paths') |
55
|
2 |
|
->normalizeKeys(false) |
56
|
2 |
|
->useAttributeAsKey('paths') |
57
|
2 |
|
->beforeNormalization() |
58
|
2 |
|
->always() |
59
|
2 |
|
->then(function ($paths) { |
60
|
1 |
|
$normalized = array(); |
61
|
1 |
|
foreach ($paths as $path => $namespace) { |
62
|
1 |
|
if (is_array($namespace)) { |
63
|
|
|
// xml |
64
|
1 |
|
$path = $namespace['value']; |
65
|
1 |
|
$namespace = $namespace['namespace']; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// path within the default namespace |
69
|
1 |
|
if (ctype_digit((string) $path)) { |
70
|
|
|
$path = $namespace; |
71
|
|
|
$namespace = null; |
72
|
|
|
} |
73
|
|
|
|
74
|
1 |
|
$normalized[$path] = $namespace; |
75
|
|
|
} |
76
|
|
|
|
77
|
1 |
|
return $normalized; |
78
|
2 |
|
}) |
79
|
2 |
|
->end() |
80
|
2 |
|
->prototype('variable')->end() |
81
|
2 |
|
->end() |
82
|
2 |
|
->end() |
83
|
|
|
; |
84
|
|
|
|
85
|
2 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Configure Twig format options. |
90
|
|
|
* |
91
|
|
|
* @return TwigNodeDefinition $this |
92
|
|
|
*/ |
93
|
2 |
|
private function configureTwigFormatOptions() |
94
|
|
|
{ |
95
|
|
|
$this |
96
|
2 |
|
->children() |
97
|
2 |
|
->arrayNode('date') |
98
|
2 |
|
->info('The default format options used by the date filter') |
99
|
2 |
|
->addDefaultsIfNotSet() |
100
|
2 |
|
->children() |
101
|
2 |
|
->scalarNode('format')->defaultValue('F j, Y H:i')->end() |
102
|
2 |
|
->scalarNode('interval_format')->defaultValue('%d days')->end() |
103
|
2 |
|
->scalarNode('timezone') |
104
|
2 |
|
->info('The timezone used when formatting dates, when set to null, the timezone returned by date_default_timezone_get() is used') |
105
|
2 |
|
->defaultNull() |
106
|
2 |
|
->end() |
107
|
2 |
|
->end() |
108
|
2 |
|
->end() |
109
|
2 |
|
->arrayNode('number_format') |
110
|
2 |
|
->info('The default format options for the number_format filter') |
111
|
2 |
|
->addDefaultsIfNotSet() |
112
|
2 |
|
->children() |
113
|
2 |
|
->integerNode('decimals')->defaultValue(0)->end() |
114
|
2 |
|
->scalarNode('decimal_point')->defaultValue('.')->end() |
115
|
2 |
|
->scalarNode('thousands_separator')->defaultValue(',')->end() |
116
|
2 |
|
->end() |
117
|
2 |
|
->end() |
118
|
2 |
|
->end() |
119
|
|
|
; |
120
|
|
|
|
121
|
2 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|