| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class DecoderResult |
| 5 |
* |
| 6 |
* @created 17.01.2021 |
| 7 |
* @author ZXing Authors |
| 8 |
* @author Smiley <smiley@chillerlan.net> |
| 9 |
* @copyright 2021 Smiley |
| 10 |
* @license Apache-2.0 |
| 11 |
*/ |
| 12 |
namespace WCPOS\Vendor\chillerlan\QRCode\Decoder; |
| 13 |
|
| 14 |
use WCPOS\Vendor\chillerlan\QRCode\Common\BitBuffer; |
| 15 |
use WCPOS\Vendor\chillerlan\QRCode\Common\EccLevel; |
| 16 |
use WCPOS\Vendor\chillerlan\QRCode\Common\MaskPattern; |
| 17 |
use WCPOS\Vendor\chillerlan\QRCode\Common\Version; |
| 18 |
use WCPOS\Vendor\chillerlan\QRCode\Data\QRMatrix; |
| 19 |
use function property_exists; |
| 20 |
/** |
| 21 |
* Encapsulates the result of decoding a matrix of bits. This typically |
| 22 |
* applies to 2D barcode formats. For now, it contains the raw bytes obtained |
| 23 |
* as well as a String interpretation of those bytes, if applicable. |
| 24 |
* |
| 25 |
* @property \chillerlan\QRCode\Common\BitBuffer $rawBytes |
| 26 |
* @property string $data |
| 27 |
* @property \chillerlan\QRCode\Common\Version $version |
| 28 |
* @property \chillerlan\QRCode\Common\EccLevel $eccLevel |
| 29 |
* @property \chillerlan\QRCode\Common\MaskPattern $maskPattern |
| 30 |
* @property int $structuredAppendParity |
| 31 |
* @property int $structuredAppendSequence |
| 32 |
* @property \chillerlan\QRCode\Detector\FinderPattern[] $finderPatterns |
| 33 |
*/ |
| 34 |
final class DecoderResult |
| 35 |
{ |
| 36 |
private BitBuffer $rawBytes; |
| 37 |
private Version $version; |
| 38 |
private EccLevel $eccLevel; |
| 39 |
private MaskPattern $maskPattern; |
| 40 |
private string $data = ''; |
| 41 |
private int $structuredAppendParity = -1; |
| 42 |
private int $structuredAppendSequence = -1; |
| 43 |
/** @var \chillerlan\QRCode\Detector\FinderPattern[] */ |
| 44 |
private array $finderPatterns = []; |
| 45 |
/** |
| 46 |
* DecoderResult constructor. |
| 47 |
*/ |
| 48 |
public function __construct(?iterable $properties = null) |
| 49 |
{ |
| 50 |
if ($properties !== null) { |
| 51 |
foreach ($properties as $property => $value) { |
| 52 |
if (!property_exists($this, $property)) { |
| 53 |
continue; |
| 54 |
} |
| 55 |
$this->{$property} = $value; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
/** |
| 60 |
* @return mixed|null |
| 61 |
*/ |
| 62 |
public function __get(string $property) |
| 63 |
{ |
| 64 |
if (property_exists($this, $property)) { |
| 65 |
return $this->{$property}; |
| 66 |
} |
| 67 |
return null; |
| 68 |
} |
| 69 |
/** |
| 70 |
* |
| 71 |
*/ |
| 72 |
public function __toString() : string |
| 73 |
{ |
| 74 |
return $this->data; |
| 75 |
} |
| 76 |
/** |
| 77 |
* |
| 78 |
*/ |
| 79 |
public function hasStructuredAppend() : bool |
| 80 |
{ |
| 81 |
return $this->structuredAppendParity >= 0 && $this->structuredAppendSequence >= 0; |
| 82 |
} |
| 83 |
/** |
| 84 |
* Returns a QRMatrix instance with the settings and data of the reader result |
| 85 |
*/ |
| 86 |
public function getQRMatrix() : QRMatrix |
| 87 |
{ |
| 88 |
return (new QRMatrix($this->version, $this->eccLevel))->initFunctionalPatterns()->writeCodewords($this->rawBytes)->setFormatInfo($this->maskPattern)->mask($this->maskPattern); |
| 89 |
} |
| 90 |
} |
| 91 |
|