| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class QRMarkupHTML |
| 5 |
* |
| 6 |
* @created 06.06.2022 |
| 7 |
* @author smiley <smiley@chillerlan.net> |
| 8 |
* @copyright 2022 smiley |
| 9 |
* @license MIT |
| 10 |
*/ |
| 11 |
namespace WCPOS\Vendor\chillerlan\QRCode\Output; |
| 12 |
|
| 13 |
use function implode, sprintf; |
| 14 |
/** |
| 15 |
* HTML output (a cheap markup substitute when SVG is not available or not an option) |
| 16 |
*/ |
| 17 |
class QRMarkupHTML extends QRMarkup |
| 18 |
{ |
| 19 |
public const MIME_TYPE = 'text/html'; |
| 20 |
/** |
| 21 |
* @inheritDoc |
| 22 |
*/ |
| 23 |
protected function createMarkup(bool $saveToFile) : string |
| 24 |
{ |
| 25 |
$rows = []; |
| 26 |
$cssClass = $this->getCssClass(); |
| 27 |
foreach ($this->matrix->getMatrix() as $row) { |
| 28 |
$element = '<span style="background: %s;"></span>'; |
| 29 |
$modules = \array_map(fn(int $M_TYPE): string => sprintf($element, $this->getModuleValue($M_TYPE)), $row); |
| 30 |
$rows[] = sprintf('<div>%s</div>%s', implode('', $modules), $this->eol); |
| 31 |
} |
| 32 |
$html = sprintf('<div class="%1$s">%3$s%2$s</div>%3$s', $cssClass, implode('', $rows), $this->eol); |
| 33 |
// wrap the snippet into a body when saving to file |
| 34 |
if ($saveToFile) { |
| 35 |
$html = sprintf('<!DOCTYPE html><html lang="none">%2$s<head>%2$s<meta charset="UTF-8">%2$s' . '<title>QR Code</title></head>%2$s<body>%1$s</body>%2$s</html>', $html, $this->eol); |
| 36 |
} |
| 37 |
return $html; |
| 38 |
} |
| 39 |
} |
| 40 |
|