@@ -31,7 +31,9 @@ |
||
31 | 31 | /** Returns the data that has been bound to $element, or, if no data is bound to $element climb the DOM tree to find the data bound to a parent node*/ |
32 | 32 | public function getData(\DomElement $element = null, $type = 'data') { |
33 | 33 | while ($element) { |
34 | - if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type]; |
|
34 | + if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) { |
|
35 | + return $this->elementMap[$element][$type]; |
|
36 | + } |
|
35 | 37 | $element = $element->parentNode; |
36 | 38 | } |
37 | 39 | return $this->data; |
@@ -105,7 +105,7 @@ |
||
105 | 105 | $string = $this->extractString($i); |
106 | 106 | $length = strlen($string)+1; |
107 | 107 | $char = $this->getChar($char); |
108 | - $string = str_replace('\\' . $char, $char, $string); |
|
108 | + $string = str_replace('\\'.$char, $char, $string); |
|
109 | 109 | $tokens[] = ['type' => self::STRING, 'value' => $string]; |
110 | 110 | return $length; |
111 | 111 | } |
@@ -76,10 +76,15 @@ discard block |
||
76 | 76 | $name .= $this->str[$i+1]; |
77 | 77 | $i++; |
78 | 78 | } |
79 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
80 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
81 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
82 | - else $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
79 | + if (is_numeric($name)) { |
|
80 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
81 | + } else if ($name == 'true') { |
|
82 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
83 | + } else if ($name == 'false') { |
|
84 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
85 | + } else { |
|
86 | + $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
87 | + } |
|
83 | 88 | } |
84 | 89 | } |
85 | 90 | |
@@ -114,7 +119,9 @@ discard block |
||
114 | 119 | private function extractString($pos) { |
115 | 120 | $char = $this->str[$pos]; |
116 | 121 | $end = strpos($this->str, $char, $pos+1); |
117 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
122 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
123 | + $end = strpos($this->str, $char, $end+1); |
|
124 | + } |
|
118 | 125 | |
119 | 126 | return substr($this->str, $pos+1, $end-$pos-1); |
120 | 127 | } |
@@ -123,18 +130,26 @@ discard block |
||
123 | 130 | $close = strpos($this->str, $closeBracket, $open); |
124 | 131 | |
125 | 132 | $cPos = $open+1; |
126 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
133 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
134 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
135 | + } |
|
127 | 136 | return substr($this->str, $open+1, $close-$open-1); |
128 | 137 | } |
129 | 138 | |
130 | 139 | private function identifyChar($chr) { |
131 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
132 | - else return self::NAME; |
|
140 | + if (isset($this->chars[$chr])) { |
|
141 | + return $this->chars[$chr]; |
|
142 | + } else { |
|
143 | + return self::NAME; |
|
144 | + } |
|
133 | 145 | } |
134 | 146 | |
135 | 147 | private function getChar($num) { |
136 | 148 | $chars = array_reverse($this->chars); |
137 | - if (isset($chars[$num])) return $chars[$num]; |
|
138 | - else return false; |
|
149 | + if (isset($chars[$num])) { |
|
150 | + return $chars[$num]; |
|
151 | + } else { |
|
152 | + return false; |
|
153 | + } |
|
139 | 154 | } |
140 | 155 | } |
@@ -15,13 +15,19 @@ discard block |
||
15 | 15 | } |
16 | 16 | |
17 | 17 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
18 | - if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element); |
|
18 | + if ($element->getAttribute('transphporm') === 'added') { |
|
19 | + return $element->parentNode->removeChild($element); |
|
20 | + } |
|
19 | 21 | $max = $this->getMax($values); |
20 | 22 | $count = 0; |
21 | 23 | |
22 | - if (empty($values[0])) $values[0] = []; |
|
24 | + if (empty($values[0])) { |
|
25 | + $values[0] = []; |
|
26 | + } |
|
23 | 27 | foreach ($values[0] as $key => $iteration) { |
24 | - if ($count+1 > $max) break; |
|
28 | + if ($count+1 > $max) { |
|
29 | + break; |
|
30 | + } |
|
25 | 31 | $clone = $this->cloneElement($element, $iteration, $key, $count++); |
26 | 32 | //Re-run the hook on the new element, but use the iterated data |
27 | 33 | //Don't run repeat on the clones element or it will loop forever |
@@ -45,7 +51,9 @@ discard block |
||
45 | 51 | |
46 | 52 | private function tagElement($element, $count) { |
47 | 53 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
48 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
54 | + if ($count > 0) { |
|
55 | + $element->setAttribute('transphporm', 'added'); |
|
56 | + } |
|
49 | 57 | } |
50 | 58 | |
51 | 59 | private function getMax($values) { |
@@ -54,7 +62,9 @@ discard block |
||
54 | 62 | |
55 | 63 | private function createHook($newRules, $pseudoMatcher, $properties) { |
56 | 64 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet)); |
57 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
65 | + foreach ($properties as $name => $property) { |
|
66 | + $hook->registerProperty($name, $property); |
|
67 | + } |
|
58 | 68 | return $hook; |
59 | 69 | } |
60 | 70 | } |
@@ -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')); |
|
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')); |
|
12 | + } else if (strtolower($values[0]) === 'none') { |
|
13 | + $element->setAttribute('transphporm', 'remove'); |
|
14 | + } else { |
|
15 | + $element->setAttribute('transphporm', 'show'); |
|
16 | + } |
|
13 | 17 | } |
14 | 18 | } |
15 | 19 | \ No newline at end of file |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | $valueParser = new \Transphporm\Parser\Value($this->functionSet); |
27 | 27 | |
28 | - $criteria = $name . '(' . $criteria; |
|
28 | + $criteria = $name.'('.$criteria; |
|
29 | 29 | |
30 | 30 | $pos = strpos($pseudo, '!'); |
31 | 31 | if ($pos === false) $pos = strpos($pseudo, '='); |
@@ -15,10 +15,14 @@ discard block |
||
15 | 15 | public function match($pseudo, \DomElement $element) { |
16 | 16 | |
17 | 17 | $pos = strpos($pseudo, '['); |
18 | - if ($pos === false) return true; |
|
18 | + if ($pos === false) { |
|
19 | + return true; |
|
20 | + } |
|
19 | 21 | |
20 | 22 | $name = substr($pseudo, 0, $pos); |
21 | - if (!$this->functionSet->hasFunction($name)) return true; |
|
23 | + if (!$this->functionSet->hasFunction($name)) { |
|
24 | + return true; |
|
25 | + } |
|
22 | 26 | |
23 | 27 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); |
24 | 28 | $criteria = $bracketMatcher->match('[', ']'); |
@@ -28,11 +32,14 @@ discard block |
||
28 | 32 | $criteria = $name . '(' . $criteria; |
29 | 33 | |
30 | 34 | $pos = strpos($pseudo, '!'); |
31 | - if ($pos === false) $pos = strpos($pseudo, '='); |
|
35 | + if ($pos === false) { |
|
36 | + $pos = strpos($pseudo, '='); |
|
37 | + } |
|
32 | 38 | if ($pos === false) { |
33 | 39 | $criteria .= ')=true'; |
40 | + } else { |
|
41 | + $criteria = substr_replace($criteria, ')', $pos, 0); |
|
34 | 42 | } |
35 | - else $criteria = substr_replace($criteria, ')', $pos, 0); |
|
36 | 43 | |
37 | 44 | return $valueParser->parse($criteria, $element)[0]; |
38 | 45 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\TSSFunction; |
8 | 8 | /* Handles data() and iteration() function calls from the stylesheet */ |
9 | -class Data implements \Transphporm\TSSFunction{ |
|
9 | +class Data implements \Transphporm\TSSFunction { |
|
10 | 10 | private $data; |
11 | 11 | private $dataKey; |
12 | 12 | private $functionSet; |
@@ -18,8 +18,11 @@ |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run(array $args, \DomElement $element = null) { |
21 | - if ($this->dataKey === "root") $data = $this->data->getData(null, 'data'); |
|
22 | - else $data = $this->data->getData($element, $this->dataKey); |
|
21 | + if ($this->dataKey === "root") { |
|
22 | + $data = $this->data->getData(null, 'data'); |
|
23 | + } else { |
|
24 | + $data = $this->data->getData($element, $this->dataKey); |
|
25 | + } |
|
23 | 26 | $parser = new \Transphporm\Parser\Value($this->functionSet, true); |
24 | 27 | $return = $parser->parseTokens($args, $data); |
25 | 28 | return $return[0]; |
@@ -1,25 +1,25 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\TSSFunction; |
3 | 3 | class Json implements \Transphporm\TSSFunction { |
4 | - private $baseDir; |
|
4 | + private $baseDir; |
|
5 | 5 | |
6 | - public function __construct(&$baseDir) { |
|
7 | - $this->baseDir = &$baseDir; |
|
8 | - } |
|
6 | + public function __construct(&$baseDir) { |
|
7 | + $this->baseDir = &$baseDir; |
|
8 | + } |
|
9 | 9 | |
10 | - public function run(array $args, \DomElement $element = null) { |
|
11 | - $json = $args[0]; |
|
10 | + public function run(array $args, \DomElement $element = null) { |
|
11 | + $json = $args[0]; |
|
12 | 12 | |
13 | - if (trim($json)[0] != '{') { |
|
14 | - $path = $this->baseDir . $json; |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | - $json = file_get_contents($json); |
|
17 | - } |
|
13 | + if (trim($json)[0] != '{') { |
|
14 | + $path = $this->baseDir . $json; |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | + $json = file_get_contents($json); |
|
17 | + } |
|
18 | 18 | |
19 | - $map = json_decode($json, true); |
|
19 | + $map = json_decode($json, true); |
|
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
22 | 22 | |
23 | - return $map; |
|
24 | - } |
|
23 | + return $map; |
|
24 | + } |
|
25 | 25 | } |
@@ -11,14 +11,14 @@ |
||
11 | 11 | $json = $args[0]; |
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | - $path = $this->baseDir . $json; |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
14 | + $path = $this->baseDir.$json; |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
16 | 16 | $json = file_get_contents($json); |
17 | 17 | } |
18 | 18 | |
19 | 19 | $map = json_decode($json, true); |
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
22 | 22 | |
23 | 23 | return $map; |
24 | 24 | } |
@@ -12,13 +12,17 @@ |
||
12 | 12 | |
13 | 13 | if (trim($json)[0] != '{') { |
14 | 14 | $path = $this->baseDir . $json; |
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
15 | + if (!file_exists($path)) { |
|
16 | + throw new \Exception('File does not exist at: ' . $path); |
|
17 | + } |
|
16 | 18 | $json = file_get_contents($json); |
17 | 19 | } |
18 | 20 | |
19 | 21 | $map = json_decode($json, true); |
20 | 22 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
23 | + if (!is_array($map)) { |
|
24 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
25 | + } |
|
22 | 26 | |
23 | 27 | return $map; |
24 | 28 | } |
@@ -155,6 +155,10 @@ |
||
155 | 155 | |
156 | 156 | //Extracts $last from $data. If "last" is "bar" from value "foo.bar", |
157 | 157 | //$data contains "foo" and this function reads $data[$bar] or $data->$bar |
158 | + |
|
159 | + /** |
|
160 | + * @param ValueResult|null $result |
|
161 | + */ |
|
158 | 162 | private function extractLast($result) { |
159 | 163 | if ($this->autoLookup && isset($this->data->{$this->last})) { |
160 | 164 | return $this->result->processValue($this->data->{$this->last}); |
@@ -51,7 +51,9 @@ discard block |
||
51 | 51 | $this->data = $data; |
52 | 52 | $this->last = null; |
53 | 53 | |
54 | - if (empty($tokens)) return [$this->data]; |
|
54 | + if (empty($tokens)) { |
|
55 | + return [$this->data]; |
|
56 | + } |
|
55 | 57 | |
56 | 58 | foreach ($tokens as $token) { |
57 | 59 | $this->{$this->tokenFuncs[$token['type']]}($token); |
@@ -66,27 +68,36 @@ discard block |
||
66 | 68 | |
67 | 69 | if ($this->result->getMode() == Tokenizer::NOT && $token['type'] == Tokenizer::EQUALS) { |
68 | 70 | $this->result->setMode(Tokenizer::NOT); |
71 | + } else { |
|
72 | + $this->result->setMode($token['type']); |
|
69 | 73 | } |
70 | - else $this->result->setMode($token['type']); |
|
71 | 74 | } |
72 | 75 | |
73 | 76 | |
74 | 77 | //Reads the last selected value from $data regardless if it's an array or object and overrides $this->data with the new value |
75 | 78 | private function moveLastToData() { |
76 | - if (isset($this->data->{$this->last})) $this->data = $this->data->{$this->last}; |
|
77 | - else if (is_array($this->data) && isset($this->data[$this->last])) $this->data = $this->data[$this->last]; |
|
79 | + if (isset($this->data->{$this->last})) { |
|
80 | + $this->data = $this->data->{$this->last}; |
|
81 | + } else if (is_array($this->data) && isset($this->data[$this->last])) { |
|
82 | + $this->data = $this->data[$this->last]; |
|
83 | + } |
|
78 | 84 | } |
79 | 85 | |
80 | 86 | //Dot moves $data to the next object in $data foo.bar moves the $data pointer from `foo` to `bar` |
81 | 87 | private function processDot($token) { |
82 | - if ($this->last !== null) $this->moveLastToData(); |
|
83 | - else $this->data = $this->result->pop(); |
|
88 | + if ($this->last !== null) { |
|
89 | + $this->moveLastToData(); |
|
90 | + } else { |
|
91 | + $this->data = $this->result->pop(); |
|
92 | + } |
|
84 | 93 | |
85 | 94 | $this->last = null; |
86 | 95 | } |
87 | 96 | |
88 | 97 | private function processSquareBracket($token) { |
89 | - if ($this->last !== null) $this->moveLastToData(); |
|
98 | + if ($this->last !== null) { |
|
99 | + $this->moveLastToData(); |
|
100 | + } |
|
90 | 101 | $parser = new Value($this->baseData, $this->autoLookup); |
91 | 102 | $this->last = $parser->parseTokens($token['value'], null)[0]; |
92 | 103 | } |
@@ -108,15 +119,15 @@ discard block |
||
108 | 119 | private function processBrackets($token) { |
109 | 120 | if ($this->baseData instanceof \Transphporm\Functionset && $this->baseData->hasFunction($this->last)) { |
110 | 121 | $this->callTransphpormFunctions($token); |
111 | - } |
|
112 | - else if ($this->data instanceof \Transphporm\Functionset) { |
|
122 | + } else if ($this->data instanceof \Transphporm\Functionset) { |
|
113 | 123 | $this->result = $this->result->processValue($this->data->{$this->last}($token['value'])); |
114 | 124 | $this->last = null; |
115 | - } |
|
116 | - else { |
|
125 | + } else { |
|
117 | 126 | $parser = new Value($this->baseData, $this->autoLookup); |
118 | 127 | $args = $parser->parseTokens($token['value'], $this->data); |
119 | - if ($args[0] == $this->data) $args = []; |
|
128 | + if ($args[0] == $this->data) { |
|
129 | + $args = []; |
|
130 | + } |
|
120 | 131 | $funcResult = $this->callFunc($this->last, $args, $this->data); |
121 | 132 | $this->result->processValue($funcResult); |
122 | 133 | $this->last = null; |
@@ -127,9 +138,12 @@ discard block |
||
127 | 138 | $this->result->processValue($this->baseData->{$this->last}($token['value'])); |
128 | 139 | foreach ($this->result->getResult() as $i => $value) { |
129 | 140 | if (is_array($this->data)) { |
130 | - if (isset($this->data[$value])) $this->result[$i] = $this->data[$value]; |
|
141 | + if (isset($this->data[$value])) { |
|
142 | + $this->result[$i] = $this->data[$value]; |
|
143 | + } |
|
144 | + } else if (is_scalar($value) && isset($this->data->$value)) { |
|
145 | + $this->result[$i] = $this->data->$value; |
|
131 | 146 | } |
132 | - else if (is_scalar($value) && isset($this->data->$value)) $this->result[$i] = $this->data->$value; |
|
133 | 147 | } |
134 | 148 | $this->last = null; |
135 | 149 | } |
@@ -139,12 +153,10 @@ discard block |
||
139 | 153 | if ($this->last !== null) { |
140 | 154 | try { |
141 | 155 | $this->extractLast($this->result); |
142 | - } |
|
143 | - catch (\UnexpectedValueException $e) { |
|
156 | + } catch (\UnexpectedValueException $e) { |
|
144 | 157 | if (!$this->autoLookup) { |
145 | 158 | $this->result->processValue($this->last); |
146 | - } |
|
147 | - else { |
|
159 | + } else { |
|
148 | 160 | $this->result->clear(); |
149 | 161 | $this->result[0] = false; |
150 | 162 | } |
@@ -158,8 +170,7 @@ discard block |
||
158 | 170 | private function extractLast($result) { |
159 | 171 | if ($this->autoLookup && isset($this->data->{$this->last})) { |
160 | 172 | return $this->result->processValue($this->data->{$this->last}); |
161 | - } |
|
162 | - else if (is_array($this->data) && isset($this->data[$this->last])) { |
|
173 | + } else if (is_array($this->data) && isset($this->data[$this->last])) { |
|
163 | 174 | return $this->result->processValue($this->data[$this->last]); |
164 | 175 | } |
165 | 176 | throw new \UnexpectedValueException('Not found'); |
@@ -170,7 +181,10 @@ discard block |
||
170 | 181 | } |
171 | 182 | |
172 | 183 | private function callFuncOnObject($obj, $func, $args) { |
173 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
174 | - else return call_user_func_array([$obj, $func], $args); |
|
184 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
185 | + return call_user_func_array($obj->$func, $args); |
|
186 | + } else { |
|
187 | + return call_user_func_array([$obj, $func], $args); |
|
188 | + } |
|
175 | 189 | } |
176 | 190 | } |
177 | 191 | \ No newline at end of file |
@@ -67,12 +67,16 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function loadProperties(Hook\PropertyHook $hook) { |
70 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
70 | + foreach ($this->properties as $name => $property) { |
|
71 | + $hook->registerProperty($name, $property); |
|
72 | + } |
|
71 | 73 | } |
72 | 74 | |
73 | 75 | public function createPseudoMatcher($pseudo) { |
74 | 76 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
75 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
|
77 | + foreach ($this->pseudo as $pseudoFunction) { |
|
78 | + $pseudoMatcher->registerFunction($pseudoFunction); |
|
79 | + } |
|
76 | 80 | return $pseudoMatcher; |
77 | 81 | } |
78 | 82 |