Result.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. * Copyright 2007 ZXing authors
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. namespace Zxing;
  18. /**
  19. * <p>Encapsulates the result of decoding a barcode within an image.</p>
  20. *
  21. * @author Sean Owen
  22. */
  23. final class Result {
  24. private $text;
  25. private $rawBytes;
  26. private $resultPoints;
  27. private $format;
  28. private $resultMetadata;
  29. private $timestamp;
  30. public function __construct($text,
  31. $rawBytes,
  32. $resultPoints,
  33. $format,
  34. $timestamp = '') {
  35. $this->text = $text;
  36. $this->rawBytes = $rawBytes;
  37. $this->resultPoints = $resultPoints;
  38. $this->format = $format;
  39. $this->resultMetadata = null;
  40. $this->timestamp = $timestamp?$timestamp:time();
  41. }
  42. /**
  43. * @return raw text encoded by the barcode
  44. */
  45. public function getText() {
  46. return $this->text;
  47. }
  48. /**
  49. * @return raw bytes encoded by the barcode, if applicable, otherwise {@code null}
  50. */
  51. public function getRawBytes() {
  52. return $this->rawBytes;
  53. }
  54. /**
  55. * @return points related to the barcode in the image. These are typically points
  56. * identifying finder patterns or the corners of the barcode. The exact meaning is
  57. * specific to the type of barcode that was decoded.
  58. */
  59. public function getResultPoints() {
  60. return $this->resultPoints;
  61. }
  62. /**
  63. * @return {@link BarcodeFormat} representing the format of the barcode that was decoded
  64. */
  65. public function getBarcodeFormat() {
  66. return $this->format;
  67. }
  68. /**
  69. * @return {@link Map} mapping {@link ResultMetadataType} keys to values. May be
  70. * {@code null}. This contains optional metadata about what was detected about the barcode,
  71. * like orientation.
  72. */
  73. public function getResultMetadata() {
  74. return $this->resultMetadata;
  75. }
  76. public function putMetadata($type, $value) {
  77. if ($this->resultMetadata == null) {
  78. $this->resultMetadata = array();
  79. }
  80. $resultMetadata[$type] = $value;
  81. }
  82. public function putAllMetadata($metadata) {
  83. if ($metadata != null) {
  84. if ($this->resultMetadata == null) {
  85. $this->resultMetadata = $metadata;
  86. } else {
  87. $this->resultMetadata = array_merge($this->resultMetadata, $metadata);
  88. }
  89. }
  90. }
  91. public function addResultPoints($newPoints) {
  92. $oldPoints = $this->resultPoints;
  93. if ($oldPoints == null) {
  94. $this->resultPoints = $newPoints;
  95. } else if ($newPoints != null && count($newPoints) > 0) {
  96. $allPoints = fill_array(0,count($oldPoints)+count($newPoints),0);
  97. $allPoints = arraycopy($oldPoints, 0, $allPoints, 0, count($oldPoints));
  98. $allPoints = arraycopy($newPoints, 0, $allPoints, count($oldPoints), count($newPoints));
  99. $this->resultPoints = $allPoints;
  100. }
  101. }
  102. public function getTimestamp() {
  103. return $this->timestamp;
  104. }
  105. //@Override
  106. public function toString() {
  107. return $this->text;
  108. }
  109. }