BaseGenerator.class.php (677B)
1 <?php 2 3 4 namespace cms\generator; 5 6 7 use util\cache\Cache; 8 use util\cache\FileCache; 9 10 11 /** 12 * Base class for generators. 13 * 14 * @package cms\generator 15 */ 16 abstract class BaseGenerator implements Generator 17 { 18 /** 19 * @var BaseContext 20 */ 21 protected $context; 22 23 /** 24 * Every generator has a cache for its value. 25 * @return Cache 26 */ 27 public function getCache() { 28 29 return new FileCache( $this->context->getCacheKey(),function() { 30 return $this->generate(); 31 }, 0 ); 32 } 33 34 35 /** 36 * Generates a value. 37 * 38 * @return mixed 39 */ 40 protected abstract function generate(); 41 42 43 /** 44 * Calculates the MIME-Type 45 * 46 * @return string 47 */ 48 public abstract function getMimeType(); 49 }