1 | <?php |
||
21 | abstract class AbstractWriter implements WriterInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var RendererInterface |
||
25 | */ |
||
26 | protected $renderer; |
||
27 | |||
28 | /** |
||
29 | * AbstractWriter constructor. |
||
30 | * |
||
31 | * @param RendererInterface $renderer |
||
32 | */ |
||
33 | protected function __construct(RendererInterface $renderer) |
||
34 | { |
||
35 | $this->renderer = $renderer; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @inheritdoc |
||
40 | */ |
||
41 | public function writeDataUri(QrCodeInterface $qrCode): string |
||
42 | { |
||
43 | return 'data:' . $this->getContentType() . ';base64,' . base64_encode($this->writeString($qrCode)); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @inheritdoc |
||
48 | */ |
||
49 | public function writeFile(QrCodeInterface $qrCode, $path) |
||
50 | { |
||
51 | return file_put_contents($path, $this->writeString($qrCode)); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | * @throws ReflectionException |
||
57 | */ |
||
58 | public function getName(): string |
||
59 | { |
||
60 | return strtolower(str_replace('Writer', '', (new ReflectionClass($this))->getShortName())); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param array $color |
||
65 | * |
||
66 | * @return Rgb |
||
67 | */ |
||
68 | protected function convertColor(array $color): Rgb |
||
69 | { |
||
70 | return new Rgb($color['r'], $color['g'], $color['b']); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param string $errorCorrectionLevel |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | protected function convertErrorCorrectionLevel($errorCorrectionLevel): string |
||
85 | } |
||
86 |