Switch from eval() to include() in template class. APC caches includes nowadays so caching is not necessary any more.

This commit is contained in:
Alex Cabal 2019-04-05 18:40:48 -05:00
parent 106a156f5e
commit 530cad6cc8

View file

@ -3,25 +3,15 @@ use function Safe\file_get_contents;
use function Safe\ob_end_clean;
class Template{
protected static $Cache = [];
protected static function Get(string $templateName, array $arguments = []): string{
// Expand the passed variables
// Use these funny names so that we can use 'name' and 'value' as template variables
// Expand the passed variables to make them available to the included template.
// We use these funny names so that we can use 'name' and 'value' as template variables if we want to.
foreach($arguments as $innerName => $innerValue){
$$innerName = $innerValue;
}
if(array_key_exists($templateName, self::$Cache)){
$fileContents = self::$Cache[$templateName];
}
else{
$fileContents = file_get_contents(TEMPLATES_PATH . '/' . $templateName . '.php');
self::$Cache[$templateName] = $fileContents;
}
ob_start();
eval(' ?>' . $fileContents . '<? ');
include(TEMPLATES_PATH . '/' . $templateName . '.php');
$contents = ob_get_contents() ?: '';
ob_end_clean();