Skip to content

Commit 61ece69

Browse files
authored
Merge pull request #1134 from phalcon/3.2.x
3.2.9
2 parents c77ddde + 6295b22 commit 61ece69

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

scripts/Phalcon/Initializable.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
208208
$compiledPath = function ($templatePath) use (
209209
$voltConfig,
210210
$basePath,
211-
$ptoolsPath,
212-
$appCacheDir,
213-
$defaultCacheDir
211+
$ptoolsPath
214212
) {
215213
/**
216214
* @var DiInterface $this
@@ -225,20 +223,8 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
225223
$templatePath = trim($templatePath, '\\/');
226224
$filename = str_replace(['\\', '/'], $voltConfig->get('separator', '_'), $templatePath);
227225
$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);
242228

243229
return rtrim($cacheDir, '\\/') . DS . $filename;
244230
};
@@ -256,6 +242,38 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
256242
);
257243
}
258244

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+
259277
/**
260278
* Initialize the View.
261279
*/
@@ -676,20 +694,21 @@ function () {
676694
*/
677695
protected function initUi()
678696
{
697+
$that = $this;
698+
679699
$this->di->setShared(
680700
'sidebar',
681-
function () {
701+
function () use ($that) {
682702
/**
683-
* @var DiInterface $this
684703
* @var Registry $registry
685704
*/
686-
$registry = $this->getShared('registry');
705+
$registry = $that->di->getShared('registry');
687706
$menuItems = $registry->offsetGet('directories')->elementsDir . DS . 'sidebar-menu.php';
688707

689708
/** @noinspection PhpIncludeInspection */
690709
$menu = new SidebarMenu(include $menuItems);
691710

692-
$menu->setDI($this->di);
711+
$menu->setDI($that->di);
693712

694713
return $menu;
695714
}

0 commit comments

Comments
 (0)