1<?php 2 3/** 4 * "Singleton" 5 */ 6class CSSCache { 7 function get() { 8 global $__g_css_manager; 9 10 if (!isset($__g_css_manager)) { 11 $__g_css_manager = new CSSCache(); 12 }; 13 14 return $__g_css_manager; 15 } 16 17 function _getCacheFilename($url) { 18 return CACHE_DIR.md5($url).'.css.compiled'; 19 } 20 21 function _isCached($url) { 22 $cache_filename = $this->_getCacheFilename($url); 23 return is_readable($cache_filename); 24 } 25 26 function &_readCached($url) { 27 $cache_filename = $this->_getCacheFilename($url); 28 $obj = unserialize(file_get_contents($cache_filename)); 29 return $obj; 30 } 31 32 function _putCached($url, $css) { 33 file_put_contents($this->_getCacheFilename($url), serialize($css)); 34 } 35 36 function &compile($url, $css, &$pipeline) { 37 if ($this->_isCached($url)) { 38 return $this->_readCached($url); 39 } else { 40 $cssruleset = new CSSRuleset(); 41 $cssruleset->parse_css($css, $pipeline); 42 $this->_putCached($url, $cssruleset); 43 return $cssruleset; 44 }; 45 } 46} 47 48?>