QRDataModeAbstract.php 939 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Class QRDataModeAbstract
  4. *
  5. * @created 19.11.2020
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2020 smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCode\Data;
  11. /**
  12. */
  13. abstract class QRDataModeAbstract implements QRDataModeInterface{
  14. /**
  15. * the current data mode: Num, Alphanum, Kanji, Byte
  16. */
  17. protected static int $datamode;
  18. /**
  19. * The data to write
  20. */
  21. protected string $data;
  22. /**
  23. * QRDataModeAbstract constructor.
  24. *
  25. * @throws \chillerlan\QRCode\Data\QRCodeDataException
  26. */
  27. public function __construct(string $data){
  28. if(!$this::validateString($data)){
  29. throw new QRCodeDataException('invalid data');
  30. }
  31. $this->data = $data;
  32. }
  33. /**
  34. * returns the character count of the $data string
  35. */
  36. protected function getCharCount():int{
  37. return strlen($this->data);
  38. }
  39. /**
  40. * @inheritDoc
  41. */
  42. public function getDataMode():int{
  43. return $this::$datamode;
  44. }
  45. }