1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89:
<?php
class StringTemplateLoader implements TemplateLoader
{
private $content = '';
private $hashed_content;
private static $parsing_cache = null;
public static function __static()
{
self::$parsing_cache = new RAMDataStore();
}
public function __construct($content)
{
$this->content = $content;
$this->hashed_content = md5($content);
}
public function load()
{
if (self::is_cached($this->hashed_content))
{
return self::get_cached_template($this->hashed_content);
}
else
{
$parser = new TemplateSyntaxParser();
$parsed_content = $parser->parse($this->content);
self::register_cached_template($this->hashed_content, $parsed_content);
return $parsed_content;
}
}
private static function is_cached($hashed_content)
{
return self::$parsing_cache->contains($hashed_content);
}
private static function get_cached_template($hashed_content)
{
return self::$parsing_cache->get($hashed_content);
}
private static function register_cached_template($hashed_content, $parsed_content)
{
self::$parsing_cache->store($hashed_content, $parsed_content);
}
public function supports_caching()
{
return false;
}
public function get_cache_file_path()
{
return null;
}
}
?>