Make renderWithTiwg a static function
There's zero need to create a new instance of the class before calling it, so this removes a very small amount of overhead, but more importantly removes the need to create and define a new class of it each time, which makes the code very slightly cleaner
This commit is contained in:
parent
ea7f3ac65b
commit
97e6a8a4e6
5 changed files with 7 additions and 11 deletions
|
@ -5,3 +5,4 @@ parameters:
|
||||||
excludePaths:
|
excludePaths:
|
||||||
analyse:
|
analyse:
|
||||||
- src/Vendor
|
- src/Vendor
|
||||||
|
- src/Cache
|
||||||
|
|
|
@ -19,7 +19,6 @@ class AntCMS
|
||||||
{
|
{
|
||||||
$start_time = microtime(true);
|
$start_time = microtime(true);
|
||||||
$content = $this->getPage($page);
|
$content = $this->getPage($page);
|
||||||
$antTwig = new AntTwig;
|
|
||||||
|
|
||||||
if (!$content || !is_array($content)) {
|
if (!$content || !is_array($content)) {
|
||||||
$this->renderException("404");
|
$this->renderException("404");
|
||||||
|
@ -36,7 +35,7 @@ class AntCMS
|
||||||
'AntCMSKeywords' => $content['keywords'],
|
'AntCMSKeywords' => $content['keywords'],
|
||||||
);
|
);
|
||||||
$pageTemplate = str_replace('<!--AntCMS-Body-->', $markdown, $pageTemplate);
|
$pageTemplate = str_replace('<!--AntCMS-Body-->', $markdown, $pageTemplate);
|
||||||
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
|
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
|
||||||
|
|
||||||
$end_time = microtime(true);
|
$end_time = microtime(true);
|
||||||
$elapsed_time = round($end_time - $start_time, 4);
|
$elapsed_time = round($end_time - $start_time, 4);
|
||||||
|
|
|
@ -94,8 +94,7 @@ class AntPages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$antTwig = new AntTwig;
|
$navHTML = AntTwig::renderWithTiwg($navTemplate, array('pages' => $pages));
|
||||||
$navHTML = $antTwig->renderWithTiwg($navTemplate, array('pages' => $pages));
|
|
||||||
|
|
||||||
$antCache->setCache($cacheKey, $navHTML);
|
$antCache->setCache($cacheKey, $navHTML);
|
||||||
return $navHTML;
|
return $navHTML;
|
||||||
|
|
|
@ -12,7 +12,7 @@ class AntTwig
|
||||||
* @param string|null $theme
|
* @param string|null $theme
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function renderWithTiwg(string $content = '', array $params = array(), string $theme = null)
|
public static function renderWithTiwg(string $content = '', array $params = array(), string $theme = null)
|
||||||
{
|
{
|
||||||
$twigCache = AntConfig::currentConfig('enableCache') ? AntCachePath : false;
|
$twigCache = AntConfig::currentConfig('enableCache') ? AntCachePath : false;
|
||||||
$theme = $theme ?? AntConfig::currentConfig('activeTheme');
|
$theme = $theme ?? AntConfig::currentConfig('activeTheme');
|
||||||
|
|
|
@ -38,7 +38,6 @@ class AdminPlugin extends AntPlugin
|
||||||
$this->managePages($route);
|
$this->managePages($route);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$antTwig = new AntTwig;
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'AntCMSTitle' => 'AntCMS Admin Dashboard',
|
'AntCMSTitle' => 'AntCMS Admin Dashboard',
|
||||||
'AntCMSDescription' => 'The AntCMS admin dashboard',
|
'AntCMSDescription' => 'The AntCMS admin dashboard',
|
||||||
|
@ -50,7 +49,7 @@ class AdminPlugin extends AntPlugin
|
||||||
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/config/'>AntCMS Configuration</a><br>\n";
|
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/config/'>AntCMS Configuration</a><br>\n";
|
||||||
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/'>Page management</a><br>\n";
|
$HTMLTemplate .= "<a href='//" . AntConfig::currentConfig('baseURL') . "plugin/admin/pages/'>Page management</a><br>\n";
|
||||||
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
|
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
|
||||||
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
|
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
|
||||||
|
|
||||||
echo $pageTemplate;
|
echo $pageTemplate;
|
||||||
break;
|
break;
|
||||||
|
@ -68,7 +67,6 @@ class AdminPlugin extends AntPlugin
|
||||||
$HTMLTemplate = $antCMS->getThemeTemplate('textarea_edit_layout');
|
$HTMLTemplate = $antCMS->getThemeTemplate('textarea_edit_layout');
|
||||||
$currentConfig = AntConfig::currentConfig();
|
$currentConfig = AntConfig::currentConfig();
|
||||||
$currentConfigFile = file_get_contents(antConfigFile);
|
$currentConfigFile = file_get_contents(antConfigFile);
|
||||||
$antTwig = new AntTwig;
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'AntCMSTitle' => 'AntCMS Configuration',
|
'AntCMSTitle' => 'AntCMS Configuration',
|
||||||
'AntCMSDescription' => 'The AntCMS configuration screen',
|
'AntCMSDescription' => 'The AntCMS configuration screen',
|
||||||
|
@ -119,7 +117,7 @@ class AdminPlugin extends AntPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
|
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
|
||||||
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
|
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
|
||||||
|
|
||||||
echo $pageTemplate;
|
echo $pageTemplate;
|
||||||
exit;
|
exit;
|
||||||
|
@ -135,7 +133,6 @@ class AdminPlugin extends AntPlugin
|
||||||
$pageTemplate = $antCMS->getPageLayout();
|
$pageTemplate = $antCMS->getPageLayout();
|
||||||
$HTMLTemplate = $antCMS->getThemeTemplate('markdown_edit_layout');
|
$HTMLTemplate = $antCMS->getThemeTemplate('markdown_edit_layout');
|
||||||
$pages = AntPages::getPages();
|
$pages = AntPages::getPages();
|
||||||
$antTwig = new AntTwig;
|
|
||||||
$params = array(
|
$params = array(
|
||||||
'AntCMSTitle' => 'AntCMS Page Management',
|
'AntCMSTitle' => 'AntCMS Page Management',
|
||||||
'AntCMSDescription' => 'The AntCMS page management screen',
|
'AntCMSDescription' => 'The AntCMS page management screen',
|
||||||
|
@ -247,7 +244,7 @@ class AdminPlugin extends AntPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
|
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
|
||||||
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
|
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
|
||||||
|
|
||||||
echo $pageTemplate;
|
echo $pageTemplate;
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Reference in a new issue