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:
Belle Aerni 2023-01-19 15:07:15 -08:00
parent ea7f3ac65b
commit 97e6a8a4e6
5 changed files with 7 additions and 11 deletions

View File

@ -5,3 +5,4 @@ parameters:
excludePaths:
analyse:
- src/Vendor
- src/Cache

View File

@ -19,7 +19,6 @@ class AntCMS
{
$start_time = microtime(true);
$content = $this->getPage($page);
$antTwig = new AntTwig;
if (!$content || !is_array($content)) {
$this->renderException("404");
@ -36,7 +35,7 @@ class AntCMS
'AntCMSKeywords' => $content['keywords'],
);
$pageTemplate = str_replace('<!--AntCMS-Body-->', $markdown, $pageTemplate);
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
$end_time = microtime(true);
$elapsed_time = round($end_time - $start_time, 4);

View File

@ -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);
return $navHTML;

View File

@ -12,7 +12,7 @@ class AntTwig
* @param string|null $theme
* @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;
$theme = $theme ?? AntConfig::currentConfig('activeTheme');

View File

@ -38,7 +38,6 @@ class AdminPlugin extends AntPlugin
$this->managePages($route);
default:
$antTwig = new AntTwig;
$params = array(
'AntCMSTitle' => '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/pages/'>Page management</a><br>\n";
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
echo $pageTemplate;
break;
@ -68,7 +67,6 @@ class AdminPlugin extends AntPlugin
$HTMLTemplate = $antCMS->getThemeTemplate('textarea_edit_layout');
$currentConfig = AntConfig::currentConfig();
$currentConfigFile = file_get_contents(antConfigFile);
$antTwig = new AntTwig;
$params = array(
'AntCMSTitle' => 'AntCMS Configuration',
'AntCMSDescription' => 'The AntCMS configuration screen',
@ -119,7 +117,7 @@ class AdminPlugin extends AntPlugin
}
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
echo $pageTemplate;
exit;
@ -135,7 +133,6 @@ class AdminPlugin extends AntPlugin
$pageTemplate = $antCMS->getPageLayout();
$HTMLTemplate = $antCMS->getThemeTemplate('markdown_edit_layout');
$pages = AntPages::getPages();
$antTwig = new AntTwig;
$params = array(
'AntCMSTitle' => 'AntCMS Page Management',
'AntCMSDescription' => 'The AntCMS page management screen',
@ -247,7 +244,7 @@ class AdminPlugin extends AntPlugin
}
$pageTemplate = str_replace('<!--AntCMS-Body-->', $HTMLTemplate, $pageTemplate);
$pageTemplate = $antTwig->renderWithTiwg($pageTemplate, $params);
$pageTemplate = AntTwig::renderWithTiwg($pageTemplate, $params);
echo $pageTemplate;
exit;