Mercurial > SimpleWebPresenter
comparison Page.inc @ 80:88904282b888
Documentation fixes.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 12 Oct 2012 16:59:19 +0200 |
| parents | 7c68015b211a |
| children | 2a8e2f571b24 |
comparison
equal
deleted
inserted
replaced
| 79:9b490aa11124 | 80:88904282b888 |
|---|---|
| 6 $cache = ScriptIncludeCache::instance(__FILE__); | 6 $cache = ScriptIncludeCache::instance(__FILE__); |
| 7 $cache->includeOnce('Options.inc', dirname(__FILE__)); | 7 $cache->includeOnce('Options.inc', dirname(__FILE__)); |
| 8 /// @endcond | 8 /// @endcond |
| 9 | 9 |
| 10 /** | 10 /** |
| 11 * Functionality for generating a page | 11 * Master class for generating a page |
| 12 */ | 12 */ |
| 13 class Page | 13 class Page |
| 14 { | 14 { |
| 15 private $cache; | 15 private $cache; |
| 16 | 16 |
| 17 function __construct($cache) | 17 /** |
| 18 * Constructs a page | |
| 19 * | |
| 20 * @param $cache optionally sets a cache | |
| 21 */ | |
| 22 function __construct($cache = null) | |
| 18 { | 23 { |
| 19 $this->setCache($cache); | 24 $this->setCache($cache); |
| 20 } | 25 } |
| 21 | 26 |
| 27 /** | |
| 28 * Set the cache | |
| 29 * | |
| 30 * @param $cache The cache object | |
| 31 */ | |
| 22 protected function setCache($cache) | 32 protected function setCache($cache) |
| 23 { | 33 { |
| 24 $this->cache = $cache; | 34 $this->cache = $cache; |
| 25 } | 35 } |
| 26 | 36 |
| 37 /** | |
| 38 * Get the cache | |
| 39 * | |
| 40 * @return The cache object | |
| 41 */ | |
| 27 protected function getCache() | 42 protected function getCache() |
| 28 { | 43 { |
| 29 return $this->cache; | 44 return $this->cache; |
| 30 } | 45 } |
| 31 | 46 |
| 47 /** | |
| 48 * Decide wether or not this page may be compressed. | |
| 49 * | |
| 50 * Normally this is a check for http headers, but some pages | |
| 51 * eg. pictures may not want to be compressed, and may override this | |
| 52 * function. | |
| 53 * | |
| 54 * @return bool if this page may be compressed | |
| 55 */ | |
| 32 function mayCompress() | 56 function mayCompress() |
| 33 { | 57 { |
| 34 return (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')); | 58 return (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')); |
| 35 } | 59 } |
| 36 | 60 |
| 61 /** | |
| 62 * Turns on compression for this page | |
| 63 * | |
| 64 * @note This may not be reversed | |
| 65 */ | |
| 37 function startCompression() | 66 function startCompression() |
| 38 { | 67 { |
| 39 ob_start("ob_gzhandler"); | 68 ob_start("ob_gzhandler"); |
| 40 } | 69 } |
| 41 | 70 |
| 71 /** | |
| 72 * Generates the actual content of the page | |
| 73 * | |
| 74 * @return the content buffer | |
| 75 */ | |
| 76 abstract function generateContent(); | |
| 77 | |
| 78 /** | |
| 79 * Finishes all necessary processing to determine the cacheset of this page. | |
| 80 * | |
| 81 * @return bool if this page may be cached | |
| 82 */ | |
| 83 abstract function cacheCheck(); | |
| 84 | |
| 85 /** | |
| 86 * Generates an appropriate response to the request. | |
| 87 * | |
| 88 * Eg. 302 NOT CHANGED, error message or the actual content | |
| 89 */ | |
| 42 function genPage() | 90 function genPage() |
| 43 { | 91 { |
| 44 if ($this->cacheCheck()) { | 92 if ($this->cacheCheck()) { |
| 45 $this->cache->CheckHttpModified(); | 93 $this->cache->CheckHttpModified(); |
| 46 } | 94 } |
