QRDataBase.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Class QRDataBase
  4. *
  5. * @filesource QRDataBase.php
  6. * @created 25.11.2015
  7. * @package chillerlan\QRCode\Data
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2015 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCode\Data;
  13. /**
  14. *
  15. */
  16. class QRDataBase{
  17. /**
  18. * @var string
  19. */
  20. public $data;
  21. /**
  22. * @var int
  23. */
  24. public $dataLength;
  25. /**
  26. * @var array
  27. */
  28. protected $lengthBits = [0, 0, 0];
  29. /**
  30. * QRDataBase constructor.
  31. *
  32. * @param string $data
  33. */
  34. public function __construct($data){
  35. $this->data = $data;
  36. $this->dataLength = strlen($data);
  37. }
  38. /**
  39. * @param int $type
  40. *
  41. * @return int
  42. * @throws \chillerlan\QRCode\Data\QRCodeDataException
  43. */
  44. public function getLengthInBits($type){
  45. switch(true){
  46. case $type >= 1 && $type <= 9: return $this->lengthBits[0]; // 1 - 9
  47. case $type <= 26 : return $this->lengthBits[1]; // 10 - 26
  48. case $type <= 40 : return $this->lengthBits[2]; // 27 - 40
  49. default:
  50. throw new QRCodeDataException('$type: '.$type);
  51. }
  52. }
  53. }