PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.20
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.20
1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 All 164 releases
woocommerce-pos / vendor_prefixed / chillerlan / php-qrcode / src / Data / Byte.php

Byte.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.20, at vendor_prefixed/chillerlan/php-qrcode/src/Data/Byte.php

75 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Byte
5 *
6 * @created 25.11.2015
7 * @author Smiley <[email protected]>
8 * @copyright 2015 Smiley
9 * @license MIT
10 */
11 namespace WCPOS\Vendor\chillerlan\QRCode\Data;
12
13 use WCPOS\Vendor\chillerlan\QRCode\Common\BitBuffer;
14 use WCPOS\Vendor\chillerlan\QRCode\Common\Mode;
15 use function chr, ord;
16 /**
17 * 8-bit Byte mode, ISO-8859-1 or UTF-8
18 *
19 * ISO/IEC 18004:2000 Section 8.3.4
20 * ISO/IEC 18004:2000 Section 8.4.4
21 */
22 final class Byte extends QRDataModeAbstract
23 {
24 /**
25 * @inheritDoc
26 */
27 public const DATAMODE = Mode::BYTE;
28 /**
29 * @inheritDoc
30 */
31 public function getLengthInBits() : int
32 {
33 return $this->getCharCount() * 8;
34 }
35 /**
36 * @inheritDoc
37 */
38 public static function validateString(string $string) : bool
39 {
40 return $string !== '';
41 }
42 /**
43 * @inheritDoc
44 */
45 public function write(BitBuffer $bitBuffer, int $versionNumber) : QRDataModeInterface
46 {
47 $len = $this->getCharCount();
48 $bitBuffer->put(self::DATAMODE, 4)->put($len, $this::getLengthBits($versionNumber));
49 $i = 0;
50 while ($i < $len) {
51 $bitBuffer->put(ord($this->data[$i]), 8);
52 $i++;
53 }
54 return $this;
55 }
56 /**
57 * @inheritDoc
58 *
59 * @throws \chillerlan\QRCode\Data\QRCodeDataException
60 */
61 public static function decodeSegment(BitBuffer $bitBuffer, int $versionNumber) : string
62 {
63 $length = $bitBuffer->read(self::getLengthBits($versionNumber));
64 if ($bitBuffer->available() < 8 * $length) {
65 throw new QRCodeDataException('not enough bits available');
66 // @codeCoverageIgnore
67 }
68 $readBytes = '';
69 for ($i = 0; $i < $length; $i++) {
70 $readBytes .= chr($bitBuffer->read(8));
71 }
72 return $readBytes;
73 }
74 }
75