Skip to content

Commit

Permalink
Merge pull request phalcon#1134 from phalcon/3.2.x
Browse files Browse the repository at this point in the history
3.2.9
  • Loading branch information
sergeyklay authored Oct 25, 2017
2 parents c77ddde + 6295b22 commit 61ece69
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions scripts/Phalcon/Initializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ function ($view, $di) use ($basePath, $ptoolsPath) {
$compiledPath = function ($templatePath) use (
$voltConfig,
$basePath,
$ptoolsPath,
$appCacheDir,
$defaultCacheDir
$ptoolsPath
) {
/**
* @var DiInterface $this
Expand All @@ -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;
};
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 61ece69

Please sign in to comment.