@@ -12,6 +12,9 @@ |
||
| 12 | 12 | private $locale; |
| 13 | 13 | private $baseDir; |
| 14 | 14 | |
| 15 | + /** |
|
| 16 | + * @param string $baseDir |
|
| 17 | + */ |
|
| 15 | 18 | public function __construct(\SplObjectStorage $objectStorage, $data, $locale, $baseDir) { |
| 16 | 19 | $this->dataStorage = $objectStorage; |
| 17 | 20 | $this->data = $data; |
@@ -22,7 +22,9 @@ discard block |
||
| 22 | 22 | /** Binds data to an element */ |
| 23 | 23 | public function bind(\DomElement $element, $data, $type = 'data') { |
| 24 | 24 | //This is a bit of a hack to workaround #24, might need a better way of doing this if it causes a problem |
| 25 | - if (is_array($data) && $this->isObjectArray($data)) $data = $data[0]; |
|
| 25 | + if (is_array($data) && $this->isObjectArray($data)) { |
|
| 26 | + $data = $data[0]; |
|
| 27 | + } |
|
| 26 | 28 | $content = isset($this->dataStorage[$element]) ? $this->dataStorage[$element] : []; |
| 27 | 29 | $content[$type] = $data; |
| 28 | 30 | $this->dataStorage[$element] = $content; |
@@ -45,7 +47,9 @@ discard block |
||
| 45 | 47 | /** 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*/ |
| 46 | 48 | private function getData(\DomElement $element, $type = 'data') { |
| 47 | 49 | while ($element) { |
| 48 | - if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) return $this->dataStorage[$element][$type]; |
|
| 50 | + if (isset($this->dataStorage[$element]) && isset($this->dataStorage[$element][$type])) { |
|
| 51 | + return $this->dataStorage[$element][$type]; |
|
| 52 | + } |
|
| 49 | 53 | $element = $element->parentNode; |
| 50 | 54 | } |
| 51 | 55 | return $this->data; |
@@ -62,16 +66,24 @@ discard block |
||
| 62 | 66 | $parts = explode('.', $name[0]); |
| 63 | 67 | $obj = $data; |
| 64 | 68 | foreach ($parts as $part) { |
| 65 | - if ($part === '') continue; |
|
| 66 | - if (is_callable([$obj, $part])) $obj = call_user_func([$obj, $part]); |
|
| 67 | - else $obj = $this->ifNull($obj, $part); |
|
| 69 | + if ($part === '') { |
|
| 70 | + continue; |
|
| 71 | + } |
|
| 72 | + if (is_callable([$obj, $part])) { |
|
| 73 | + $obj = call_user_func([$obj, $part]); |
|
| 74 | + } else { |
|
| 75 | + $obj = $this->ifNull($obj, $part); |
|
| 76 | + } |
|
| 68 | 77 | } |
| 69 | 78 | return $obj; |
| 70 | 79 | } |
| 71 | 80 | |
| 72 | 81 | private function ifNull($obj, $key) { |
| 73 | - if (is_array($obj)) return isset($obj[$key]) ? $obj[$key] : null; |
|
| 74 | - else return isset($obj->$key) ? $obj->$key : null; |
|
| 82 | + if (is_array($obj)) { |
|
| 83 | + return isset($obj[$key]) ? $obj[$key] : null; |
|
| 84 | + } else { |
|
| 85 | + return isset($obj->$key) ? $obj->$key : null; |
|
| 86 | + } |
|
| 75 | 87 | } |
| 76 | 88 | |
| 77 | 89 | public function attr($val, $element) { |
@@ -97,14 +109,18 @@ discard block |
||
| 97 | 109 | |
| 98 | 110 | $doc = $newTemplate->output([], true)->body; |
| 99 | 111 | |
| 100 | - if (isset($val[1])) return $this->templateSubsection($val[1], $doc, $element); |
|
| 112 | + if (isset($val[1])) { |
|
| 113 | + return $this->templateSubsection($val[1], $doc, $element); |
|
| 114 | + } |
|
| 101 | 115 | |
| 102 | 116 | $newNode = $element->ownerDocument->importNode($doc->documentElement, true); |
| 103 | 117 | |
| 104 | 118 | $result = []; |
| 105 | 119 | |
| 106 | 120 | if ($newNode->tagName === 'template') { |
| 107 | - foreach ($newNode->childNodes as $node) $result[] = $node->cloneNode(true); |
|
| 121 | + foreach ($newNode->childNodes as $node) { |
|
| 122 | + $result[] = $node->cloneNode(true); |
|
| 123 | + } |
|
| 108 | 124 | } |
| 109 | 125 | //else $result[] = $newNode; |
| 110 | 126 | |