@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $cachedOutput = $this->loadTemplate(); |
| 39 | 39 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 40 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 40 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 41 | 41 | |
| 42 | 42 | //Allow $time to be set via arguments to spoof time passage during tests |
| 43 | 43 | foreach ($this->getRules($template) as $rule) { |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | //N.b. only files can be cached |
| 79 | 79 | private function getRules($template) { |
| 80 | 80 | if (is_file($this->tss)) { |
| 81 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
| 81 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
| 82 | 82 | //The cache for the key: the filename and template prefix |
| 83 | 83 | //Each template may have a different prefix which changes the parsed TSS, |
| 84 | 84 | //Because of this the cache needs to be generated for each template prefix. |
| 85 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
| 85 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
| 86 | 86 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 87 | 87 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 88 | 88 | if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse()); |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | private function getLocale() { |
| 109 | 109 | if (is_array($this->locale)) return $this->locale; |
| 110 | - 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); |
|
| 111 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 110 | + 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); |
|
| 111 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | public function registerProperties($object) { |
@@ -63,12 +63,15 @@ discard block |
||
| 63 | 63 | $node = $element->ownerDocument->importNode($node, true); |
| 64 | 64 | $element->appendChild($node); |
| 65 | 65 | } |
| 66 | + } else { |
|
| 67 | + $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
| 66 | 68 | } |
| 67 | - else $element->appendChild($element->ownerDocument->createTextNode(implode('', $content))); |
|
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | private function removeAllChildren($element) { |
| 71 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 72 | + while ($element->hasChildNodes()) { |
|
| 73 | + $element->removeChild($element->firstChild); |
|
| 74 | + } |
|
| 72 | 75 | } |
| 73 | 76 | |
| 74 | 77 | public function registerFormatter($formatter) { |
@@ -76,11 +79,15 @@ discard block |
||
| 76 | 79 | } |
| 77 | 80 | |
| 78 | 81 | private function format($value, $rules) { |
| 79 | - if (!isset($rules['format'])) return $value; |
|
| 82 | + if (!isset($rules['format'])) { |
|
| 83 | + return $value; |
|
| 84 | + } |
|
| 80 | 85 | $format = new \Transphporm\StringExtractor($rules['format']); |
| 81 | 86 | $options = explode(' ', $format); |
| 82 | 87 | $functionName = array_shift($options); |
| 83 | - foreach ($options as &$f) $f = trim($format->rebuild($f), '"'); |
|
| 88 | + foreach ($options as &$f) { |
|
| 89 | + $f = trim($format->rebuild($f), '"'); |
|
| 90 | + } |
|
| 84 | 91 | |
| 85 | 92 | return $this->processFormat($options, $functionName, $value); |
| 86 | 93 | } |
@@ -97,7 +104,9 @@ discard block |
||
| 97 | 104 | } |
| 98 | 105 | |
| 99 | 106 | public function repeat($value, $element, $rule) { |
| 100 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
| 107 | + if ($element->getAttribute('transphporm') === 'added') { |
|
| 108 | + return $element->parentNode->removeChild($element); |
|
| 109 | + } |
|
| 101 | 110 | |
| 102 | 111 | foreach ($value as $key => $iteration) { |
| 103 | 112 | $clone = $element->cloneNode(true); |
@@ -114,7 +123,9 @@ discard block |
||
| 114 | 123 | unset($newRules['repeat']); |
| 115 | 124 | |
| 116 | 125 | $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data); |
| 117 | - foreach ($rule->getProperties() as $obj) $hook->registerProperties($obj); |
|
| 126 | + foreach ($rule->getProperties() as $obj) { |
|
| 127 | + $hook->registerProperties($obj); |
|
| 128 | + } |
|
| 118 | 129 | $hook->run($clone); |
| 119 | 130 | } |
| 120 | 131 | |
@@ -125,8 +136,11 @@ discard block |
||
| 125 | 136 | } |
| 126 | 137 | |
| 127 | 138 | public function display($value, $element) { |
| 128 | - if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
| 129 | - else $element->setAttribute('transphporm', 'show'); |
|
| 139 | + if (strtolower($value[0]) === 'none') { |
|
| 140 | + $element->setAttribute('transphporm', 'remove'); |
|
| 141 | + } else { |
|
| 142 | + $element->setAttribute('transphporm', 'show'); |
|
| 143 | + } |
|
| 130 | 144 | } |
| 131 | 145 | |
| 132 | 146 | public function bind($value, $element) { |
@@ -9,8 +9,11 @@ |
||
| 9 | 9 | class PostProcess implements \Transphporm\Hook { |
| 10 | 10 | public function run(\DomElement $element) { |
| 11 | 11 | $transphporm = $element->getAttribute('transphporm'); |
| 12 | - if ($transphporm === 'remove') $element->parentNode->removeChild($element); |
|
| 13 | - else $element->removeAttribute('transphporm'); |
|
| 12 | + if ($transphporm === 'remove') { |
|
| 13 | + $element->parentNode->removeChild($element); |
|
| 14 | + } else { |
|
| 15 | + $element->removeAttribute('transphporm'); |
|
| 16 | + } |
|
| 14 | 17 | } |
| 15 | 18 | |
| 16 | 19 | } |
| 17 | 20 | \ No newline at end of file |