@@ -19,8 +19,9 @@ |
||
19 | 19 | public function __call($name, $args) { |
20 | 20 | if (isset($this->functions[$name])) { |
21 | 21 | return $this->functions[$name]->run($args[0], $args[1]); |
22 | + } else { |
|
23 | + return \Transphporm\Parser\Value::IS_NOT_FUNCTION; |
|
22 | 24 | } |
23 | - else return \Transphporm\Parser\Value::IS_NOT_FUNCTION; |
|
24 | 25 | } |
25 | 26 | |
26 | 27 | public function addFunction($name, \Transphporm\TSSFunction $function) { |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | /** Binds data to an element */ |
19 | 19 | public function bind(\DomNode $element, $data, $type = 'data') { |
20 | 20 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
21 | - if (is_array($data) && $this->isObjectArray($data)) $data = $data[0]; |
|
21 | + if (is_array($data) && $this->isObjectArray($data)) { |
|
22 | + $data = $data[0]; |
|
23 | + } |
|
22 | 24 | $content = isset($this->elementMap[$element]) ? $this->elementMap[$element] : []; |
23 | 25 | $content[$type] = $data; |
24 | 26 | $this->elementMap[$element] = $content; |
@@ -31,7 +33,9 @@ discard block |
||
31 | 33 | /** 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 | 34 | public function getData(\DomElement $element = null, $type = 'data') { |
33 | 35 | while ($element) { |
34 | - if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) return $this->elementMap[$element][$type]; |
|
36 | + if (isset($this->elementMap[$element]) && isset($this->elementMap[$element][$type])) { |
|
37 | + return $this->elementMap[$element][$type]; |
|
38 | + } |
|
35 | 39 | $element = $element->parentNode; |
36 | 40 | } |
37 | 41 | return $this->data; |
@@ -6,12 +6,12 @@ |
||
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 $dataType; |
12 | 12 | private $functionSet; |
13 | 13 | |
14 | - public function __construct(\Transphporm\Hook\ElementData $data, \Transphporm\FunctionSet $functionSet, $dataKey = 'data') { |
|
14 | + public function __construct(\Transphporm\Hook\ElementData $data, \Transphporm\FunctionSet $functionSet, $dataKey = 'data') { |
|
15 | 15 | $this->data = $data; |
16 | 16 | $this->dataKey = $dataKey; |
17 | 17 | $this->functionSet = $functionSet; |
@@ -25,14 +25,18 @@ discard block |
||
25 | 25 | $valueParser = new \Transphporm\Parser\Value($this->functionSet); |
26 | 26 | |
27 | 27 | foreach ($parts as $part) { |
28 | - if ($part === '') continue; |
|
28 | + if ($part === '') { |
|
29 | + continue; |
|
30 | + } |
|
29 | 31 | $part = $valueParser->parse($part, $element)[0]; |
30 | 32 | |
31 | 33 | $funcResult = $this->traverseObj($part, $obj, $valueParser, $element); |
32 | 34 | |
33 | - if ($funcResult !== false) $obj = $funcResult; |
|
34 | - |
|
35 | - else $obj = $this->ifNull($obj, $part); |
|
35 | + if ($funcResult !== false) { |
|
36 | + $obj = $funcResult; |
|
37 | + } else { |
|
38 | + $obj = $this->ifNull($obj, $part); |
|
39 | + } |
|
36 | 40 | } |
37 | 41 | return $obj; |
38 | 42 | } |
@@ -41,14 +45,19 @@ discard block |
||
41 | 45 | if (strpos($part, '(') !== false) { |
42 | 46 | $subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false); |
43 | 47 | return $subObjParser->parse($part, $element)[0]; |
48 | + } else if (method_exists($obj, $part)) { |
|
49 | + return call_user_func([$obj, $part]); |
|
50 | + } else { |
|
51 | + return false; |
|
44 | 52 | } |
45 | - else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); |
|
46 | - else return false; |
|
47 | 53 | } |
48 | 54 | |
49 | 55 | private function ifNull($obj, $key) { |
50 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
51 | - else return isset($obj->$key) ? $obj->$key : null; |
|
56 | + if (is_array($obj)) { |
|
57 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
58 | + } else { |
|
59 | + return isset($obj->$key) ? $obj->$key : null; |
|
60 | + } |
|
52 | 61 | } |
53 | 62 | |
54 | 63 |
@@ -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][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][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 |
@@ -15,11 +15,15 @@ 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 | foreach ($values[0] as $key => $iteration) { |
22 | - if ($count+1 > $max) break; |
|
24 | + if ($count+1 > $max) { |
|
25 | + break; |
|
26 | + } |
|
23 | 27 | $clone = $this->cloneElement($element, $iteration, $key, $count++); |
24 | 28 | //Re-run the hook on the new element, but use the iterated data |
25 | 29 | //Don't run repeat on the clones element or it will loop forever |
@@ -43,7 +47,9 @@ discard block |
||
43 | 47 | |
44 | 48 | private function tagElement($element, $count) { |
45 | 49 | //Mark all but one of the nodes as having been added by transphporm, when the hook is run again, these are removed |
46 | - if ($count > 0) $element->setAttribute('transphporm', 'added'); |
|
50 | + if ($count > 0) { |
|
51 | + $element->setAttribute('transphporm', 'added'); |
|
52 | + } |
|
47 | 53 | } |
48 | 54 | |
49 | 55 | private function getMax($values) { |
@@ -52,7 +58,9 @@ discard block |
||
52 | 58 | |
53 | 59 | private function createHook($newRules, $pseudoMatcher, $properties) { |
54 | 60 | $hook = new \Transphporm\Hook\PropertyHook($newRules, $pseudoMatcher, new \Transphporm\Parser\Value($this->functionSet)); |
55 | - foreach ($properties as $name => $property) $hook->registerProperty($name, $property); |
|
61 | + foreach ($properties as $name => $property) { |
|
62 | + $hook->registerProperty($name, $property); |
|
63 | + } |
|
56 | 64 | return $hook; |
57 | 65 | } |
58 | 66 | } |
59 | 67 | \ No newline at end of file |
@@ -26,7 +26,9 @@ discard block |
||
26 | 26 | $newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss); |
27 | 27 | |
28 | 28 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
29 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
29 | + if ($selector != '') { |
|
30 | + return $this->templateSubsection($doc, $selector); |
|
31 | + } |
|
30 | 32 | |
31 | 33 | $newNode = $doc->documentElement; |
32 | 34 | $result = []; |
@@ -53,7 +55,9 @@ discard block |
||
53 | 55 | |
54 | 56 | private function getClonedElement($node, $tss) { |
55 | 57 | $clone = $node->cloneNode(true); |
56 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
58 | + if ($tss != null && $clone instanceof \DomElement) { |
|
59 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
60 | + } |
|
57 | 61 | return $clone; |
58 | 62 | } |
59 | 63 | } |
60 | 64 | \ No newline at end of file |
@@ -22,7 +22,7 @@ |
||
22 | 22 | public function run(array $args, \DomElement $element) { |
23 | 23 | $selector = $this->readArray($args, 1); |
24 | 24 | $tss = $this->readArray($args, 2); |
25 | - $newTemplate = new \Transphporm\Builder($this->baseDir . $args[0], $tss ? $this->baseDir . $tss : null); |
|
25 | + $newTemplate = new \Transphporm\Builder($this->baseDir.$args[0], $tss ? $this->baseDir.$tss : null); |
|
26 | 26 | |
27 | 27 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
28 | 28 | if ($selector != '') return $this->templateSubsection($doc, $selector); |
@@ -18,6 +18,9 @@ |
||
18 | 18 | return ucwords($val); |
19 | 19 | } |
20 | 20 | |
21 | + /** |
|
22 | + * @param string $val |
|
23 | + */ |
|
21 | 24 | public function html($val) { |
22 | 25 | $doc = new \DomDocument(); |
23 | 26 | $doc->loadXML($val); |
@@ -27,6 +27,6 @@ |
||
27 | 27 | public function debug($val) { |
28 | 28 | ob_start(); |
29 | 29 | var_dump($val); |
30 | - return $this->html('<pre>' . ob_get_clean() . '</pre>'); |
|
30 | + return $this->html('<pre>'.ob_get_clean().'</pre>'); |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -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); |
|
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 | 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 | - 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 | } |
@@ -14,10 +14,14 @@ discard block |
||
14 | 14 | |
15 | 15 | public function match($pseudo, \DomElement $element) { |
16 | 16 | $pos = strpos($pseudo, '['); |
17 | - if ($pos === false) return true; |
|
17 | + if ($pos === false) { |
|
18 | + return true; |
|
19 | + } |
|
18 | 20 | |
19 | 21 | $name = substr($pseudo, 0, $pos); |
20 | - if (!is_callable([$this->functionSet, $name])) return true; |
|
22 | + if (!is_callable([$this->functionSet, $name])) { |
|
23 | + return true; |
|
24 | + } |
|
21 | 25 | |
22 | 26 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($pseudo); |
23 | 27 | $criteria = $bracketMatcher->match('[', ']'); |
@@ -42,16 +46,21 @@ discard block |
||
42 | 46 | |
43 | 47 | private function parseValue($value, $element) { |
44 | 48 | $valueParser = new \Transphporm\Parser\Value($this->functionSet); |
45 | - if ($value == 'true') return true; |
|
46 | - else if ($value == 'false') return false; |
|
47 | - else return $valueParser->parse($value, $element)[0]; |
|
49 | + if ($value == 'true') { |
|
50 | + return true; |
|
51 | + } else if ($value == 'false') { |
|
52 | + return false; |
|
53 | + } else { |
|
54 | + return $valueParser->parse($value, $element)[0]; |
|
55 | + } |
|
48 | 56 | } |
49 | 57 | |
50 | 58 | private function getOperator($field) { |
51 | 59 | if ($field[strlen($field)-1] == '!') { |
52 | 60 | return '!'; |
61 | + } else { |
|
62 | + return ''; |
|
53 | 63 | } |
54 | - else return ''; |
|
55 | 64 | } |
56 | 65 | |
57 | 66 | } |