QR8bitByte.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * This file is part of the phpQr package
  4. *
  5. * See @see QRCode class for description of package and license.
  6. */
  7. /**
  8. * Import necessary dependencies
  9. */
  10. require_once 'QRByte.php';
  11. require_once 'QRMode.php';
  12. /**
  13. * This class provides the 8bit Byte implementaton of a QRByte
  14. *
  15. * @author Maik Greubel <[email protected]>
  16. * @package phpQr
  17. */
  18. class QR8bitByte implements QRByte
  19. {
  20. /**
  21. * The data
  22. * @var array
  23. */
  24. private $data;
  25. /**
  26. * The mode
  27. * @var unknown
  28. */
  29. private $mode;
  30. /**
  31. * Retrieve the mode
  32. *
  33. * @return int The mode
  34. * @see QRByte::getMode()
  35. */
  36. public function getMode()
  37. {
  38. return $this->mode;
  39. }
  40. /**
  41. * Retrieve the length
  42. *
  43. * @return int The length
  44. * @see QRByte::getLength()
  45. */
  46. public function getLength()
  47. {
  48. return strlen($this->data);
  49. }
  50. /**
  51. * Write data to byte
  52. *
  53. * @param QRBitBuffer $buffer The data to write into byte
  54. *
  55. * @see QRByte::write()
  56. */
  57. public function write(QRBitBuffer $buffer)
  58. {
  59. for($i = 0; $i < strlen($this->data); $i++)
  60. {
  61. $buffer->put(ord($this->data[$i]), 8);
  62. }
  63. }
  64. /**
  65. * Create a new instance of a QR8bitByte
  66. *
  67. * @param array $data The data for the Byte
  68. */
  69. public function __construct($data)
  70. {
  71. $this->data = $data;
  72. $this->mode = QRMode::MODE_8BIT_BYTE;
  73. }
  74. }