@@ -69,23 +69,6 @@ trait HelpersHandler
69
69
*/
70
70
protected $ nodeHandler ;
71
71
72
- /**
73
- * @var array
74
- */
75
- protected $ templatingHelpers = [
76
- 'actions ' ,
77
- 'assets ' ,
78
- 'code ' ,
79
- 'form ' ,
80
- 'request ' ,
81
- 'router ' ,
82
- 'security ' ,
83
- 'session ' ,
84
- 'slots ' ,
85
- 'stopwatch ' ,
86
- 'translator ' ,
87
- ];
88
-
89
72
/**
90
73
* Get the Pug engine.
91
74
*
@@ -94,10 +77,7 @@ trait HelpersHandler
94
77
public function getRenderer (): Pug
95
78
{
96
79
if ($ this ->pug === null ) {
97
- $ cache = $ this ->getCacheDir ();
98
- (new Filesystem ())->mkdir ($ cache );
99
-
100
- $ this ->pug = $ this ->createEngine ($ this ->getRendererOptions ($ cache ));
80
+ $ this ->pug = $ this ->createEngine ($ this ->getRendererOptions ());
101
81
$ this ->copyTwigFunctions ();
102
82
$ this ->initializePugPlugins ();
103
83
$ this ->share ($ this ->getTwig ()->getGlobals ());
@@ -112,51 +92,60 @@ public function onNode(callable $nodeHandler): void
112
92
$ this ->nodeHandler = $ nodeHandler ;
113
93
}
114
94
115
- protected function getRendererOptions (string $ cache ): array
95
+ protected function getRendererOptions (): array
116
96
{
117
- $ environment = $ this ->kernel ->getEnvironment ();
118
- $ projectDirectory = $ this ->kernel ->getProjectDir ();
119
- $ assetsDirectories = [$ projectDirectory .'/Resources/assets ' ];
120
- $ viewDirectories = [$ projectDirectory .'/templates ' ];
121
-
122
- if (($ loader = $ this ->getTwig ()->getLoader ()) instanceof FilesystemLoader &&
123
- is_array ($ paths = $ loader ->getPaths ()) &&
124
- isset ($ paths [0 ])
125
- ) {
126
- $ viewDirectories [] = $ paths [0 ];
127
- }
97
+ if ($ this ->options === null ) {
98
+ $ environment = $ this ->kernel ->getEnvironment ();
99
+ $ projectDirectory = $ this ->kernel ->getProjectDir ();
100
+ $ assetsDirectories = [$ projectDirectory .'/Resources/assets ' ];
101
+ $ viewDirectories = [$ projectDirectory .'/templates ' ];
102
+
103
+ if (($ loader = $ this ->getTwig ()->getLoader ()) instanceof FilesystemLoader &&
104
+ is_array ($ paths = $ loader ->getPaths ()) &&
105
+ isset ($ paths [0 ])
106
+ ) {
107
+ $ viewDirectories [] = $ paths [0 ];
108
+ }
128
109
129
- $ srcDir = $ projectDirectory .'/src ' ;
130
- $ webDir = $ projectDirectory .'/public ' ;
131
- $ baseDir = isset ($ this ->userOptions ['baseDir ' ])
132
- ? $ this ->userOptions ['baseDir ' ]
133
- : $ this ->crawlDirectories ($ srcDir , $ assetsDirectories , $ viewDirectories );
134
- $ baseDir = $ baseDir && file_exists ($ baseDir ) ? realpath ($ baseDir ) : $ baseDir ;
135
- $ this ->defaultTemplateDirectory = $ baseDir ;
110
+ $ srcDir = $ projectDirectory .'/src ' ;
111
+ $ webDir = $ projectDirectory .'/public ' ;
112
+ $ baseDir = isset ($ this ->userOptions ['baseDir ' ])
113
+ ? $ this ->userOptions ['baseDir ' ]
114
+ : $ this ->crawlDirectories ($ srcDir , $ assetsDirectories , $ viewDirectories );
115
+ $ baseDir = $ baseDir && file_exists ($ baseDir ) ? realpath ($ baseDir ) : $ baseDir ;
116
+ $ this ->defaultTemplateDirectory = $ baseDir ;
136
117
137
- if (isset ($ this ->userOptions ['paths ' ])) {
138
- $ viewDirectories = array_merge ($ viewDirectories , $ this ->userOptions ['paths ' ] ?: []);
118
+ if (isset ($ this ->userOptions ['paths ' ])) {
119
+ $ viewDirectories = array_merge ($ viewDirectories , $ this ->userOptions ['paths ' ] ?: []);
120
+ }
121
+
122
+ $ debug = $ this ->kernel ->isDebug ();
123
+ $ options = array_merge ([
124
+ 'debug ' => $ debug ,
125
+ 'assetDirectory ' => static ::extractUniquePaths ($ assetsDirectories ),
126
+ 'viewDirectories ' => static ::extractUniquePaths ($ viewDirectories ),
127
+ 'baseDir ' => $ baseDir ,
128
+ 'cache ' => $ debug ? false : $ this ->getCacheDir (),
129
+ 'environment ' => $ environment ,
130
+ 'extension ' => ['.pug ' , '.jade ' ],
131
+ 'outputDirectory ' => $ webDir ,
132
+ 'prettyprint ' => $ debug ,
133
+ 'on_node ' => $ this ->nodeHandler ,
134
+ ], $ this ->userOptions );
135
+ $ cache = $ options ['cache ' ] ?? $ options ['cache_dir ' ] ?? null ;
136
+
137
+ if ($ cache ) {
138
+ (new Filesystem ())->mkdir ($ cache );
139
+ }
140
+
141
+ $ options ['paths ' ] = array_unique (array_filter ($ options ['viewDirectories ' ], function ($ path ) use ($ baseDir ) {
142
+ return $ path !== $ baseDir ;
143
+ }));
144
+
145
+ $ this ->options = $ options ;
139
146
}
140
147
141
- $ debug = $ this ->kernel ->isDebug ();
142
- $ options = array_merge ([
143
- 'debug ' => $ debug ,
144
- 'assetDirectory ' => static ::extractUniquePaths ($ assetsDirectories ),
145
- 'viewDirectories ' => static ::extractUniquePaths ($ viewDirectories ),
146
- 'baseDir ' => $ baseDir ,
147
- 'cache ' => $ debug ? false : $ cache ,
148
- 'environment ' => $ environment ,
149
- 'extension ' => ['.pug ' , '.jade ' ],
150
- 'outputDirectory ' => $ webDir ,
151
- 'prettyprint ' => $ debug ,
152
- 'on_node ' => $ this ->nodeHandler ,
153
- ], $ this ->userOptions );
154
-
155
- $ options ['paths ' ] = array_unique (array_filter ($ options ['viewDirectories ' ], function ($ path ) use ($ baseDir ) {
156
- return $ path !== $ baseDir ;
157
- }));
158
-
159
- return $ options ;
148
+ return $ this ->options ;
160
149
}
161
150
162
151
protected function createEngine (array $ options ): Pug
@@ -232,9 +221,11 @@ protected function interpolateTwigFunctions(string $code): string
232
221
case ') ' :
233
222
if ((--$ opening ) !== 0 ) {
234
223
$ argument .= ') ' ;
224
+
225
+ break ;
235
226
}
236
227
237
- break ;
228
+ break 2 ;
238
229
239
230
case ', ' :
240
231
if ($ opening > 1 ) {
0 commit comments