@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $cachedOutput = $this->loadTemplate(); |
| 32 | 32 | $xml = $cachedOutput['body']; |
| 33 | 33 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 34 | - $template = new Template($this->isValidDoc($xml) ? $xml : '<template>' . $xml . '</template>' ); |
|
| 34 | + $template = new Template($this->isValidDoc($xml) ? $xml : '<template>'.$xml.'</template>'); |
|
| 35 | 35 | $time = time(); |
| 36 | 36 | |
| 37 | 37 | foreach ($this->getRules($template) as $rule) { |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | private function getRules($template) { |
| 61 | 61 | if (is_file($this->tss)) { |
| 62 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
| 63 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
| 62 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
| 63 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
| 64 | 64 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 65 | 65 | if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
| 66 | 66 | else return $rules; |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | private function getLocale() { |
| 86 | 86 | if (is_array($this->locale)) return $this->locale; |
| 87 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 88 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 87 | + else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.$this->locale.'.json'), true); |
|
| 88 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | public function registerProperties($object) { |
@@ -34,10 +34,14 @@ discard block |
||
| 34 | 34 | $template = new Template($this->isValidDoc($xml) ? $xml : '<template>' . $xml . '</template>' ); |
| 35 | 35 | |
| 36 | 36 | //Allow $time to be set via arguments to spoof time passage during tests |
| 37 | - if (!$time) $time = time(); |
|
| 37 | + if (!$time) { |
|
| 38 | + $time = time(); |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | foreach ($this->getRules($template) as $rule) { |
| 40 | - if ($rule->shouldRun($time)) $this->executeTssRule($rule, $template, $data); |
|
| 42 | + if ($rule->shouldRun($time)) { |
|
| 43 | + $this->executeTssRule($rule, $template, $data); |
|
| 44 | + } |
|
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | $output = $template->output($document); |
@@ -49,7 +53,9 @@ discard block |
||
| 49 | 53 | private function executeTssRule($rule, $template, $data) { |
| 50 | 54 | $rule->touch(); |
| 51 | 55 | $hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data); |
| 52 | - foreach ($this->registeredProperties as $properties) $hook->registerProperties($properties); |
|
| 56 | + foreach ($this->registeredProperties as $properties) { |
|
| 57 | + $hook->registerProperties($properties); |
|
| 58 | + } |
|
| 53 | 59 | $template->addHook($rule->query, $hook); |
| 54 | 60 | } |
| 55 | 61 | |
@@ -57,8 +63,9 @@ discard block |
||
| 57 | 63 | if (trim($this->template)[0] !== '<') { |
| 58 | 64 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 59 | 65 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 66 | + } else { |
|
| 67 | + return ['body' => $this->template, 'headers' => []]; |
|
| 60 | 68 | } |
| 61 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 62 | 69 | } |
| 63 | 70 | |
| 64 | 71 | private function getRules($template) { |
@@ -66,10 +73,14 @@ discard block |
||
| 66 | 73 | $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
| 67 | 74 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
| 68 | 75 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 69 | - if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
| 70 | - else return $rules; |
|
| 76 | + if (!$rules) { |
|
| 77 | + return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
|
| 78 | + } else { |
|
| 79 | + return $rules; |
|
| 80 | + } |
|
| 81 | + } else { |
|
| 82 | + return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
| 71 | 83 | } |
| 72 | - else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse(); |
|
| 73 | 84 | } |
| 74 | 85 | |
| 75 | 86 | private function getBasicProperties($data, $locale, &$headers) { |
@@ -77,7 +88,9 @@ discard block |
||
| 77 | 88 | $basicProperties->registerFormatter(new Formatter\Number($locale)); |
| 78 | 89 | $basicProperties->registerFormatter(new Formatter\Date($locale)); |
| 79 | 90 | $basicProperties->registerFormatter(new Formatter\StringFormatter()); |
| 80 | - foreach ($this->formatters as $formatter) $basicProperties->registerFormatter($formatter); |
|
| 91 | + foreach ($this->formatters as $formatter) { |
|
| 92 | + $basicProperties->registerFormatter($formatter); |
|
| 93 | + } |
|
| 81 | 94 | |
| 82 | 95 | return isset($this->userCache) ? new Hook\Cache($basicProperties, $this->userCache) : $basicProperties; |
| 83 | 96 | } |
@@ -87,9 +100,13 @@ discard block |
||
| 87 | 100 | } |
| 88 | 101 | |
| 89 | 102 | private function getLocale() { |
| 90 | - if (is_array($this->locale)) return $this->locale; |
|
| 91 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 92 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 103 | + if (is_array($this->locale)) { |
|
| 104 | + return $this->locale; |
|
| 105 | + } else if (strlen($this->locale) > 0) { |
|
| 106 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 107 | + } else { |
|
| 108 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 109 | + } |
|
| 93 | 110 | } |
| 94 | 111 | |
| 95 | 112 | public function registerProperties($object) { |
@@ -20,7 +20,8 @@ |
||
| 20 | 20 | public function load($key, $modified = 0) { |
| 21 | 21 | if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) { |
| 22 | 22 | return $this->cache[$key]['content']; |
| 23 | + } else { |
|
| 24 | + return false; |
|
| 23 | 25 | } |
| 24 | - else return false; |
|
| 25 | 26 | } |
| 26 | 27 | } |
| 27 | 28 | \ No newline at end of file |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | const S = 1; |
| 12 | 12 | const M = 60; |
| 13 | - const H = self::M*60; |
|
| 14 | - const D = self::H*24; |
|
| 13 | + const H = self::M * 60; |
|
| 14 | + const D = self::H * 24; |
|
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | public function __construct($query, $pseudo, $depth, $index, array $properties = []) { |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | $num = (int) $frequency; |
| 44 | 44 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 45 | 45 | |
| 46 | - $offset = $num * constant(self::class . '::' . $unit); |
|
| 46 | + $offset = $num * constant(self::class.'::'.$unit); |
|
| 47 | 47 | |
| 48 | - if ($time > $this->lastRun + $offset) return true; |
|
| 48 | + if ($time > $this->lastRun+$offset) return true; |
|
| 49 | 49 | else return false; |
| 50 | 50 | |
| 51 | 51 | } |
@@ -38,17 +38,23 @@ |
||
| 38 | 38 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
| 39 | 39 | $frequency = $this->properties['update-frequency']; |
| 40 | 40 | $static = ['always' => true, 'never' => false]; |
| 41 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
| 41 | + if (isset($static[$frequency])) { |
|
| 42 | + return $static[$frequency]; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | $num = (int) $frequency; |
| 44 | 46 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 45 | 47 | |
| 46 | 48 | $offset = $num * constant(self::class . '::' . $unit); |
| 47 | 49 | |
| 48 | - if ($time > $this->lastRun + $offset) return true; |
|
| 49 | - else return false; |
|
| 50 | + if ($time > $this->lastRun + $offset) { |
|
| 51 | + return true; |
|
| 52 | + } else { |
|
| 53 | + return false; |
|
| 54 | + } |
|
| 50 | 55 | |
| 56 | + } else { |
|
| 57 | + return true; |
|
| 51 | 58 | } |
| 52 | - else return true; |
|
| 53 | 59 | } |
| 54 | 60 | } |
| 55 | 61 | \ No newline at end of file |