File tree Expand file tree Collapse file tree 5 files changed +70
-0
lines changed
src/Symfony/Bundle/TwigBundle
Tests/DependencyInjection Expand file tree Collapse file tree 5 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 9
9
10
10
<xsd : complexType name =" config" >
11
11
<xsd : sequence >
12
+ <xsd : element name =" date" type =" date" minOccurs =" 0" maxOccurs =" 1" />
13
+ <xsd : element name =" number-format" type =" number_format" minOccurs =" 0" maxOccurs =" 1" />
14
+
12
15
<!-- @deprecated since version 2.6, to be removed in 3.0 -->
13
16
<xsd : element name =" form" type =" form" minOccurs =" 0" maxOccurs =" 1" />
14
17
<xsd : element name =" form-theme" type =" xsd:string" minOccurs =" 0" maxOccurs =" unbounded" />
28
31
<xsd : attribute name =" exception-controller" type =" xsd:string" />
29
32
</xsd : complexType >
30
33
34
+ <xsd : complexType name =" date" >
35
+ <xsd : attribute name =" format" type =" xsd:string" />
36
+ <xsd : attribute name =" interval-format" type =" xsd:string" />
37
+ <xsd : attribute name =" timezone" type =" xsd:string" />
38
+ </xsd : complexType >
39
+
40
+ <xsd : complexType name =" number_format" >
41
+ <xsd : attribute name =" decimals" type =" xsd:integer" />
42
+ <xsd : attribute name =" decimal-point" type =" xsd:string" />
43
+ <xsd : attribute name =" thousands-separator" type =" xsd:string" />
44
+ </xsd : complexType >
45
+
31
46
<xsd : complexType name =" form" >
32
47
<xsd : choice minOccurs =" 1" maxOccurs =" unbounded" >
33
48
<xsd : element name =" resource" type =" xsd:string" />
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ $ container ->loadFromExtension ('twig ' , array (
4
+ 'date ' => array (
5
+ 'format ' => 'Y-m-d ' ,
6
+ 'interval_format ' => '%d ' ,
7
+ 'timezone ' => 'Europe/Berlin ' ,
8
+ ),
9
+ 'number_format ' => array (
10
+ 'decimals ' => 2 ,
11
+ 'decimal_point ' => ', ' ,
12
+ 'thousands_separator ' => '. ' ,
13
+ ),
14
+ ));
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" ?>
2
+ <container xmlns =" http://symfony.com/schema/dic/services"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xmlns : twig =" http://symfony.com/schema/dic/twig"
5
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6
+ http://symfony.com/schema/dic/twig http://symfony.com/schema/dic/twig/twig-1.0.xsd" >
7
+
8
+ <twig : config >
9
+ <twig : date format =" Y-m-d" interval-format =" %d" timezone =" Europe/Berlin" />
10
+ <twig : number-format decimals =" 2" decimal-point =" ," thousands-separator =" ." />
11
+ </twig : config >
12
+ </container >
Original file line number Diff line number Diff line change
1
+ twig :
2
+ date :
3
+ format : Y-m-d
4
+ interval_format : ' %d'
5
+ timezone : Europe/Berlin
6
+ number_format :
7
+ decimals : 2
8
+ decimal_point : ' ,'
9
+ thousands_separator : .
Original file line number Diff line number Diff line change @@ -150,6 +150,26 @@ public function testLoadDefaultTemplateEscapingGuesserConfiguration($format)
150
150
$ this ->assertEquals ('name ' , $ options ['autoescape ' ]);
151
151
}
152
152
153
+ /**
154
+ * @dataProvider getFormats
155
+ */
156
+ public function testLoadCustomDateFormats ($ fileFormat )
157
+ {
158
+ $ container = $ this ->createContainer ();
159
+ $ container ->registerExtension (new TwigExtension ());
160
+ $ this ->loadFromFile ($ container , 'formats ' , $ fileFormat );
161
+ $ this ->compileContainer ($ container );
162
+
163
+ $ environmentConfigurator = $ container ->getDefinition ('twig.configurator.environment ' );
164
+
165
+ $ this ->assertSame ('Y-m-d ' , $ environmentConfigurator ->getArgument (0 ));
166
+ $ this ->assertSame ('%d ' , $ environmentConfigurator ->getArgument (1 ));
167
+ $ this ->assertSame ('Europe/Berlin ' , $ environmentConfigurator ->getArgument (2 ));
168
+ $ this ->assertSame (2 , $ environmentConfigurator ->getArgument (3 ));
169
+ $ this ->assertSame (', ' , $ environmentConfigurator ->getArgument (4 ));
170
+ $ this ->assertSame ('. ' , $ environmentConfigurator ->getArgument (5 ));
171
+ }
172
+
153
173
public function testGlobalsWithDifferentTypesAndValues ()
154
174
{
155
175
$ globals = array (
You can’t perform that action at this time.
0 commit comments