mtvbrianking /
laravel-ussd
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bmatovu\Ussd\Traits; |
||
| 4 | |||
| 5 | use Bmatovu\Ussd\Support\Dom; |
||
| 6 | |||
| 7 | trait Variables |
||
| 8 | { |
||
| 9 | protected function getVar(string $name, string $default = '', string $nodeName = 'variable'): string |
||
| 10 | { |
||
| 11 | $children = Dom::getElements($this->node->childNodes, $nodeName); |
||
| 12 | |||
| 13 | foreach ($children as $child) { |
||
| 14 | if ($name === $this->readAttrText('name', '', $child)) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 15 | return $this->readAttrText('value', $default, $child); |
||
| 16 | } |
||
| 17 | } |
||
| 18 | |||
| 19 | return $default; |
||
| 20 | } |
||
| 21 | |||
| 22 | protected function getVars(string $nodeName = 'variable'): array |
||
| 23 | { |
||
| 24 | $children = Dom::getElements($this->node->childNodes, $nodeName); |
||
| 25 | |||
| 26 | $variables = []; |
||
| 27 | foreach ($children as $child) { |
||
| 28 | $name = $this->readAttrText('name', '', $child); |
||
| 29 | $value = $this->readAttrText('value', '', $child); |
||
| 30 | |||
| 31 | $variables[$name] = $value; |
||
| 32 | } |
||
| 33 | |||
| 34 | return $variables; |
||
| 35 | } |
||
| 36 | } |
||
| 37 |