@@ -69,23 +69,6 @@ trait HelpersHandler
6969 */
7070 protected $ nodeHandler ;
7171
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-
8972 /**
9073 * Get the Pug engine.
9174 *
@@ -94,10 +77,7 @@ trait HelpersHandler
9477 public function getRenderer (): Pug
9578 {
9679 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 ());
10181 $ this ->copyTwigFunctions ();
10282 $ this ->initializePugPlugins ();
10383 $ this ->share ($ this ->getTwig ()->getGlobals ());
@@ -112,51 +92,60 @@ public function onNode(callable $nodeHandler): void
11292 $ this ->nodeHandler = $ nodeHandler ;
11393 }
11494
115- protected function getRendererOptions (string $ cache ): array
95+ protected function getRendererOptions (): array
11696 {
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+ }
128109
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 ;
136117
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 ;
139146 }
140147
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 ;
160149 }
161150
162151 protected function createEngine (array $ options ): Pug
@@ -232,9 +221,11 @@ protected function interpolateTwigFunctions(string $code): string
232221 case ') ' :
233222 if ((--$ opening ) !== 0 ) {
234223 $ argument .= ') ' ;
224+
225+ break ;
235226 }
236227
237- break ;
228+ break 2 ;
238229
239230 case ', ' :
240231 if ($ opening > 1 ) {
0 commit comments