@@ -208,9 +208,7 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
208
208
$ compiledPath = function ($ templatePath ) use (
209
209
$ voltConfig ,
210
210
$ basePath ,
211
- $ ptoolsPath ,
212
- $ appCacheDir ,
213
- $ defaultCacheDir
211
+ $ ptoolsPath
214
212
) {
215
213
/**
216
214
* @var DiInterface $this
@@ -225,20 +223,8 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
225
223
$ templatePath = trim ($ templatePath , '\\/ ' );
226
224
$ filename = str_replace (['\\' , '/ ' ], $ voltConfig ->get ('separator ' , '_ ' ), $ templatePath );
227
225
$ filename = basename ($ filename , '.volt ' ) . $ voltConfig ->get ('compiledExt ' , '.php ' );
228
- $ cacheDir = $ voltConfig ->get ('cacheDir ' , $ appCacheDir );
229
-
230
- if (!$ cacheDir || !is_dir ($ cacheDir ) || !is_writable ($ cacheDir )) {
231
- $ this ->getShared ('logger ' )->warning (
232
- 'Unable to initialize Volt cache dir: {cache}. Used temp path: {default} ' ,
233
- [
234
- 'cache ' => $ cacheDir ,
235
- 'default ' => $ defaultCacheDir
236
- ]
237
- );
238
-
239
- $ cacheDir = $ defaultCacheDir ;
240
- mkdir ($ cacheDir , 0777 , true );
241
- }
226
+
227
+ $ cacheDir = self ::getCacheDir ($ voltConfig );
242
228
243
229
return rtrim ($ cacheDir , '\\/ ' ) . DS . $ filename ;
244
230
};
@@ -256,6 +242,38 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
256
242
);
257
243
}
258
244
245
+ /**
246
+ * get volt cache directory
247
+ *
248
+ * @param Config $voltConfig
249
+ *
250
+ * @return string
251
+ */
252
+ protected function getCacheDir (Config $ voltConfig )
253
+ {
254
+ $ appCacheDir = $ this ->di ->getShared ('config ' )->path ('application.cacheDir ' );
255
+ $ cacheDir = $ voltConfig ->get ('cacheDir ' , $ appCacheDir );
256
+ $ defaultCacheDir = sys_get_temp_dir () . DS . 'phalcon ' . DS . 'volt ' ;
257
+
258
+ if ($ cacheDir && is_dir ($ cacheDir ) && is_writable ($ cacheDir )) {
259
+ return $ cacheDir ;
260
+ }
261
+
262
+ $ this ->di ->getShared ('logger ' )->warning (
263
+ 'Unable to initialize Volt cache dir: {cache}. Used temp path: {default} ' ,
264
+ [
265
+ 'cache ' => $ cacheDir ,
266
+ 'default ' => $ defaultCacheDir
267
+ ]
268
+ );
269
+
270
+ if (!is_dir ($ defaultCacheDir )) {
271
+ mkdir ($ defaultCacheDir , 0777 , true );
272
+ }
273
+
274
+ return $ defaultCacheDir ;
275
+ }
276
+
259
277
/**
260
278
* Initialize the View.
261
279
*/
@@ -676,20 +694,21 @@ function () {
676
694
*/
677
695
protected function initUi ()
678
696
{
697
+ $ that = $ this ;
698
+
679
699
$ this ->di ->setShared (
680
700
'sidebar ' ,
681
- function () {
701
+ function () use ( $ that ) {
682
702
/**
683
- * @var DiInterface $this
684
703
* @var Registry $registry
685
704
*/
686
- $ registry = $ this ->getShared ('registry ' );
705
+ $ registry = $ that -> di ->getShared ('registry ' );
687
706
$ menuItems = $ registry ->offsetGet ('directories ' )->elementsDir . DS . 'sidebar-menu.php ' ;
688
707
689
708
/** @noinspection PhpIncludeInspection */
690
709
$ menu = new SidebarMenu (include $ menuItems );
691
710
692
- $ menu ->setDI ($ this ->di );
711
+ $ menu ->setDI ($ that ->di );
693
712
694
713
return $ menu ;
695
714
}
0 commit comments