mtvbrianking /
laravel-ussd
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bmatovu\Ussd\Actions; |
||
| 4 | |||
| 5 | use Bmatovu\Ussd\Contracts\AnswerableTag; |
||
| 6 | use Bmatovu\Ussd\Contracts\RenderableTag; |
||
| 7 | use Bmatovu\Ussd\Exceptions\FlowBreakException; |
||
| 8 | use Bmatovu\Ussd\Store; |
||
| 9 | use Bmatovu\Ussd\Traits\Attributes; |
||
| 10 | use Bmatovu\Ussd\Traits\Expressions; |
||
| 11 | use Bmatovu\Ussd\Traits\Variables; |
||
| 12 | |||
| 13 | class BaseAction implements RenderableTag, AnswerableTag |
||
| 14 | { |
||
| 15 | use Attributes; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 16 | use Expressions; |
||
| 17 | use Variables; |
||
|
0 ignored issues
–
show
|
|||
| 18 | |||
| 19 | protected \DOMNode $node; |
||
| 20 | protected Store $store; |
||
| 21 | |||
| 22 | 2 | public function __construct(\DOMNode $node, Store $store) |
|
| 23 | { |
||
| 24 | 2 | $this->node = $node; |
|
| 25 | 2 | $this->store = $store; |
|
| 26 | } |
||
| 27 | |||
| 28 | 1 | public function handle(): ?string |
|
| 29 | { |
||
| 30 | 1 | $this->shiftCursor(); |
|
| 31 | |||
| 32 | 1 | $fails = $this->store->get('fails', 0); |
|
| 33 | |||
| 34 | 1 | return $fails |
|
| 35 | ? $this->readAttrText('error', 'InternalError') |
||
| 36 | 1 | : $this->readAttrText(); |
|
| 37 | } |
||
| 38 | |||
| 39 | public function process(?string $answer): void |
||
| 40 | { |
||
| 41 | throw new FlowBreakException('Override this func...'); |
||
| 42 | } |
||
| 43 | |||
| 44 | 1 | protected function shiftCursor(): void |
|
| 45 | { |
||
| 46 | 1 | $exp = $this->store->get('_exp'); |
|
| 47 | |||
| 48 | 1 | $this->store->put('_pre', $exp); |
|
| 49 | 1 | $this->store->put('_exp', $this->incExp($exp)); |
|
| 50 | } |
||
| 51 | } |
||
| 52 |