Number.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Class Number
  4. *
  5. * @filesource Number.php
  6. * @created 26.11.2015
  7. * @package QRCode
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2015 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCode\Data;
  13. use chillerlan\QRCode\BitBuffer;
  14. use chillerlan\QRCode\QRConst;
  15. use chillerlan\QRCode\Util;
  16. /**
  17. *
  18. */
  19. class Number extends QRDataBase implements QRDataInterface{
  20. /**
  21. * @var int
  22. */
  23. public $mode = QRConst::MODE_NUMBER;
  24. /**
  25. * @var array
  26. */
  27. protected $lengthBits = [10, 12, 14];
  28. /**
  29. * @param \chillerlan\QRCode\BitBuffer $buffer
  30. */
  31. public function write(BitBuffer &$buffer){
  32. $i = 0;
  33. while($i + 2 < $this->dataLength){
  34. $buffer->put(Util::parseInt(substr($this->data, $i, 3)), 10);
  35. $i += 3;
  36. }
  37. if($i < $this->dataLength){
  38. if($this->dataLength - $i === 1){
  39. $buffer->put(Util::parseInt(substr($this->data, $i, $i + 1)), 4);
  40. }
  41. else if($this->dataLength - $i === 2){
  42. $buffer->put(Util::parseInt(substr($this->data, $i, $i + 2)), 7);
  43. }
  44. }
  45. }
  46. }