mirror of
https://github.com/standardebooks/web.git
synced 2025-07-09 16:20:27 -04:00
Switch from eval() to include() in template class. APC caches includes nowadays so caching is not necessary any more.
This commit is contained in:
parent
106a156f5e
commit
530cad6cc8
1 changed files with 3 additions and 13 deletions
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue