@@ -32,8 +32,9 @@ discard block |
||
| 32 | 32 | $params = $bracketMatcher->match('(', ')'); |
| 33 | 33 | |
| 34 | 34 | return ['name' => $name, 'params' => $params, 'endPoint' => $bracketMatcher->getClosePos()]; |
| 35 | + } else { |
|
| 36 | + return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
| 35 | 37 | } |
| 36 | - else return ['name' => null, 'params' => $function, 'endPoint' => strlen($function)]; |
|
| 37 | 38 | } |
| 38 | 39 | |
| 39 | 40 | public function parse($function, \DomElement $element) { |
@@ -41,13 +42,15 @@ discard block |
||
| 41 | 42 | if ($function && in_array($function[0], ['\'', '"'])) { |
| 42 | 43 | $finalPos = $this->findMatchingPos($function, $function[0]); |
| 43 | 44 | $result[] = $this->extractQuotedString($function[0], $function); |
| 44 | - } |
|
| 45 | - else { |
|
| 45 | + } else { |
|
| 46 | 46 | $func = $this->parseFunction($function); |
| 47 | 47 | $finalPos = $func['endPoint']; |
| 48 | 48 | |
| 49 | - if (($data = $this->getFunctionValue($func['name'], $func['params'], $element)) !== false) $result = $this->appendToArray($result, $data); |
|
| 50 | - else $result[] = trim($function); |
|
| 49 | + if (($data = $this->getFunctionValue($func['name'], $func['params'], $element)) !== false) { |
|
| 50 | + $result = $this->appendToArray($result, $data); |
|
| 51 | + } else { |
|
| 52 | + $result[] = trim($function); |
|
| 53 | + } |
|
| 51 | 54 | } |
| 52 | 55 | $remaining = trim(substr($function, $finalPos+1)); |
| 53 | 56 | return $this->parseNextValue($remaining, $result, $element); |
@@ -56,23 +59,27 @@ discard block |
||
| 56 | 59 | private function getFunctionValue($name, $params, $element) { |
| 57 | 60 | if (($data = $this->callFunc($name, $params, $element)) !== false) { |
| 58 | 61 | return $data; |
| 59 | - } |
|
| 60 | - else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element)) !== false) { |
|
| 62 | + } else if ($this->parent != null && ($data = $this->parent->callFunc($name, $params, $element)) !== false) { |
|
| 61 | 63 | return $data; |
| 64 | + } else { |
|
| 65 | + return false; |
|
| 62 | 66 | } |
| 63 | - else return false; |
|
| 64 | 67 | } |
| 65 | 68 | |
| 66 | 69 | private function appendToArray($array, $value) { |
| 67 | - if (is_array($value)) $array += $value; |
|
| 68 | - else $array[] = $value; |
|
| 70 | + if (is_array($value)) { |
|
| 71 | + $array += $value; |
|
| 72 | + } else { |
|
| 73 | + $array[] = $value; |
|
| 74 | + } |
|
| 69 | 75 | return $array; |
| 70 | 76 | } |
| 71 | 77 | |
| 72 | 78 | private function callFunc($name, $params, $element) { |
| 73 | 79 | if ($name && $this->isCallable($this->dataFunction, $name)) { |
| 74 | - if ($this->callParamsAsArray) return $this->dataFunction->$name($this->parse($params, $element), $element); |
|
| 75 | - else { |
|
| 80 | + if ($this->callParamsAsArray) { |
|
| 81 | + return $this->dataFunction->$name($this->parse($params, $element), $element); |
|
| 82 | + } else { |
|
| 76 | 83 | return $this->callFuncOnObject($this->dataFunction, $name, $this->parse($params, $element)); |
| 77 | 84 | } |
| 78 | 85 | } |
@@ -85,12 +92,17 @@ discard block |
||
| 85 | 92 | } |
| 86 | 93 | |
| 87 | 94 | private function callFuncOnObject($obj, $func, $params) { |
| 88 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $params); |
|
| 89 | - else return call_user_func_array([$obj, $func], $params); |
|
| 95 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
| 96 | + return call_user_func_array($obj->$func, $params); |
|
| 97 | + } else { |
|
| 98 | + return call_user_func_array([$obj, $func], $params); |
|
| 99 | + } |
|
| 90 | 100 | } |
| 91 | 101 | |
| 92 | 102 | private function parseNextValue($remaining, $result, $element) { |
| 93 | - if (strlen($remaining) > 0 && $remaining[0] == ',') $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
|
| 103 | + if (strlen($remaining) > 0 && $remaining[0] == ',') { |
|
| 104 | + $result = array_merge($result, $this->parse(trim(substr($remaining, 1)), $element)); |
|
| 105 | + } |
|
| 94 | 106 | return $result; |
| 95 | 107 | } |
| 96 | 108 | |
@@ -98,8 +110,9 @@ discard block |
||
| 98 | 110 | $pos = $start+1; |
| 99 | 111 | $end = 0; |
| 100 | 112 | while ($end = strpos($string, $char, $pos)) { |
| 101 | - if ($string[$end-1] === $escape) $pos = $end+1; |
|
| 102 | - else { |
|
| 113 | + if ($string[$end-1] === $escape) { |
|
| 114 | + $pos = $end+1; |
|
| 115 | + } else { |
|
| 103 | 116 | break; |
| 104 | 117 | } |
| 105 | 118 | } |