@@ -13,7 +13,7 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function currency($num) { |
| 15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
| 16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
| 17 | - else return $num . $this->locale['currency']; |
|
| 16 | + if ($this->locale['currency_position'] === 'before') return $this->locale['currency'].$num; |
|
| 17 | + else return $num.$this->locale['currency']; |
|
| 18 | 18 | } |
| 19 | 19 | } |
| 20 | 20 | \ No newline at end of file |
@@ -13,7 +13,10 @@ |
||
| 13 | 13 | |
| 14 | 14 | public function currency($num) { |
| 15 | 15 | $num = $this->decimal($num, $this->locale['currency_decimals']); |
| 16 | - if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num; |
|
| 17 | - else return $num . $this->locale['currency']; |
|
| 16 | + if ($this->locale['currency_position'] === 'before') { |
|
| 17 | + return $this->locale['currency'] . $num; |
|
| 18 | + } else { |
|
| 19 | + return $num . $this->locale['currency']; |
|
| 20 | + } |
|
| 18 | 21 | } |
| 19 | 22 | } |
| 20 | 23 | \ No newline at end of file |
@@ -39,9 +39,9 @@ |
||
| 39 | 39 | $num = (int) $frequency; |
| 40 | 40 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 41 | 41 | |
| 42 | - $offset = $num * constant(self::class . '::' . $unit); |
|
| 42 | + $offset = $num * constant(self::class.'::'.$unit); |
|
| 43 | 43 | |
| 44 | - if ($time > $this->lastRun + $offset) return true; |
|
| 44 | + if ($time > $this->lastRun+$offset) return true; |
|
| 45 | 45 | else return false; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | private $pseudo; |
| 11 | 11 | private $depth; |
| 12 | 12 | private $index; |
| 13 | - private $file; |
|
| 13 | + private $file; |
|
| 14 | 14 | private $line; |
| 15 | 15 | private $properties = []; |
| 16 | 16 | private $lastRun = 0; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $this->pseudo = $pseudo; |
| 27 | 27 | $this->depth = $depth; |
| 28 | 28 | $this->index = $index; |
| 29 | - $this->file = $file; |
|
| 29 | + $this->file = $file; |
|
| 30 | 30 | $this->line = $line; |
| 31 | 31 | $this->properties = $properties; |
| 32 | 32 | } |
@@ -44,23 +44,32 @@ |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | private function timeFrequency($frequency, $time = null) { |
| 47 | - if ($time === null) $time = time(); |
|
| 47 | + if ($time === null) { |
|
| 48 | + $time = time(); |
|
| 49 | + } |
|
| 48 | 50 | $num = (int) $frequency; |
| 49 | 51 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 50 | 52 | |
| 51 | 53 | $offset = $num * constant(self::class . '::' . $unit); |
| 52 | 54 | |
| 53 | - if ($time > $this->lastRun + $offset) return true; |
|
| 54 | - else return false; |
|
| 55 | + if ($time > $this->lastRun + $offset) { |
|
| 56 | + return true; |
|
| 57 | + } else { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 55 | 60 | } |
| 56 | 61 | |
| 57 | 62 | public function shouldRun($time = null) { |
| 58 | 63 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
| 59 | 64 | $frequency = $this->properties['update-frequency']->read(); |
| 60 | 65 | $static = ['always' => true, 'never' => false]; |
| 61 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
| 62 | - else return $this->timeFrequency($frequency, $time); |
|
| 66 | + if (isset($static[$frequency])) { |
|
| 67 | + return $static[$frequency]; |
|
| 68 | + } else { |
|
| 69 | + return $this->timeFrequency($frequency, $time); |
|
| 70 | + } |
|
| 71 | + } else { |
|
| 72 | + return true; |
|
| 63 | 73 | } |
| 64 | - else return true; |
|
| 65 | 74 | } |
| 66 | 75 | } |
@@ -9,9 +9,13 @@ |
||
| 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 if ($transphporm === 'text') $element->parentNode->replaceChild($element->firstChild, $element); |
|
| 14 | - else $element->removeAttribute('transphporm'); |
|
| 12 | + if ($transphporm === 'remove') { |
|
| 13 | + $element->parentNode->removeChild($element); |
|
| 14 | + } else if ($transphporm === 'text') { |
|
| 15 | + $element->parentNode->replaceChild($element->firstChild, $element); |
|
| 16 | + } else { |
|
| 17 | + $element->removeAttribute('transphporm'); |
|
| 18 | + } |
|
| 15 | 19 | } |
| 16 | 20 | |
| 17 | 21 | } |
| 18 | 22 | \ No newline at end of file |
@@ -7,8 +7,12 @@ |
||
| 7 | 7 | namespace Transphporm\Property; |
| 8 | 8 | class Display implements \Transphporm\Property { |
| 9 | 9 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 10 | - if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
| 11 | - else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
| 12 | - else $element->setAttribute('transphporm', 'show'); |
|
| 10 | + if ($pseudoMatcher->hasFunction('attr')) { |
|
| 11 | + $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
| 12 | + } else if (strtolower($values[0]) === 'none') { |
|
| 13 | + $element->setAttribute('transphporm', 'remove'); |
|
| 14 | + } else { |
|
| 15 | + $element->setAttribute('transphporm', 'show'); |
|
| 16 | + } |
|
| 13 | 17 | } |
| 14 | 18 | } |
@@ -102,14 +102,14 @@ |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | private function getProperties($tokens) { |
| 105 | - $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
| 105 | + $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
| 106 | 106 | |
| 107 | - $return = []; |
|
| 108 | - foreach ($rules as $rule) { |
|
| 109 | - $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
| 110 | - $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
| 111 | - } |
|
| 107 | + $return = []; |
|
| 108 | + foreach ($rules as $rule) { |
|
| 109 | + $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
| 110 | + $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $return; |
|
| 114 | - } |
|
| 113 | + return $return; |
|
| 114 | + } |
|
| 115 | 115 | } |
@@ -39,6 +39,9 @@ discard block |
||
| 39 | 39 | return $this->cache->write($this->file, $rules, $this->import); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | + /** |
|
| 43 | + * @param integer $indexStart |
|
| 44 | + */ |
|
| 42 | 45 | private function parseTokens($indexStart) { |
| 43 | 46 | $this->rules = []; |
| 44 | 47 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
@@ -65,6 +68,10 @@ discard block |
||
| 65 | 68 | if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
| 66 | 69 | } |
| 67 | 70 | |
| 71 | + /** |
|
| 72 | + * @param Tokens $selector |
|
| 73 | + * @param integer $index |
|
| 74 | + */ |
|
| 68 | 75 | private function CssToRules($selector, $index, $properties, $line) { |
| 69 | 76 | $parts = $selector->trim()->splitOnToken(Tokenizer::ARG); |
| 70 | 77 | $rules = []; |
@@ -88,6 +95,9 @@ discard block |
||
| 88 | 95 | return $rules; |
| 89 | 96 | } |
| 90 | 97 | |
| 98 | + /** |
|
| 99 | + * @param integer $indexStart |
|
| 100 | + */ |
|
| 91 | 101 | private function processingInstructions($token, $indexStart) { |
| 92 | 102 | if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
| 93 | 103 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
@@ -121,7 +121,7 @@ |
||
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | private function sortPseudo($a, $b) { |
| 124 | - return count($a->pseudo) < count($b->pseudo) ? -1 :1; |
|
| 124 | + return count($a->pseudo) < count($b->pseudo) ? -1 : 1; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | private function getProperties($tokens) { |
@@ -25,14 +25,19 @@ discard block |
||
| 25 | 25 | $this->file = $tss; |
| 26 | 26 | $this->rules = $this->cache->load($tss); |
| 27 | 27 | $this->filePath->addPath(dirname(realpath($tss))); |
| 28 | - if (empty($this->rules)) $tss = file_get_contents($tss); |
|
| 29 | - else return; |
|
| 28 | + if (empty($this->rules)) { |
|
| 29 | + $tss = file_get_contents($tss); |
|
| 30 | + } else { |
|
| 31 | + return; |
|
| 32 | + } |
|
| 30 | 33 | } |
| 31 | 34 | $this->tss = (new Tokenizer($tss))->getTokens(); |
| 32 | 35 | } |
| 33 | 36 | |
| 34 | 37 | public function parse($indexStart = 0) { |
| 35 | - if (!empty($this->rules)) return $this->rules['rules']; |
|
| 38 | + if (!empty($this->rules)) { |
|
| 39 | + return $this->rules['rules']; |
|
| 40 | + } |
|
| 36 | 41 | $rules = $this->parseTokens($indexStart); |
| 37 | 42 | usort($rules, [$this, 'sortRules']); |
| 38 | 43 | $this->checkError($rules); |
@@ -45,8 +50,9 @@ discard block |
||
| 45 | 50 | foreach (new TokenFilterIterator($this->tss, [Tokenizer::WHITESPACE]) as $token) { |
| 46 | 51 | if ($processing = $this->processingInstructions($token, count($this->rules)+$indexStart)) { |
| 47 | 52 | $this->rules = array_merge($this->rules, $processing); |
| 53 | + } else if ($token['type'] !== Tokenizer::NEW_LINE) { |
|
| 54 | + $this->addRules($token, $indexStart++); |
|
| 48 | 55 | } |
| 49 | - else if ($token['type'] !== Tokenizer::NEW_LINE) $this->addRules($token, $indexStart++); |
|
| 50 | 56 | } |
| 51 | 57 | |
| 52 | 58 | return $this->rules; |
@@ -56,14 +62,18 @@ discard block |
||
| 56 | 62 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
| 57 | 63 | |
| 58 | 64 | $this->tss->skip(count($selector)); |
| 59 | - if (count($selector) === 0) return; |
|
| 65 | + if (count($selector) === 0) { |
|
| 66 | + return; |
|
| 67 | + } |
|
| 60 | 68 | |
| 61 | 69 | $newRules = $this->cssToRules($selector, count($this->rules)+$indexStart, $this->getProperties($this->tss->current()['value']), $token['line']); |
| 62 | 70 | $this->rules = $this->writeRule($this->rules, $newRules); |
| 63 | 71 | } |
| 64 | 72 | |
| 65 | 73 | private function checkError($rules) { |
| 66 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
| 74 | + if (empty($rules) && count($this->tss) > 0) { |
|
| 75 | + throw new \Exception('No TSS rules parsed'); |
|
| 76 | + } |
|
| 67 | 77 | } |
| 68 | 78 | |
| 69 | 79 | private function CssToRules($selector, $index, $properties, $line) { |
@@ -91,7 +101,9 @@ discard block |
||
| 91 | 101 | } |
| 92 | 102 | |
| 93 | 103 | private function processingInstructions($token, $indexStart) { |
| 94 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
| 104 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 95 | 107 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
| 96 | 108 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
| 97 | 109 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -111,10 +123,15 @@ discard block |
||
| 111 | 123 | |
| 112 | 124 | private function sortRules($a, $b) { |
| 113 | 125 | //If they have the same depth, compare on index |
| 114 | - if ($a->query === $b->query) return $this->sortPseudo($a, $b); |
|
| 126 | + if ($a->query === $b->query) { |
|
| 127 | + return $this->sortPseudo($a, $b); |
|
| 128 | + } |
|
| 115 | 129 | |
| 116 | - if ($a->depth === $b->depth) $property = 'index'; |
|
| 117 | - else $property = 'depth'; |
|
| 130 | + if ($a->depth === $b->depth) { |
|
| 131 | + $property = 'index'; |
|
| 132 | + } else { |
|
| 133 | + $property = 'depth'; |
|
| 134 | + } |
|
| 118 | 135 | |
| 119 | 136 | return ($a->$property < $b->$property) ? -1 : 1; |
| 120 | 137 | } |
@@ -35,7 +35,9 @@ |
||
| 35 | 35 | |
| 36 | 36 | public function rewind() { |
| 37 | 37 | $this->tokens->rewind(); |
| 38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
| 38 | + while ($this->shouldContinue()) { |
|
| 39 | + $this->tokens->next(); |
|
| 40 | + } |
|
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | private function shouldContinue() { |
@@ -6,39 +6,39 @@ |
||
| 6 | 6 | * @version 1.2 */ |
| 7 | 7 | namespace Transphporm\Parser; |
| 8 | 8 | class TokenFilterIterator implements \Iterator { |
| 9 | - private $ignore; |
|
| 10 | - private $tokens; |
|
| 9 | + private $ignore; |
|
| 10 | + private $tokens; |
|
| 11 | 11 | |
| 12 | - public function __construct(Tokens $tokens, array $ignore) { |
|
| 13 | - $this->ignore = $ignore; |
|
| 14 | - $this->tokens = $tokens; |
|
| 15 | - } |
|
| 12 | + public function __construct(Tokens $tokens, array $ignore) { |
|
| 13 | + $this->ignore = $ignore; |
|
| 14 | + $this->tokens = $tokens; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - public function current() { |
|
| 18 | - return $this->tokens->current(); |
|
| 19 | - } |
|
| 17 | + public function current() { |
|
| 18 | + return $this->tokens->current(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - public function key() { |
|
| 22 | - return $this->tokens->key(); |
|
| 23 | - } |
|
| 21 | + public function key() { |
|
| 22 | + return $this->tokens->key(); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - public function valid() { |
|
| 26 | - return $this->tokens->valid(); |
|
| 27 | - } |
|
| 25 | + public function valid() { |
|
| 26 | + return $this->tokens->valid(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function next() { |
|
| 30 | - do { |
|
| 31 | - $this->tokens->next(); |
|
| 32 | - } |
|
| 33 | - while ($this->shouldContinue()); |
|
| 34 | - } |
|
| 29 | + public function next() { |
|
| 30 | + do { |
|
| 31 | + $this->tokens->next(); |
|
| 32 | + } |
|
| 33 | + while ($this->shouldContinue()); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function rewind() { |
|
| 37 | - $this->tokens->rewind(); |
|
| 38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
| 39 | - } |
|
| 36 | + public function rewind() { |
|
| 37 | + $this->tokens->rewind(); |
|
| 38 | + while ($this->shouldContinue()) $this->tokens->next(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - private function shouldContinue() { |
|
| 42 | - return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
| 43 | - } |
|
| 41 | + private function shouldContinue() { |
|
| 42 | + return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -62,6 +62,10 @@ discard block |
||
| 62 | 62 | return (object) $result; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + /** |
|
| 66 | + * @param Template $template |
|
| 67 | + * @param Config $config |
|
| 68 | + */ |
|
| 65 | 69 | private function processRules($template, $config) { |
| 66 | 70 | $rules = $this->getRules($template, $config); |
| 67 | 71 | |
@@ -71,6 +75,10 @@ discard block |
||
| 71 | 75 | } |
| 72 | 76 | |
| 73 | 77 | //Add a postprocessing hook. This cleans up anything transphporm has added to the markup which needs to be removed |
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param Template $template |
|
| 81 | + */ |
|
| 74 | 82 | private function doPostProcessing($template) { |
| 75 | 83 | $template->addHook('//*[@transphporm]', new Hook\PostProcess()); |
| 76 | 84 | return $template; |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | |
| 54 | 54 | $cachedOutput = $this->loadTemplate(); |
| 55 | 55 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 56 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 56 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 57 | 57 | $valueParser = new Parser\Value($functionSet); |
| 58 | 58 | $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers); |
| 59 | 59 | |
@@ -27,7 +27,9 @@ discard block |
||
| 27 | 27 | $this->cache = new Cache(new \ArrayObject()); |
| 28 | 28 | $this->filePath = new FilePath(); |
| 29 | 29 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
| 30 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
| 30 | + foreach ($modules as $module) { |
|
| 31 | + $this->loadModule(new $module); |
|
| 32 | + } |
|
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -56,7 +58,9 @@ discard block |
||
| 56 | 58 | $valueParser = new Parser\Value($functionSet); |
| 57 | 59 | $this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers); |
| 58 | 60 | |
| 59 | - foreach ($this->modules as $module) $module->load($this->config); |
|
| 61 | + foreach ($this->modules as $module) { |
|
| 62 | + $module->load($this->config); |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | $this->processRules($template, $this->config); |
| 62 | 66 | |
@@ -70,7 +74,9 @@ discard block |
||
| 70 | 74 | $rules = $this->getRules($template, $config); |
| 71 | 75 | |
| 72 | 76 | foreach ($rules as $rule) { |
| 73 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
| 77 | + if ($rule->shouldRun($this->time)) { |
|
| 78 | + $this->executeTssRule($rule, $template, $config); |
|
| 79 | + } |
|
| 74 | 80 | } |
| 75 | 81 | } |
| 76 | 82 | |
@@ -93,7 +99,9 @@ discard block |
||
| 93 | 99 | //Load a template, firstly check if it's a file or a valid string |
| 94 | 100 | private function loadTemplate() { |
| 95 | 101 | $result = ['body' => $this->template, 'headers' => []]; |
| 96 | - if (file_exists($this->template)) $result = $this->loadTemplateFromFile($this->template); |
|
| 102 | + if (file_exists($this->template)) { |
|
| 103 | + $result = $this->loadTemplateFromFile($this->template); |
|
| 104 | + } |
|
| 97 | 105 | return $result; |
| 98 | 106 | } |
| 99 | 107 | |
@@ -119,6 +127,8 @@ discard block |
||
| 119 | 127 | |
| 120 | 128 | public function __destruct() { |
| 121 | 129 | //Required hack as DomXPath can only register static functions clear, the statically stored instance to avoid memory leaks |
| 122 | - if (isset($this->config)) $this->config->getCssToXpath()->cleanup(); |
|
| 130 | + if (isset($this->config)) { |
|
| 131 | + $this->config->getCssToXpath()->cleanup(); |
|
| 132 | + } |
|
| 123 | 133 | } |
| 124 | 134 | } |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function setLocale($locale) { |
| 44 | - $format = new \Transphporm\Module\Format($locale); |
|
| 45 | - $this->modules[get_class($format)] = $format; |
|
| 46 | - } |
|
| 44 | + $format = new \Transphporm\Module\Format($locale); |
|
| 45 | + $this->modules[get_class($format)] = $format; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | public function addPath($dir) { |
| 49 | 49 | $this->filePath->addPath($dir); |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | //Load a template, firstly check if it's a file or a valid string |
| 99 | 99 | private function loadTemplate() { |
| 100 | - $result = ['body' => $this->template, 'headers' => []]; |
|
| 100 | + $result = ['body' => $this->template, 'headers' => []]; |
|
| 101 | 101 | if (file_exists($this->template)) $result = $this->loadTemplateFromFile($this->template); |
| 102 | 102 | return $result; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - private function loadTemplateFromFile($file) { |
|
| 106 | - $xml = $this->cache->load($this->template, filemtime($this->template)); |
|
| 107 | - return $xml ? $xml : ['body' => file_get_contents($this->template) ?: "", 'headers' => []]; |
|
| 108 | - } |
|
| 105 | + private function loadTemplateFromFile($file) { |
|
| 106 | + $xml = $this->cache->load($this->template, filemtime($this->template)); |
|
| 107 | + return $xml ? $xml : ['body' => file_get_contents($this->template) ?: "", 'headers' => []]; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | //Load the TSS rules either from a file or as a string |
| 111 | 111 | //N.b. only files can be cached |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | const FORMATTER = 'formatter'; |
| 8 | 8 | |
| 9 | 9 | public function __construct(RunException $runException, $file, $line) { |
| 10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 10 | + $message = $runException->getMessage().' on Line '.$line.' of '.($file === null ? 'tss' : $file); |
|
| 11 | 11 | |
| 12 | 12 | parent::__construct($message, 0, $runException->getPrevious()); |
| 13 | 13 | } |
@@ -6,14 +6,14 @@ |
||
| 6 | 6 | * @version 1.2 */ |
| 7 | 7 | namespace Transphporm; |
| 8 | 8 | class Exception extends \Exception { |
| 9 | - const PROPERTY = 'property'; |
|
| 10 | - const TSS_FUNCTION = 'function'; |
|
| 11 | - const PSEUDO = 'pseudo'; |
|
| 12 | - const FORMATTER = 'formatter'; |
|
| 9 | + const PROPERTY = 'property'; |
|
| 10 | + const TSS_FUNCTION = 'function'; |
|
| 11 | + const PSEUDO = 'pseudo'; |
|
| 12 | + const FORMATTER = 'formatter'; |
|
| 13 | 13 | |
| 14 | - public function __construct(RunException $runException, $file, $line) { |
|
| 15 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 14 | + public function __construct(RunException $runException, $file, $line) { |
|
| 15 | + $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 16 | 16 | |
| 17 | - parent::__construct($message, 0, $runException->getPrevious()); |
|
| 18 | - } |
|
| 17 | + parent::__construct($message, 0, $runException->getPrevious()); |
|
| 18 | + } |
|
| 19 | 19 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | private function getCacheKey($file) { |
| 28 | - return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
|
| 28 | + return $file.$this->prefix.dirname(realpath($file)).DIRECTORY_SEPARATOR; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function load($tss) { |
@@ -18,7 +18,9 @@ discard block |
||
| 18 | 18 | $rules = $this->cache->load($key, filemtime($file)); |
| 19 | 19 | if ($rules) { |
| 20 | 20 | foreach ($rules['import'] as $file) { |
| 21 | - if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false; |
|
| 21 | + if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 22 | 24 | } |
| 23 | 25 | } |
| 24 | 26 | return $rules; |
@@ -33,7 +35,9 @@ discard block |
||
| 33 | 35 | } |
| 34 | 36 | |
| 35 | 37 | public function write($file, $rules, $imports = []) { |
| 36 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 38 | + if (is_file($file)) { |
|
| 39 | + $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 40 | + } |
|
| 37 | 41 | return $rules; |
| 38 | 42 | } |
| 39 | 43 | } |
@@ -6,13 +6,13 @@ discard block |
||
| 6 | 6 | * @version 1.2 */ |
| 7 | 7 | namespace Transphporm; |
| 8 | 8 | class TSSCache { |
| 9 | - private $cache; |
|
| 10 | - private $prefix; |
|
| 9 | + private $cache; |
|
| 10 | + private $prefix; |
|
| 11 | 11 | |
| 12 | - public function __construct(Cache $cache, $prefix) { |
|
| 13 | - $this->cache = $cache; |
|
| 14 | - $this->prefix = $prefix; |
|
| 15 | - } |
|
| 12 | + public function __construct(Cache $cache, $prefix) { |
|
| 13 | + $this->cache = $cache; |
|
| 14 | + $this->prefix = $prefix; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | 17 | private function getRulesFromCache($file) { |
| 18 | 18 | //The cache for the key: the filename and template prefix |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - public function load($tss) { |
|
| 37 | - return $this->getRulesFromCache($tss); |
|
| 38 | - } |
|
| 36 | + public function load($tss) { |
|
| 37 | + return $this->getRulesFromCache($tss); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function write($file, $rules, $imports = []) { |
|
| 41 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 42 | - return $rules; |
|
| 43 | - } |
|
| 40 | + public function write($file, $rules, $imports = []) { |
|
| 41 | + if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
| 42 | + return $rules; |
|
| 43 | + } |
|
| 44 | 44 | } |