|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Prgayman\Zatca\Utilis; |
| 4 | + |
| 5 | +class QrCodeOptions |
| 6 | +{ |
| 7 | + |
| 8 | + /** |
| 9 | + * Holds the size of the QrCode in pixels. |
| 10 | + * |
| 11 | + * @var int |
| 12 | + */ |
| 13 | + protected $pixels = 100; |
| 14 | + |
| 15 | + /** |
| 16 | + * Holds the margin size of the QrCode. |
| 17 | + * |
| 18 | + * @var int |
| 19 | + */ |
| 20 | + protected $margin = 0; |
| 21 | + |
| 22 | + /** |
| 23 | + * Holds the selected formatter. |
| 24 | + * |
| 25 | + * @var string |
| 26 | + */ |
| 27 | + protected $format = 'svg'; |
| 28 | + |
| 29 | + /** |
| 30 | + * The foreground color of the QrCode. |
| 31 | + * |
| 32 | + * @var array|null |
| 33 | + */ |
| 34 | + protected $color = null; |
| 35 | + |
| 36 | + /** |
| 37 | + * The background color of the QrCode. |
| 38 | + * |
| 39 | + * @var array|null |
| 40 | + */ |
| 41 | + protected $backgroundColor = null; |
| 42 | + |
| 43 | + /** |
| 44 | + * The style of the blocks within the QrCode. |
| 45 | + * Possible values are square, dot, and round. |
| 46 | + * |
| 47 | + * @var string |
| 48 | + */ |
| 49 | + protected $style = 'square'; |
| 50 | + |
| 51 | + /** |
| 52 | + * The size of the selected style between 0 and 1. |
| 53 | + * This only applies to dot and round. |
| 54 | + * |
| 55 | + * @var float|null |
| 56 | + */ |
| 57 | + protected $styleSize = null; |
| 58 | + |
| 59 | + /** |
| 60 | + * The style to apply to the eye. |
| 61 | + * Possible values are circle and square. |
| 62 | + * |
| 63 | + * @var string|null |
| 64 | + */ |
| 65 | + protected $eyeStyle = null; |
| 66 | + |
| 67 | + /** |
| 68 | + * Sets the size of the QrCode. |
| 69 | + * |
| 70 | + * @param int $pixels |
| 71 | + * @return QrCodeOptions |
| 72 | + */ |
| 73 | + public function size(int $pixels): self |
| 74 | + { |
| 75 | + $this->pixels = $pixels; |
| 76 | + |
| 77 | + return $this; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Sets the margin of the QrCode. |
| 82 | + * |
| 83 | + * @param int $margin |
| 84 | + * @return QrCodeOptions |
| 85 | + */ |
| 86 | + public function margin(int $margin): self |
| 87 | + { |
| 88 | + $this->margin = $margin; |
| 89 | + |
| 90 | + return $this; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Sets the format of the QrCode. |
| 95 | + * |
| 96 | + * @param string $format |
| 97 | + * @return QrCodeOptions |
| 98 | + */ |
| 99 | + public function format(string $format): self |
| 100 | + { |
| 101 | + $this->format = $format; |
| 102 | + |
| 103 | + return $this; |
| 104 | + } |
| 105 | + |
| 106 | + |
| 107 | + /** |
| 108 | + * Sets the foreground color of the QrCode. |
| 109 | + * |
| 110 | + * @param int $red |
| 111 | + * @param int $green |
| 112 | + * @param int $blue |
| 113 | + * @param null|int $alpha |
| 114 | + * |
| 115 | + * @return QrCodeOptions |
| 116 | + */ |
| 117 | + public function color(int $red, int $green, int $blue, ?int $alpha = null): self |
| 118 | + { |
| 119 | + $this->color = [$red, $green, $blue, $alpha]; |
| 120 | + |
| 121 | + return $this; |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Sets the background color of the QrCode. |
| 126 | + * |
| 127 | + * @param int $red |
| 128 | + * @param int $green |
| 129 | + * @param int $blue |
| 130 | + * @param null|int $alpha |
| 131 | + * |
| 132 | + * @return QrCodeOptions |
| 133 | + */ |
| 134 | + public function backgroundColor(int $red, int $green, int $blue, ?int $alpha = null): self |
| 135 | + { |
| 136 | + $this->backgroundColor = [$red, $green, $blue, $alpha]; |
| 137 | + |
| 138 | + return $this; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Sets the style of the blocks for the QrCode. |
| 143 | + * |
| 144 | + * @param string $style |
| 145 | + * @param float $size |
| 146 | + * |
| 147 | + * @return QrCodeOptions |
| 148 | + */ |
| 149 | + public function style(string $style, float $size = 0.5): self |
| 150 | + { |
| 151 | + $this->style = $style; |
| 152 | + $this->styleSize = $size; |
| 153 | + |
| 154 | + return $this; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Sets the eye style. |
| 159 | + * |
| 160 | + * @param string $style |
| 161 | + * @return QrCodeOptions |
| 162 | + */ |
| 163 | + public function eye(string $style): self |
| 164 | + { |
| 165 | + $this->eyeStyle = $style; |
| 166 | + |
| 167 | + return $this; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Fetches the size. |
| 172 | + * |
| 173 | + * @return int |
| 174 | + */ |
| 175 | + public function getSize(): int |
| 176 | + { |
| 177 | + return $this->pixels; |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Fetches the margin. |
| 182 | + * |
| 183 | + * @return int |
| 184 | + */ |
| 185 | + public function getMargin(): int |
| 186 | + { |
| 187 | + return $this->margin; |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * Fetches the format. |
| 192 | + * |
| 193 | + * @return string |
| 194 | + */ |
| 195 | + public function getFormat(): string |
| 196 | + { |
| 197 | + return $this->format; |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * Fetches the foreground color. |
| 202 | + * |
| 203 | + * @return array|null |
| 204 | + */ |
| 205 | + public function getColor() |
| 206 | + { |
| 207 | + return $this->color; |
| 208 | + } |
| 209 | + |
| 210 | + /** |
| 211 | + * Fetches the background color. |
| 212 | + * |
| 213 | + * @return array|null |
| 214 | + */ |
| 215 | + public function getBackgroundColor() |
| 216 | + { |
| 217 | + return $this->backgroundColor; |
| 218 | + } |
| 219 | + |
| 220 | + /** |
| 221 | + * Fetches the style. |
| 222 | + * |
| 223 | + * @return string |
| 224 | + */ |
| 225 | + public function getStyle(): string |
| 226 | + { |
| 227 | + return $this->style; |
| 228 | + } |
| 229 | + |
| 230 | + /** |
| 231 | + * Fetches the style size. |
| 232 | + * |
| 233 | + * @return float|null |
| 234 | + */ |
| 235 | + public function getStyleSize() |
| 236 | + { |
| 237 | + return $this->styleSize; |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * Fetches the eye style. |
| 242 | + * |
| 243 | + * @return string|null |
| 244 | + */ |
| 245 | + public function getEye() |
| 246 | + { |
| 247 | + return $this->eyeStyle; |
| 248 | + } |
| 249 | +} |
0 commit comments