@@ -12,6 +12,9 @@ discard block |
||
12 | 12 | private $prefix; |
13 | 13 | private $valueParser; |
14 | 14 | |
15 | + /** |
|
16 | + * @param string $tss |
|
17 | + */ |
|
15 | 18 | public function __construct($tss, $baseDir, Value $valueParser, $prefix = '') { |
16 | 19 | $this->tss = $this->stripComments($tss); |
17 | 20 | $this->baseDir = $baseDir; |
@@ -38,12 +41,20 @@ discard block |
||
38 | 41 | return $rules; |
39 | 42 | } |
40 | 43 | |
44 | + /** |
|
45 | + * @param string $selector |
|
46 | + * @param integer $index |
|
47 | + */ |
|
41 | 48 | private function CssToRule($selector, $index) { |
42 | 49 | $xPath = new CssToXpath($selector, $this->valueParser, $this->prefix); |
43 | 50 | $rule = new \Transphporm\Rule($xPath->getXpath(), $xPath->getPseudo(), $xPath->getDepth(), $index++); |
44 | 51 | return $rule; |
45 | 52 | } |
46 | 53 | |
54 | + /** |
|
55 | + * @param string $selector |
|
56 | + * @param \Transphporm\Rule $newRule |
|
57 | + */ |
|
47 | 58 | private function writeRule($rules, $selector, $newRule) { |
48 | 59 | if (isset($rules[$selector])) { |
49 | 60 | $newRule->properties = array_merge($rules[$selector]->properties, $newRule->properties); |
@@ -54,6 +65,10 @@ discard block |
||
54 | 65 | return $rules; |
55 | 66 | } |
56 | 67 | |
68 | + /** |
|
69 | + * @param integer $pos |
|
70 | + * @param integer $next |
|
71 | + */ |
|
57 | 72 | private function processingInstructions($tss, $pos, $next) { |
58 | 73 | $rules = []; |
59 | 74 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
@@ -94,6 +109,9 @@ discard block |
||
94 | 109 | return $str; |
95 | 110 | } |
96 | 111 | |
112 | + /** |
|
113 | + * @param string $str |
|
114 | + */ |
|
97 | 115 | private function getProperties($str) { |
98 | 116 | $stringExtractor = new StringExtractor($str); |
99 | 117 | $rules = explode(';', $stringExtractor); |
@@ -33,7 +33,9 @@ discard block |
||
33 | 33 | $rules = $this->writeRule($rules, $selector, $rule); |
34 | 34 | } |
35 | 35 | //there may be processing instructions at the end |
36 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) $rules = array_merge($processing['rules'], $rules); |
|
36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss))) { |
|
37 | + $rules = array_merge($processing['rules'], $rules); |
|
38 | + } |
|
37 | 39 | usort($rules, [$this, 'sortRules']); |
38 | 40 | return $rules; |
39 | 41 | } |
@@ -63,8 +65,7 @@ discard block |
||
63 | 65 | $pos = strpos($tss, ';', $spacePos); |
64 | 66 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
65 | 67 | $rules = array_merge($rules, $this->$funcName($args)); |
66 | - } |
|
67 | - else { |
|
68 | + } else { |
|
68 | 69 | break; |
69 | 70 | } |
70 | 71 | } |
@@ -79,7 +80,9 @@ discard block |
||
79 | 80 | |
80 | 81 | private function sortRules($a, $b) { |
81 | 82 | //If they have the same depth, compare on index |
82 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
83 | + if ($a->depth === $b->depth) { |
|
84 | + return $a->index < $b->index ? -1 : 1; |
|
85 | + } |
|
83 | 86 | |
84 | 87 | return ($a->depth < $b->depth) ? -1 : 1; |
85 | 88 | } |
@@ -100,7 +103,9 @@ discard block |
||
100 | 103 | $return = []; |
101 | 104 | |
102 | 105 | foreach ($rules as $rule) { |
103 | - if (trim($rule) === '') continue; |
|
106 | + if (trim($rule) === '') { |
|
107 | + continue; |
|
108 | + } |
|
104 | 109 | $parts = explode(':', $rule, 2); |
105 | 110 | |
106 | 111 | $parts[1] = $stringExtractor->rebuild($parts[1]); |
@@ -35,6 +35,9 @@ |
||
35 | 35 | return false; |
36 | 36 | } |
37 | 37 | |
38 | + /** |
|
39 | + * @param \Transphporm\Hook\PropertyHook $rule |
|
40 | + */ |
|
38 | 41 | private function createHook($newRules, $rule) { |
39 | 42 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $rule->getPseudoMatcher(), new \Transphporm\Parser\Value($this->data)); |
40 | 43 | foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property); |
@@ -12,7 +12,7 @@ |
||
12 | 12 | $this->data = $data; |
13 | 13 | } |
14 | 14 | |
15 | - public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
|
15 | + public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
|
16 | 16 | if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
17 | 17 | |
18 | 18 | foreach ($value as $key => $iteration) { |
@@ -20,7 +20,9 @@ |
||
20 | 20 | $formatter->register(new Formatter\Date($locale)); |
21 | 21 | $formatter->register(new Formatter\StringFormatter()); |
22 | 22 | |
23 | - foreach ($formatters as $format) $formatter->register($format); |
|
23 | + foreach ($formatters as $format) { |
|
24 | + $formatter->register($format); |
|
25 | + } |
|
24 | 26 | |
25 | 27 | $this->builder->registerProperty('content', new Property\Content($data, $headers, $formatter)); |
26 | 28 | $this->builder->registerProperty('repeat', new Property\Repeat($data)); |
@@ -52,7 +52,9 @@ discard block |
||
52 | 52 | private function processRules($template, $data) { |
53 | 53 | $valueParser = new Parser\Value($data); |
54 | 54 | foreach ($this->getRules($template, $valueParser) as $rule) { |
55 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data, $valueParser); |
|
55 | + if ($rule->shouldRun($this->time)) { |
|
56 | + $this->executeTssRule($rule, $template, $data, $valueParser); |
|
57 | + } |
|
56 | 58 | } |
57 | 59 | } |
58 | 60 | |
@@ -66,7 +68,9 @@ discard block |
||
66 | 68 | private function executeTssRule($rule, $template, $data, $valueParser) { |
67 | 69 | $rule->touch(); |
68 | 70 | $hook = new Hook\PropertyHook($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $valueParser); |
69 | - foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property); |
|
71 | + foreach ($this->registeredProperties as $name => $property) { |
|
72 | + $hook->registerProperty($name, $property); |
|
73 | + } |
|
70 | 74 | $template->addHook($rule->query, $hook); |
71 | 75 | } |
72 | 76 | |
@@ -75,8 +79,9 @@ discard block |
||
75 | 79 | if (trim($this->template)[0] !== '<') { |
76 | 80 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
77 | 81 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
82 | + } else { |
|
83 | + return ['body' => $this->template, 'headers' => []]; |
|
78 | 84 | } |
79 | - else return ['body' => $this->template, 'headers' => []]; |
|
80 | 85 | } |
81 | 86 | |
82 | 87 | //Load the TSS rules either from a file or as a string |
@@ -90,10 +95,14 @@ discard block |
||
90 | 95 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
91 | 96 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
92 | 97 | $rules = $this->cache->load($key, filemtime($this->tss)); |
93 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
94 | - else return $rules; |
|
98 | + if (!$rules) { |
|
99 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
100 | + } else { |
|
101 | + return $rules; |
|
102 | + } |
|
103 | + } else { |
|
104 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
95 | 105 | } |
96 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
97 | 106 | } |
98 | 107 | |
99 | 108 | public function setCache(\ArrayAccess $cache) { |
@@ -101,9 +110,13 @@ discard block |
||
101 | 110 | } |
102 | 111 | |
103 | 112 | private function getLocale() { |
104 | - if (is_array($this->locale)) return $this->locale; |
|
105 | - 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); |
|
106 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
113 | + if (is_array($this->locale)) { |
|
114 | + return $this->locale; |
|
115 | + } else if (strlen($this->locale) > 0) { |
|
116 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
117 | + } else { |
|
118 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
119 | + } |
|
107 | 120 | } |
108 | 121 | |
109 | 122 | public function registerProperty($name, Property $property) { |
@@ -18,15 +18,20 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
21 | - if ($element->getAttribute('transphporm') === 'remove') return; |
|
21 | + if ($element->getAttribute('transphporm') === 'remove') { |
|
22 | + return; |
|
23 | + } |
|
22 | 24 | |
23 | 25 | $value = $this->formatter->format($value, $rule->getRules()); |
24 | 26 | if (!$this->processPseudo($value, $element, $rule)) { |
25 | 27 | //Remove the current contents |
26 | 28 | $this->removeAllChildren($element); |
27 | 29 | //Now make a text node |
28 | - if ($this->getContentMode($rule->getRules()) === 'replace') $this->replaceContent($element, $value); |
|
29 | - else $this->appendContent($element, $value); |
|
30 | + if ($this->getContentMode($rule->getRules()) === 'replace') { |
|
31 | + $this->replaceContent($element, $value); |
|
32 | + } else { |
|
33 | + $this->appendContent($element, $value); |
|
34 | + } |
|
30 | 35 | } |
31 | 36 | } |
32 | 37 | |
@@ -92,6 +97,8 @@ discard block |
||
92 | 97 | } |
93 | 98 | |
94 | 99 | private function removeAllChildren($element) { |
95 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
100 | + while ($element->hasChildNodes()) { |
|
101 | + $element->removeChild($element->firstChild); |
|
102 | + } |
|
96 | 103 | } |
97 | 104 | } |
98 | 105 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
12 | 12 | $this->data = $data; |
13 | 13 | } |
14 | 14 | |
15 | - public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
|
15 | + public function run($value, \DomElement $element, \Transphporm\Hook\PropertyHook $rule) { |
|
16 | 16 | $this->data->bind($element, $value); |
17 | 17 | } |
18 | 18 | } |
19 | 19 | \ No newline at end of file |