* @copyright 2022 smiley * @license MIT */ namespace chillerlan\QRCode\Output; use function implode, sprintf; /** * HTML output (a cheap markup substitute when SVG is not available or not an option) */ class QRMarkupHTML extends QRMarkup{ public const MIME_TYPE = 'text/html'; /** * @inheritDoc */ protected function createMarkup(bool $saveToFile):string{ $rows = []; $cssClass = $this->getCssClass(); foreach($this->matrix->getMatrix() as $row){ $element = ''; $modules = array_map(fn(int $M_TYPE):string => sprintf($element, $this->getModuleValue($M_TYPE)), $row); $rows[] = sprintf('
%s
%s', implode('', $modules), $this->eol); } $html = sprintf('
%3$s%2$s
%3$s', $cssClass, implode('', $rows), $this->eol); // wrap the snippet into a body when saving to file if($saveToFile){ $html = sprintf( '%2$s%2$s%2$s'. 'QR Code%2$s%1$s%2$s', $html, $this->eol ); } return $html; } }