123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace Zxing;
- final class Result
- {
- private $text;
- private $rawBytes;
- private $resultPoints;
- private $format;
- private $resultMetadata;
- private $timestamp;
- public function __construct(
- $text,
- $rawBytes,
- $resultPoints,
- $format,
- $timestamp = ''
- ) {
- $this->text = $text;
- $this->rawBytes = $rawBytes;
- $this->resultPoints = $resultPoints;
- $this->format = $format;
- $this->resultMetadata = null;
- $this->timestamp = $timestamp ?: time();
- }
-
- public function getText()
- {
- return $this->text;
- }
-
- public function getRawBytes()
- {
- return $this->rawBytes;
- }
-
- public function getResultPoints()
- {
- return $this->resultPoints;
- }
-
- public function getBarcodeFormat()
- {
- return $this->format;
- }
-
- public function getResultMetadata()
- {
- return $this->resultMetadata;
- }
- public function putMetadata($type, $value)
- {
- if ($this->resultMetadata === null) {
- $this->resultMetadata = [];
- }
- $resultMetadata[$type] = $value;
- }
- public function putAllMetadata($metadata)
- {
- if ($metadata !== null) {
- if ($this->resultMetadata === null) {
- $this->resultMetadata = $metadata;
- } else {
- $this->resultMetadata = array_merge($this->resultMetadata, $metadata);
- }
- }
- }
- public function addResultPoints($newPoints)
- {
- $oldPoints = $this->resultPoints;
- if ($oldPoints === null) {
- $this->resultPoints = $newPoints;
- } else if ($newPoints !== null && count($newPoints) > 0) {
- $allPoints = fill_array(0, count($oldPoints) + count($newPoints), 0);
- $allPoints = arraycopy($oldPoints, 0, $allPoints, 0, count($oldPoints));
- $allPoints = arraycopy($newPoints, 0, $allPoints, count($oldPoints), count($newPoints));
- $this->resultPoints = $allPoints;
- }
- }
- public function getTimestamp()
- {
- return $this->timestamp;
- }
- public function toString()
- {
- return $this->text;
- }
- }
|