@@ -30,7 +30,9 @@ |
||
| 30 | 30 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
| 31 | 31 | foreach ($xpath->query($xpathString) as $matchedElement) { |
| 32 | 32 | //Check to see whether this node was matched by the not query |
| 33 | - if ($element->isSameNode($matchedElement)) return false; |
|
| 33 | + if ($element->isSameNode($matchedElement)) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 34 | 36 | } |
| 35 | 37 | } |
| 36 | 38 | return true; |
@@ -14,6 +14,9 @@ discard block |
||
| 14 | 14 | return $this->data; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | + /** |
|
| 18 | + * @return Hook\Formatter |
|
| 19 | + */ |
|
| 17 | 20 | public function getFormatter() { |
| 18 | 21 | return $this->formatter; |
| 19 | 22 | } |
@@ -26,6 +29,9 @@ discard block |
||
| 26 | 29 | $this->formatter->register($formatter); |
| 27 | 30 | } |
| 28 | 31 | |
| 32 | + /** |
|
| 33 | + * @param string $name |
|
| 34 | + */ |
|
| 29 | 35 | public function registerProperty($name, Property $property) { |
| 30 | 36 | $this->properties[$name] = $property; |
| 31 | 37 | } |
@@ -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 |
@@ -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) { |
@@ -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) { |