@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $cachedOutput = $this->loadTemplate(); |
| 51 | 51 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 52 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 52 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 53 | 53 | |
| 54 | 54 | $this->processRules($template, $data, $featureSet); |
| 55 | 55 | |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | //N.b. only files can be cached |
| 99 | 99 | private function getRules($template, $valueParser) { |
| 100 | 100 | if (is_file($this->tss)) { |
| 101 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
| 101 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
| 102 | 102 | //The cache for the key: the filename and template prefix |
| 103 | 103 | //Each template may have a different prefix which changes the parsed TSS, |
| 104 | 104 | //Because of this the cache needs to be generated for each template prefix. |
| 105 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
| 105 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
| 106 | 106 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 107 | 107 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 108 | 108 | if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
@@ -25,7 +25,9 @@ discard block |
||
| 25 | 25 | $this->cache = new Cache(new \ArrayObject()); |
| 26 | 26 | |
| 27 | 27 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
| 28 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
| 28 | + foreach ($modules as $module) { |
|
| 29 | + $this->loadModule(new $module); |
|
| 30 | + } |
|
| 29 | 31 | } |
| 30 | 32 | |
| 31 | 33 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -44,7 +46,9 @@ discard block |
||
| 44 | 46 | $data = new Hook\DataFunction(new \SplObjectStorage(), $data, $this->baseDir); |
| 45 | 47 | $featureSet = new FeatureSet($data, new Hook\Formatter(), $headers); |
| 46 | 48 | |
| 47 | - foreach ($this->modules as $module) $module->load($featureSet); |
|
| 49 | + foreach ($this->modules as $module) { |
|
| 50 | + $module->load($featureSet); |
|
| 51 | + } |
|
| 48 | 52 | //$locale = $this->getLocale(); |
| 49 | 53 | |
| 50 | 54 | $cachedOutput = $this->loadTemplate(); |
@@ -63,7 +67,9 @@ discard block |
||
| 63 | 67 | private function processRules($template, $data, $featureSet) { |
| 64 | 68 | $valueParser = new Parser\Value($data); |
| 65 | 69 | foreach ($this->getRules($template, $valueParser) as $rule) { |
| 66 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $valueParser, $featureSet); |
|
| 70 | + if ($rule->shouldRun($this->time)) { |
|
| 71 | + $this->executeTssRule($rule, $template, $valueParser, $featureSet); |
|
| 72 | + } |
|
| 67 | 73 | } |
| 68 | 74 | } |
| 69 | 75 | |
@@ -90,8 +96,9 @@ discard block |
||
| 90 | 96 | if (trim($this->template)[0] !== '<') { |
| 91 | 97 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 92 | 98 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 99 | + } else { |
|
| 100 | + return ['body' => $this->template, 'headers' => []]; |
|
| 93 | 101 | } |
| 94 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 95 | 102 | } |
| 96 | 103 | |
| 97 | 104 | //Load the TSS rules either from a file or as a string |
@@ -105,10 +112,14 @@ discard block |
||
| 105 | 112 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
| 106 | 113 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 107 | 114 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 108 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
| 109 | - else return $rules; |
|
| 115 | + if (!$rules) { |
|
| 116 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
| 117 | + } else { |
|
| 118 | + return $rules; |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
| 110 | 122 | } |
| 111 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
| 112 | 123 | } |
| 113 | 124 | |
| 114 | 125 | public function setCache(\ArrayAccess $cache) { |
@@ -35,12 +35,16 @@ |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function loadProperties(Hook\PropertyHook $hook) { |
| 38 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 38 | + foreach ($this->properties as $name => $property) { |
|
| 39 | + $hook->registerProperty($name, $property); |
|
| 40 | + } |
|
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | public function createPseudoMatcher($pseudo) { |
| 42 | 44 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
| 43 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
|
| 45 | + foreach ($this->pseudo as $pseudoFunction) { |
|
| 46 | + $pseudoMatcher->registerFunction($pseudoFunction); |
|
| 47 | + } |
|
| 44 | 48 | return $pseudoMatcher; |
| 45 | 49 | } |
| 46 | 50 | } |
| 47 | 51 | \ No newline at end of file |
@@ -14,8 +14,8 @@ |
||
| 14 | 14 | |
| 15 | 15 | private function getLocale() { |
| 16 | 16 | if (is_array($this->locale)) return $this->locale; |
| 17 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../' . $this->locale . '.json'), true); |
|
| 18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 17 | + else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../'.$this->locale.'.json'), true); |
|
| 18 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function load(\Transphporm\FeatureSet $featureSet) { |
@@ -13,9 +13,13 @@ |
||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | private function getLocale() { |
| 16 | - if (is_array($this->locale)) return $this->locale; |
|
| 17 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../' . $this->locale . '.json'), true); |
|
| 18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 16 | + if (is_array($this->locale)) { |
|
| 17 | + return $this->locale; |
|
| 18 | + } else if (strlen($this->locale) > 0) { |
|
| 19 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../' . $this->locale . '.json'), true); |
|
| 20 | + } else { |
|
| 21 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 22 | + } |
|
| 19 | 23 | } |
| 20 | 24 | |
| 21 | 25 | public function load(\Transphporm\FeatureSet $featureSet) { |
@@ -13,13 +13,17 @@ discard block |
||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 16 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
| 16 | + if ($element->getAttribute('transphporm') === 'added') { |
|
| 17 | + return $element->parentNode->removeChild($element); |
|
| 18 | + } |
|
| 17 | 19 | |
| 18 | 20 | $count = 0; |
| 19 | 21 | foreach ($value as $key => $iteration) { |
| 20 | 22 | $clone = $element->cloneNode(true); |
| 21 | 23 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
| 22 | - if ($count++ > 0) $clone->setAttribute('transphporm', 'added'); |
|
| 24 | + if ($count++ > 0) { |
|
| 25 | + $clone->setAttribute('transphporm', 'added'); |
|
| 26 | + } |
|
| 23 | 27 | $this->data->bind($clone, $iteration, 'iteration'); |
| 24 | 28 | $this->data->bind($clone, $key, 'key'); |
| 25 | 29 | $element->parentNode->insertBefore($clone, $element); |
@@ -36,7 +40,9 @@ discard block |
||
| 36 | 40 | |
| 37 | 41 | private function createHook($newRules, $pseudoMatcher, $properties) { |
| 38 | 42 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data)); |
| 39 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 43 | + foreach ($properties as $name => $property) { |
|
| 44 | + $hook->registerProperty($name, $property); |
|
| 45 | + } |
|
| 40 | 46 | return $hook; |
| 41 | 47 | } |
| 42 | 48 | } |
| 43 | 49 | \ No newline at end of file |
@@ -8,6 +8,9 @@ discard block |
||
| 8 | 8 | class Repeat implements \Transphporm\Property { |
| 9 | 9 | private $data; |
| 10 | 10 | |
| 11 | + /** |
|
| 12 | + * @param \Transphporm\Hook\DataFunction $data |
|
| 13 | + */ |
|
| 11 | 14 | public function __construct($data) { |
| 12 | 15 | $this->data = $data; |
| 13 | 16 | } |
@@ -34,6 +37,9 @@ discard block |
||
| 34 | 37 | return false; |
| 35 | 38 | } |
| 36 | 39 | |
| 40 | + /** |
|
| 41 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
| 42 | + */ |
|
| 37 | 43 | private function createHook($newRules, $pseudoMatcher, $properties) { |
| 38 | 44 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->data)); |
| 39 | 45 | foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |