diff --git a/scripts/Phalcon/Initializable.php b/scripts/Phalcon/Initializable.php index 1a8a64fca..c4c76e136 100644 --- a/scripts/Phalcon/Initializable.php +++ b/scripts/Phalcon/Initializable.php @@ -208,9 +208,7 @@ function ($view, $di) use ($basePath, $ptoolsPath) { $compiledPath = function ($templatePath) use ( $voltConfig, $basePath, - $ptoolsPath, - $appCacheDir, - $defaultCacheDir + $ptoolsPath ) { /** * @var DiInterface $this @@ -225,20 +223,8 @@ function ($view, $di) use ($basePath, $ptoolsPath) { $templatePath = trim($templatePath, '\\/'); $filename = str_replace(['\\', '/'], $voltConfig->get('separator', '_'), $templatePath); $filename = basename($filename, '.volt') . $voltConfig->get('compiledExt', '.php'); - $cacheDir = $voltConfig->get('cacheDir', $appCacheDir); - - if (!$cacheDir || !is_dir($cacheDir) || !is_writable($cacheDir)) { - $this->getShared('logger')->warning( - 'Unable to initialize Volt cache dir: {cache}. Used temp path: {default}', - [ - 'cache' => $cacheDir, - 'default' => $defaultCacheDir - ] - ); - - $cacheDir = $defaultCacheDir; - mkdir($cacheDir, 0777, true); - } + + $cacheDir = self::getCacheDir($voltConfig); return rtrim($cacheDir, '\\/') . DS . $filename; }; @@ -256,6 +242,38 @@ function ($view, $di) use ($basePath, $ptoolsPath) { ); } + /** + * get volt cache directory + * + * @param Config $voltConfig + * + * @return string + */ + protected function getCacheDir(Config $voltConfig) + { + $appCacheDir = $this->di->getShared('config')->path('application.cacheDir'); + $cacheDir = $voltConfig->get('cacheDir', $appCacheDir); + $defaultCacheDir = sys_get_temp_dir() . DS . 'phalcon' . DS . 'volt'; + + if ($cacheDir && is_dir($cacheDir) && is_writable($cacheDir)) { + return $cacheDir; + } + + $this->di->getShared('logger')->warning( + 'Unable to initialize Volt cache dir: {cache}. Used temp path: {default}', + [ + 'cache' => $cacheDir, + 'default' => $defaultCacheDir + ] + ); + + if (!is_dir($defaultCacheDir)) { + mkdir($defaultCacheDir, 0777, true); + } + + return $defaultCacheDir; + } + /** * Initialize the View. */ @@ -676,20 +694,21 @@ function () { */ protected function initUi() { + $that = $this; + $this->di->setShared( 'sidebar', - function () { + function () use ($that) { /** - * @var DiInterface $this * @var Registry $registry */ - $registry = $this->getShared('registry'); + $registry = $that->di->getShared('registry'); $menuItems = $registry->offsetGet('directories')->elementsDir . DS . 'sidebar-menu.php'; /** @noinspection PhpIncludeInspection */ $menu = new SidebarMenu(include $menuItems); - $menu->setDI($this->di); + $menu->setDI($that->di); return $menu; }