11
11
12
12
namespace Symfony \Bundle \TwigBundle ;
13
13
14
+ use Symfony \Bridge \Twig \TwigEngine as BaseEngine ;
14
15
use Symfony \Bundle \FrameworkBundle \Templating \EngineInterface ;
15
16
use Symfony \Bundle \FrameworkBundle \Templating \GlobalVariables ;
16
17
use Symfony \Bundle \FrameworkBundle \Templating \TemplateReference ;
17
18
use Symfony \Component \Templating \TemplateNameParserInterface ;
18
19
use Symfony \Component \HttpFoundation \Response ;
19
20
use Symfony \Component \Config \FileLocatorInterface ;
20
- use Symfony \Component \Templating \StreamingEngineInterface ;
21
21
22
22
/**
23
23
* This engine knows how to render Twig templates.
24
24
*
25
25
* @author Fabien Potencier <fabien@symfony.com>
26
26
*/
27
- class TwigEngine implements EngineInterface, StreamingEngineInterface
27
+ class TwigEngine extends BaseEngine implements EngineInterface
28
28
{
29
- protected $ environment ;
30
- protected $ parser ;
31
29
protected $ locator ;
32
30
33
31
/**
@@ -40,8 +38,8 @@ class TwigEngine implements EngineInterface, StreamingEngineInterface
40
38
*/
41
39
public function __construct (\Twig_Environment $ environment , TemplateNameParserInterface $ parser , FileLocatorInterface $ locator , GlobalVariables $ globals = null )
42
40
{
43
- $ this -> environment = $ environment ;
44
- $ this -> parser = $ parser ;
41
+ parent :: __construct ( $ environment, $ parser ) ;
42
+
45
43
$ this ->locator = $ locator ;
46
44
47
45
if (null !== $ globals ) {
@@ -63,7 +61,7 @@ public function __construct(\Twig_Environment $environment, TemplateNameParserIn
63
61
public function render ($ name , array $ parameters = array ())
64
62
{
65
63
try {
66
- return $ this -> load ($ name)-> render ( $ parameters );
64
+ return parent :: render ($ name, $ parameters );
67
65
} catch (\Twig_Error $ e ) {
68
66
if ($ name instanceof TemplateReference) {
69
67
try {
@@ -77,55 +75,6 @@ public function render($name, array $parameters = array())
77
75
}
78
76
}
79
77
80
- /**
81
- * Streams a template.
82
- *
83
- * @param mixed $name A template name or a TemplateReferenceInterface instance
84
- * @param array $parameters An array of parameters to pass to the template
85
- *
86
- * @throws \RuntimeException if the template cannot be rendered
87
- */
88
- public function stream ($ name , array $ parameters = array ())
89
- {
90
- $ this ->load ($ name )->display ($ parameters );
91
- }
92
-
93
- /**
94
- * Returns true if the template exists.
95
- *
96
- * @param mixed $name A template name
97
- *
98
- * @return Boolean true if the template exists, false otherwise
99
- */
100
- public function exists ($ name )
101
- {
102
- try {
103
- $ this ->load ($ name );
104
- } catch (\InvalidArgumentException $ e ) {
105
- return false ;
106
- }
107
-
108
- return true ;
109
- }
110
-
111
- /**
112
- * Returns true if this class is able to render the given template.
113
- *
114
- * @param string $name A template name
115
- *
116
- * @return Boolean True if this class supports the given resource, false otherwise
117
- */
118
- public function supports ($ name )
119
- {
120
- if ($ name instanceof \Twig_Template) {
121
- return true ;
122
- }
123
-
124
- $ template = $ this ->parser ->parse ($ name );
125
-
126
- return 'twig ' === $ template ->get ('engine ' );
127
- }
128
-
129
78
/**
130
79
* Renders a view and returns a Response.
131
80
*
@@ -145,26 +94,4 @@ public function renderResponse($view, array $parameters = array(), Response $res
145
94
146
95
return $ response ;
147
96
}
148
-
149
- /**
150
- * Loads the given template.
151
- *
152
- * @param mixed $name A template name or an instance of Twig_Template
153
- *
154
- * @return \Twig_TemplateInterface A \Twig_TemplateInterface instance
155
- *
156
- * @throws \InvalidArgumentException if the template does not exist
157
- */
158
- protected function load ($ name )
159
- {
160
- if ($ name instanceof \Twig_Template) {
161
- return $ name ;
162
- }
163
-
164
- try {
165
- return $ this ->environment ->loadTemplate ($ name );
166
- } catch (\Twig_Error_Loader $ e ) {
167
- throw new \InvalidArgumentException ($ e ->getMessage (), $ e ->getCode (), $ e );
168
- }
169
- }
170
97
}
0 commit comments