| 1 |
<?php |
| 2 |
declare(strict_types = 1); |
| 3 |
|
| 4 |
namespace BaconQrCode\Renderer\RendererStyle; |
| 5 |
|
| 6 |
use BaconQrCode\Renderer\Eye\EyeInterface; |
| 7 |
use BaconQrCode\Renderer\Eye\ModuleEye; |
| 8 |
use BaconQrCode\Renderer\Module\ModuleInterface; |
| 9 |
use BaconQrCode\Renderer\Module\SquareModule; |
| 10 |
|
| 11 |
final class RendererStyle |
| 12 |
{ |
| 13 |
private ModuleInterface $module; |
| 14 |
|
| 15 |
private EyeInterface|null $eye; |
| 16 |
|
| 17 |
private Fill $fill; |
| 18 |
|
| 19 |
public function __construct( |
| 20 |
private int $size, |
| 21 |
private int $margin = 4, |
| 22 |
?ModuleInterface $module = null, |
| 23 |
?EyeInterface $eye = null, |
| 24 |
?Fill $fill = null |
| 25 |
) { |
| 26 |
$this->module = $module ?: SquareModule::instance(); |
| 27 |
$this->eye = $eye ?: new ModuleEye($this->module); |
| 28 |
$this->fill = $fill ?: Fill::default(); |
| 29 |
} |
| 30 |
|
| 31 |
public function withSize(int $size) : self |
| 32 |
{ |
| 33 |
$style = clone $this; |
| 34 |
$style->size = $size; |
| 35 |
return $style; |
| 36 |
} |
| 37 |
|
| 38 |
public function withMargin(int $margin) : self |
| 39 |
{ |
| 40 |
$style = clone $this; |
| 41 |
$style->margin = $margin; |
| 42 |
return $style; |
| 43 |
} |
| 44 |
|
| 45 |
public function getSize() : int |
| 46 |
{ |
| 47 |
return $this->size; |
| 48 |
} |
| 49 |
|
| 50 |
public function getMargin() : int |
| 51 |
{ |
| 52 |
return $this->margin; |
| 53 |
} |
| 54 |
|
| 55 |
public function getModule() : ModuleInterface |
| 56 |
{ |
| 57 |
return $this->module; |
| 58 |
} |
| 59 |
|
| 60 |
public function getEye() : EyeInterface |
| 61 |
{ |
| 62 |
return $this->eye; |
| 63 |
} |
| 64 |
|
| 65 |
public function getFill() : Fill |
| 66 |
{ |
| 67 |
return $this->fill; |
| 68 |
} |
| 69 |
} |