Mercurial > SimpleWebPresenter
comparison InputParser.inc @ 66:74f7b64bdb78
Lots of documentation fixes, and removal of unused function getXmlContent
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Thu, 11 Oct 2012 22:11:33 +0200 |
| parents | 92c3e52c12d4 |
| children | 4dfa3f6a2dc1 |
comparison
equal
deleted
inserted
replaced
| 65:7b87ec8b0842 | 66:74f7b64bdb78 |
|---|---|
| 1 <?php | 1 <?php |
| 2 /** | 2 /** |
| 3 * @file | 3 * Functionality for translating an XML configuration document into a webpage |
| 4 * Functionality for translating an XML document into a webpage | |
| 5 */ | 4 */ |
| 6 class InputParser { | 5 class InputParser { |
| 7 private $options; | 6 private $options; |
| 8 private $master; | 7 private $master; |
| 9 | 8 |
| 9 /** | |
| 10 * Constructs a new InputParser object | |
| 11 * | |
| 12 * @param $name name of file to read configuration from | |
| 13 * @param $masterCache CacheTimeCheck cache object to use as parent for this inputParsercache | |
| 14 * | |
| 15 * @todo masterCache is currently used as is, fix so linked caches | |
| 16 * may be used. | |
| 17 */ | |
| 10 function __construct($name, $masterCache) { | 18 function __construct($name, $masterCache) { |
| 11 $this->master = new DOMDocument(); | 19 $this->master = new DOMDocument(); |
| 12 $cache = $masterCache; | 20 $cache = $masterCache; |
| 13 $cache->cache_time($name); | 21 $cache->cache_time($name); |
| 14 $this->master->load($name); | 22 $this->master->load($name); |
| 47 } | 55 } |
| 48 $this->master = self::getFiles($this->master, $this->options); | 56 $this->master = self::getFiles($this->master, $this->options); |
| 49 | 57 |
| 50 } | 58 } |
| 51 | 59 |
| 60 /** | |
| 61 * Generate an appropriate response for this page, eg. 302 NOT | |
| 62 * MODIFIED or the actual page | |
| 63 */ | |
| 52 function genPage() | 64 function genPage() |
| 53 { | 65 { |
| 54 if (CACHING && $this->options->getCacheable()) | 66 if (CACHING && $this->options->getCacheable()) |
| 55 $this->options->getCache()->CheckHttpModified(); | 67 $this->options->getCache()->CheckHttpModified(); |
| 56 | 68 |
| 57 print $this->master->saveXml($this->master); | 69 print $this->master->saveXml($this->master); |
| 58 //print_r($cache->cacheSet(1)); | 70 //print_r($cache->cacheSet(1)); |
| 59 } | 71 } |
| 60 | 72 |
| 61 | 73 /** |
| 74 * Extracts data from a @<param@> tag. | |
| 75 * | |
| 76 * @param $param the param tag | |
| 77 * | |
| 78 * @return if the type is array, return an array, otherwise return a | |
| 79 * scalar | |
| 80 */ | |
| 62 function getParam($param) | 81 function getParam($param) |
| 63 { | 82 { |
| 64 $param_type=$param->getAttribute("type"); | 83 $param_type = $param->getAttribute("type"); |
| 65 $param_value; | 84 $param_value; |
| 66 if (!$param_type) | 85 if (! $param_type) |
| 67 $param_type="scalar"; | 86 $param_type = "scalar"; |
| 68 | 87 |
| 69 if($param_type == "scalar") { | 88 if($param_type == "scalar") { |
| 70 $param_subst=$param->getAttribute("subst"); | 89 $param_subst = $param->getAttribute("subst"); |
| 71 $param_value=$param->getAttribute("value"); | 90 $param_value = $param->getAttribute("value"); |
| 72 if ($param_subst) { | 91 if ($param_subst) { |
| 73 /* | 92 /* |
| 74 $param_value=preg_replace("/name/", $name, $param_subst); | 93 $param_value=preg_replace("/name/", $name, $param_subst); |
| 75 $param_value=preg_replace('/lang/', $lang, $param_value); | 94 $param_value=preg_replace('/lang/', $lang, $param_value); |
| 76 */ | 95 */ |
| 77 } | 96 } |
| 78 } | 97 } |
| 79 elseif($param_type == "array") { | 98 elseif($param_type == "array") { |
| 80 $params=$param->getElementsByTagName("param"); | 99 $params = $param->getElementsByTagName("param"); |
| 81 $param_value=array(); | 100 $param_value = array(); |
| 82 foreach ($param->childNodes as $param) { | 101 foreach ($param->childNodes as $param) { |
| 83 if ($param->nodeType == XML_ELEMENT_NODE) | 102 if ($param->nodeType == XML_ELEMENT_NODE) { |
| 84 { | 103 array_push($param_value, self::getParam($param)); |
| 85 array_push($param_value, self::getParam($param)); | 104 } |
| 86 } | |
| 87 } | 105 } |
| 88 } | 106 } |
| 89 return $param_value; | 107 return $param_value; |
| 90 } | 108 } |
| 91 | 109 |
| 92 function getFiles($doc, $options) { | 110 /** |
| 111 * This is the last processing stage for generating a file. | |
| 112 * | |
| 113 * @param $doc the document to be worked upon | |
| 114 * @param $options an Options object for this file. | |
| 115 * | |
| 116 * @return This is the same as the input document, fully processed | |
| 117 */ | |
| 118 static function getFiles($doc, $options) { | |
| 93 $lang = $options->getLang(); | 119 $lang = $options->getLang(); |
| 94 $conf = $options->getName(); | 120 $conf = $options->getName(); |
| 95 | 121 |
| 96 $toRemove = array(); | 122 $toRemove = array(); |
| 97 | 123 |
| 226 } | 252 } |
| 227 | 253 |
| 228 return $doc; | 254 return $doc; |
| 229 } | 255 } |
| 230 | 256 |
| 257 /** | |
| 258 * Follows all include directives recursively for the specified | |
| 259 * $param an generates an xml file. | |
| 260 * | |
| 261 * This function may be used to generate a file which has all the | |
| 262 * necessary information to determine wether or not we may cache. | |
| 263 * | |
| 264 * @param $master The master document to be processed | |
| 265 * @param $param the input tag to resolve | |
| 266 * @param $options the options object for this file | |
| 267 */ | |
| 231 function getInput($master, $param, $options) | 268 function getInput($master, $param, $options) |
| 232 { | 269 { |
| 233 $lang = $options->getLang(); | 270 $lang = $options->getLang(); |
| 234 $name = $param->getAttribute("id"); | 271 $name = $param->getAttribute("id"); |
| 235 $conf = $options->getName(); | 272 $conf = $options->getName(); |
