@@ -11,6 +11,10 @@ |
||
11 | 11 | private $selector; |
12 | 12 | private $tss; |
13 | 13 | |
14 | + /** |
|
15 | + * @param string $xml |
|
16 | + * @param string $tss |
|
17 | + */ |
|
14 | 18 | public function __construct($xml, $selector = null, $tss = null) { |
15 | 19 | $this->xml = $xml; |
16 | 20 | $this->selector = $selector; |
@@ -34,7 +34,9 @@ discard block |
||
34 | 34 | |
35 | 35 | private function getClonedElement($node) { |
36 | 36 | $clone = $node->cloneNode(true); |
37 | - if ($this->tss !== null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
37 | + if ($this->tss !== null && $clone instanceof \DomElement) { |
|
38 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
39 | + } |
|
38 | 40 | return $clone; |
39 | 41 | } |
40 | 42 | |
@@ -42,7 +44,9 @@ discard block |
||
42 | 44 | $newTemplate = new \Transphporm\Builder($this->xml, $this->tss); |
43 | 45 | |
44 | 46 | $doc = $newTemplate->output($data, true)->body; |
45 | - if ($this->selector != '') return $this->templateSubsection($doc); |
|
47 | + if ($this->selector != '') { |
|
48 | + return $this->templateSubsection($doc); |
|
49 | + } |
|
46 | 50 | |
47 | 51 | $newNode = $doc->documentElement; |
48 | 52 | $result = []; |
@@ -18,22 +18,31 @@ discard block |
||
18 | 18 | } |
19 | 19 | |
20 | 20 | public function run($value, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
21 | - if (!$this->shouldRun($element)) return false; |
|
21 | + if (!$this->shouldRun($element)) { |
|
22 | + return false; |
|
23 | + } |
|
22 | 24 | |
23 | 25 | $value = $this->formatter->format($value, $rules); |
24 | 26 | if (!$this->processPseudo($value, $element, $pseudoMatcher)) { |
25 | 27 | //Remove the current contents |
26 | 28 | $this->removeAllChildren($element); |
27 | 29 | //Now make a text node |
28 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $value); |
|
29 | - else $this->appendContent($element, $value); |
|
30 | + if ($this->getContentMode($rules) === 'replace') { |
|
31 | + $this->replaceContent($element, $value); |
|
32 | + } else { |
|
33 | + $this->appendContent($element, $value); |
|
34 | + } |
|
30 | 35 | } |
31 | 36 | } |
32 | 37 | |
33 | 38 | private function shouldRun($element) { |
34 | - if ($element->getAttribute('transphporm') === 'remove') return false; |
|
39 | + if ($element->getAttribute('transphporm') === 'remove') { |
|
40 | + return false; |
|
41 | + } |
|
35 | 42 | do { |
36 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
43 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
44 | + return false; |
|
45 | + } |
|
37 | 46 | } |
38 | 47 | while (($element = $element->parentNode) instanceof \DomElement); |
39 | 48 | return true; |
@@ -60,9 +69,10 @@ discard block |
||
60 | 69 | $new = $document->importNode($n, true); |
61 | 70 | //Removing this might cause problems with caching... |
62 | 71 | //$new->setAttribute('transphporm', 'added'); |
63 | - } |
|
64 | - else { |
|
65 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
72 | + } else { |
|
73 | + if ($n instanceof \DomText) { |
|
74 | + $n = $n->nodeValue; |
|
75 | + } |
|
66 | 76 | $new = $document->createElement('text'); |
67 | 77 | $new->appendChild($document->createTextNode($n)); |
68 | 78 | $new->setAttribute('transphporm', 'text'); |
@@ -98,7 +108,9 @@ discard block |
||
98 | 108 | while ($e = $e->previousSibling && !in_array($e->getAttribute('transphporm'), [null, 'remove'])) { |
99 | 109 | $remove[] = $e; |
100 | 110 | } |
101 | - foreach ($remove as $r) $r->parentNode->removeChild($r); |
|
111 | + foreach ($remove as $r) { |
|
112 | + $r->parentNode->removeChild($r); |
|
113 | + } |
|
102 | 114 | } |
103 | 115 | |
104 | 116 | private function replaceContent($element, $content) { |
@@ -117,6 +129,8 @@ discard block |
||
117 | 129 | } |
118 | 130 | |
119 | 131 | private function removeAllChildren($element) { |
120 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
132 | + while ($element->hasChildNodes()) { |
|
133 | + $element->removeChild($element->firstChild); |
|
134 | + } |
|
121 | 135 | } |
122 | 136 | } |
123 | 137 | \ No newline at end of file |
@@ -97,7 +97,7 @@ |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | public function template($val, $element) { |
100 | - $templateFunction = new TemplateFunction($this->baseDir . $val[0], isset($val[1]) ? $val[1] : null, isset($val[2]) ? $this->baseDir . $val[2] : null); |
|
100 | + $templateFunction = new TemplateFunction($this->baseDir.$val[0], isset($val[1]) ? $val[1] : null, isset($val[2]) ? $this->baseDir.$val[2] : null); |
|
101 | 101 | return $templateFunction->getTemplateNodes($this->getData($element)); |
102 | 102 | } |
103 | 103 | } |
@@ -24,7 +24,9 @@ discard block |
||
24 | 24 | /** Binds data to an element */ |
25 | 25 | public function bind(\DomNode $element, $data, $type = 'data') { |
26 | 26 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
27 | - if (is_array($data) && $this->isObjectArray($data)) $data = $data[0]; |
|
27 | + if (is_array($data) && $this->isObjectArray($data)) { |
|
28 | + $data = $data[0]; |
|
29 | + } |
|
28 | 30 | $content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : []; |
29 | 31 | $content[$type] = $data; |
30 | 32 | $this->dataStorage[$element] = $content; |
@@ -48,7 +50,9 @@ discard block |
||
48 | 50 | /** 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*/ |
49 | 51 | public function getData(\DomElement $element = null, $type = 'data') { |
50 | 52 | while ($element) { |
51 | - if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type]; |
|
53 | + if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) { |
|
54 | + return $this->dataStorage[$element][$type]; |
|
55 | + } |
|
52 | 56 | $element = $element->parentNode; |
53 | 57 | } |
54 | 58 | return $this->data; |
@@ -67,13 +71,17 @@ discard block |
||
67 | 71 | $valueParser = new \Transphporm\Parser\Value($this); |
68 | 72 | |
69 | 73 | foreach ($parts as $part) { |
70 | - if ($part === '') continue; |
|
74 | + if ($part === '') { |
|
75 | + continue; |
|
76 | + } |
|
71 | 77 | $part = $valueParser->parse($part, $element)[0]; |
72 | 78 | $funcResult = $this->traverseObj($part, $obj, $valueParser, $element); |
73 | 79 | |
74 | - if ($funcResult !== false) $obj = $funcResult; |
|
75 | - |
|
76 | - else $obj = $this->ifNull($obj, $part); |
|
80 | + if ($funcResult !== false) { |
|
81 | + $obj = $funcResult; |
|
82 | + } else { |
|
83 | + $obj = $this->ifNull($obj, $part); |
|
84 | + } |
|
77 | 85 | } |
78 | 86 | return $obj; |
79 | 87 | } |
@@ -82,14 +90,19 @@ discard block |
||
82 | 90 | if (strpos($part, '(') !== false) { |
83 | 91 | $subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false); |
84 | 92 | return $subObjParser->parse($part, $element)[0]; |
93 | + } else if (method_exists($obj, $part)) { |
|
94 | + return call_user_func([$obj, $part]); |
|
95 | + } else { |
|
96 | + return false; |
|
85 | 97 | } |
86 | - else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); |
|
87 | - else return false; |
|
88 | 98 | } |
89 | 99 | |
90 | 100 | private function ifNull($obj, $key) { |
91 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
92 | - else return isset($obj->$key) ? $obj->$key : null; |
|
101 | + if (is_array($obj)) { |
|
102 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
103 | + } else { |
|
104 | + return isset($obj->$key) ? $obj->$key : null; |
|
105 | + } |
|
93 | 106 | } |
94 | 107 | |
95 | 108 | public function attr($val, $element) { |