@@ -20,7 +20,9 @@ discard block |
||
| 20 | 20 | /** Binds data to an element */ |
| 21 | 21 | public function bind(\DomElement $element, $data, $type = 'data') { |
| 22 | 22 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
| 23 | - if (is_array($data) && $this->isObjectArray($data)) $data = $data[0]; |
|
| 23 | + if (is_array($data) && $this->isObjectArray($data)) { |
|
| 24 | + $data = $data[0]; |
|
| 25 | + } |
|
| 24 | 26 | $content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : []; |
| 25 | 27 | $content[$type] = $data; |
| 26 | 28 | $this->dataStorage[$element] = $content; |
@@ -44,7 +46,9 @@ discard block |
||
| 44 | 46 | /** 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*/ |
| 45 | 47 | private function getData(\DomElement $element = null, $type = 'data') { |
| 46 | 48 | while ($element) { |
| 47 | - if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type]; |
|
| 49 | + if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) { |
|
| 50 | + return $this->dataStorage[$element][$type]; |
|
| 51 | + } |
|
| 48 | 52 | $element = $element->parentNode; |
| 49 | 53 | } |
| 50 | 54 | return $this->data; |
@@ -63,13 +67,17 @@ discard block |
||
| 63 | 67 | $valueParser = new \Transphporm\Parser\Value($this); |
| 64 | 68 | |
| 65 | 69 | foreach ($parts as $part) { |
| 66 | - if ($part === '') continue; |
|
| 70 | + if ($part === '') { |
|
| 71 | + continue; |
|
| 72 | + } |
|
| 67 | 73 | $part = $valueParser->parse($part, $element)[0]; |
| 68 | 74 | $funcResult = $this->traverseObj($part, $obj, $valueParser, $element); |
| 69 | 75 | |
| 70 | - if ($funcResult !== false) $obj = $funcResult; |
|
| 71 | - |
|
| 72 | - else $obj = $this->ifNull($obj, $part); |
|
| 76 | + if ($funcResult !== false) { |
|
| 77 | + $obj = $funcResult; |
|
| 78 | + } else { |
|
| 79 | + $obj = $this->ifNull($obj, $part); |
|
| 80 | + } |
|
| 73 | 81 | } |
| 74 | 82 | return $obj; |
| 75 | 83 | } |
@@ -78,14 +86,19 @@ discard block |
||
| 78 | 86 | if (strpos($part, '(') !== false) { |
| 79 | 87 | $subObjParser = new \Transphporm\Parser\Value($obj, $valueParser, false); |
| 80 | 88 | return $subObjParser->parse($part, $element); |
| 89 | + } else if (method_exists($obj, $part)) { |
|
| 90 | + return call_user_func([$obj, $part]); |
|
| 91 | + } else { |
|
| 92 | + return false; |
|
| 81 | 93 | } |
| 82 | - else if (method_exists($obj, $part)) return call_user_func([$obj, $part]); |
|
| 83 | - else return false; |
|
| 84 | 94 | } |
| 85 | 95 | |
| 86 | 96 | private function ifNull($obj, $key) { |
| 87 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
| 88 | - else return isset($obj->$key) ? $obj->$key : null; |
|
| 97 | + if (is_array($obj)) { |
|
| 98 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
| 99 | + } else { |
|
| 100 | + return isset($obj->$key) ? $obj->$key : null; |
|
| 101 | + } |
|
| 89 | 102 | } |
| 90 | 103 | |
| 91 | 104 | public function attr($val, $element) { |
@@ -110,14 +123,18 @@ discard block |
||
| 110 | 123 | |
| 111 | 124 | $doc = $newTemplate->output([], true)->body; |
| 112 | 125 | |
| 113 | - if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element); |
|
| 126 | + if (isset($val[1])) { |
|
| 127 | + return $this->templateSubsection($val[1], $doc, $element); |
|
| 128 | + } |
|
| 114 | 129 | |
| 115 | 130 | $newNode = $element->ownerDocument->importNode($doc->documentElement, true); |
| 116 | 131 | |
| 117 | 132 | $result = []; |
| 118 | 133 | |
| 119 | 134 | if ($newNode->tagName === 'template') { |
| 120 | - foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true); |
|
| 135 | + foreach ($newNode->childNodes as $node) { |
|
| 136 | + $result[] = $node->cloneNode(true); |
|
| 137 | + } |
|
| 121 | 138 | } |
| 122 | 139 | //else $result[] = $newNode; |
| 123 | 140 | |