PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 4.0.0
WP 2FA – Two-factor authentication for WordPress v4.0.0
4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / bacon / bacon-qr-code / src / Encoder / ByteMatrix.php
wp-2fa / includes / classes / bacon / bacon-qr-code / src / Encoder Last commit date
BlockPair.php 1 week ago ByteMatrix.php 1 week ago Encoder.php 1 week ago MaskUtil.php 1 week ago MatrixUtil.php 1 week ago QrCode.php 1 week ago index.php 1 week ago
ByteMatrix.php
131 lines
1 <?php
2
3 declare (strict_types=1);
4 namespace WP2FA_Vendor\BaconQrCode\Encoder;
5
6 use SplFixedArray;
7 use Traversable;
8 /**
9 * Byte matrix.
10 */
11 final class ByteMatrix
12 {
13 /**
14 * Bytes in the matrix, represented as array.
15 *
16 * @var SplFixedArray<SplFixedArray<int>>
17 */
18 private $bytes;
19 /**
20 * Width of the matrix.
21 *
22 * @var int
23 */
24 private $width;
25 /**
26 * Height of the matrix.
27 *
28 * @var int
29 */
30 private $height;
31 public function __construct(int $width, int $height)
32 {
33 $this->height = $height;
34 $this->width = $width;
35 $this->bytes = new SplFixedArray($height);
36 for ($y = 0; $y < $height; ++$y) {
37 $this->bytes[$y] = SplFixedArray::fromArray(\array_fill(0, $width, 0));
38 }
39 }
40 /**
41 * Gets the width of the matrix.
42 */
43 public function getWidth() : int
44 {
45 return $this->width;
46 }
47 /**
48 * Gets the height of the matrix.
49 */
50 public function getHeight() : int
51 {
52 return $this->height;
53 }
54 /**
55 * Gets the internal representation of the matrix.
56 *
57 * @return SplFixedArray<SplFixedArray<int>>
58 */
59 public function getArray() : SplFixedArray
60 {
61 return $this->bytes;
62 }
63 /**
64 * @return Traversable<int>
65 */
66 public function getBytes() : Traversable
67 {
68 foreach ($this->bytes as $row) {
69 foreach ($row as $byte) {
70 (yield $byte);
71 }
72 }
73 }
74 /**
75 * Gets the byte for a specific position.
76 */
77 public function get(int $x, int $y) : int
78 {
79 return $this->bytes[$y][$x];
80 }
81 /**
82 * Sets the byte for a specific position.
83 */
84 public function set(int $x, int $y, int $value) : void
85 {
86 $this->bytes[$y][$x] = $value;
87 }
88 /**
89 * Clears the matrix with a specific value.
90 */
91 public function clear(int $value) : void
92 {
93 for ($y = 0; $y < $this->height; ++$y) {
94 for ($x = 0; $x < $this->width; ++$x) {
95 $this->bytes[$y][$x] = $value;
96 }
97 }
98 }
99 public function __clone()
100 {
101 $this->bytes = clone $this->bytes;
102 foreach ($this->bytes as $index => $row) {
103 $this->bytes[$index] = clone $row;
104 }
105 }
106 /**
107 * Returns a string representation of the matrix.
108 */
109 public function __toString() : string
110 {
111 $result = '';
112 for ($y = 0; $y < $this->height; $y++) {
113 for ($x = 0; $x < $this->width; $x++) {
114 switch ($this->bytes[$y][$x]) {
115 case 0:
116 $result .= ' 0';
117 break;
118 case 1:
119 $result .= ' 1';
120 break;
121 default:
122 $result .= ' ';
123 break;
124 }
125 }
126 $result .= "\n";
127 }
128 return $result;
129 }
130 }
131