|
10 | 10 |
|
11 | 11 | namespace CryptoQr; |
12 | 12 |
|
| 13 | +use Endroid\QrCode\Writer\Result\ResultInterface; |
| 14 | + |
13 | 15 | class CryptoQr extends Qr |
14 | 16 | { |
15 | 17 | /** |
@@ -38,34 +40,38 @@ protected function getAddressProtocol(): string |
38 | 40 | public function setLabel(string $label): void |
39 | 41 | { |
40 | 42 | $this->label = $label; |
41 | | - $this->updateText(); |
42 | 43 | } |
43 | 44 |
|
44 | 45 | public function setAmount(float $amount): void |
45 | 46 | { |
46 | 47 | $this->amount = $amount; |
47 | | - $this->updateText(); |
48 | 48 | } |
49 | 49 |
|
50 | 50 | public function setMessage(string $message): void |
51 | 51 | { |
52 | 52 | $this->message = $message; |
53 | | - $this->updateText(); |
54 | 53 | } |
55 | 54 |
|
56 | | - protected function updateText(): void |
| 55 | + private function buildData(): void |
57 | 56 | { |
58 | 57 | $uri = empty($this->getAddressProtocol()) ? '' : $this->getAddressProtocol() . ':'; |
59 | 58 | $uri .= $this->getAddress(); |
60 | | - $params = $this->getParam('amount', $this->getAmountString()) . |
61 | | - $this->getParam('label', $this->getLabel()) . |
62 | | - $this->getParam('message', $this->getMessage()); |
| 59 | + $params = $this->getParam('amount', $this->getAmountString()) |
| 60 | + . $this->getParam('label', $this->getLabel()) |
| 61 | + . $this->getParam('message', $this->getMessage()); |
63 | 62 |
|
64 | | - $this->getQrCode()->setData( |
| 63 | + $this->setAddress( |
65 | 64 | $uri . ($params !== '' ? '?' . substr($params, 1) : '') |
66 | 65 | ); |
67 | 66 | } |
68 | 67 |
|
| 68 | + protected function writerResult(): ResultInterface |
| 69 | + { |
| 70 | + $this->buildData(); |
| 71 | + |
| 72 | + return parent::writerResult(); |
| 73 | + } |
| 74 | + |
69 | 75 | private function getParam(string $label, string $value): string |
70 | 76 | { |
71 | 77 | return !empty($value) ? '&' . $label . '=' . rawurlencode($value) : ''; |
|
0 commit comments