QRMarkupHTML.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Class QRMarkupHTML
  4. *
  5. * @created 06.06.2022
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2022 smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCode\Output;
  11. use function sprintf;
  12. /**
  13. * HTML output
  14. */
  15. class QRMarkupHTML extends QRMarkup{
  16. /**
  17. * @inheritDoc
  18. */
  19. protected function createMarkup(bool $saveToFile):string{
  20. $html = empty($this->options->cssClass)
  21. ? '<div>'
  22. : sprintf('<div class="%s">', $this->getCssClass(0)); // @todo $M_TYPE
  23. $html .= $this->options->eol;
  24. for($y = 0; $y < $this->moduleCount; $y++){
  25. $html .= '<div>';
  26. for($x = 0; $x < $this->moduleCount; $x++){
  27. $html .= sprintf('<span style="background: %s;"></span>', $this->getModuleValueAt($x, $y));
  28. }
  29. $html .= '</div>'.$this->options->eol;
  30. }
  31. $html .= '</div>'.$this->options->eol;
  32. // wrap the snippet into a body when saving to file
  33. if($saveToFile){
  34. $html = sprintf(
  35. '<!DOCTYPE html><html lang=""><head><meta charset="UTF-8"><title>QR Code</title></head><body>%s</body></html>',
  36. $this->options->eol.$html
  37. );
  38. }
  39. return $html;
  40. }
  41. /**
  42. * @inheritDoc
  43. */
  44. protected function getCssClass(int $M_TYPE):string{
  45. return $this->options->cssClass;
  46. }
  47. }