MMOframework
Why AI Playground Libraries Developers Agency
FR EN
Build a project live
Index

QrCode

MMO\oauth\helpers · 1 symbol · generated 30 Nov 2026

class

QrCode

QrCode.php:14

A QR code (ISO/IEC 18004) of a short text, as an SVG: the otpauth:// link an authenticator app scans to enrol a second factor (Totp::Uri). No dependency, and nothing sent to a third party (a QR code service would see the secret). Byte mode, error correction level M, versions 1 to 40, the mask of the lowest penalty (rules 1, 2 and 4 of the standard). Follows the structure of Project Nayuki's QR Code generator (MIT)

final class MMO\oauth\helpers\QrCode
Namespace
MMO\oauth\helpers
echo QrCode::Svg(Totp::Uri($secret, 'Oviepro', 'ada@example.com'));

Constants3

BLOCKS

const BLOCKS = […41 items]

ECC_PER_BLOCK

const ECC_PER_BLOCK = […41 items]

LEVEL_BITS

level M's two bits in the format information

const LEVEL_BITS = 0

Properties4

function

protected array $function = []
Type
array

modules

protected array $modules = []
Type
array

size

protected int $size
Type
int

version

protected int $version
Type
int

Methods19

alignmentPositions()

QrCode.php:237
protected function alignmentPositions(): array
returnsarraythe centres of the alignment patterns, on each axis

drawCodewords($codewords)

QrCode.php:265
protected function drawCodewords(array $codewords): void
$codewordsarray
returnsvoid

drawFunctionPatterns()

QrCode.php:196
protected function drawFunctionPatterns(): void
returnsvoid

encode($data)

QrCode.php:108
protected function encode(array $data): array
$dataarraythe bytes of the text
returnsarraythe data codewords: byte mode, its count, the bytes, the terminator and the padding

getModules()

QrCode.php:79
function getModules(): array
returnsarrayarray<int, bool>> the modules, by row then column (true: dark), quiet zone excluded

GfMultiply($x, $y)

staticQrCode.php:180
protected static function GfMultiply(int $x, int $y): int
$xint
$yint
returnsint$x times $y in GF(2^8), modulo x^8 + x^4 + x^3 + x^2 + 1

interleave($data)

QrCode.php:123
protected function interleave(array $data): array
$dataarray
returnsarraythe data split in blocks, each followed by its error correction, interleaved

penalty()

QrCode.php:303
protected function penalty(): int
returnsintthe penalty of the modules: runs of 5 or more (rule 1), 2x2 blocks (rule 2), the balance (rule 4)

RsDivisor($degree)

staticQrCode.php:150
protected static function RsDivisor(int $degree): array
$degreeint
returnsarrayint> the generator polynomial of $degree, its leading term left out

RsRemainder($data, $divisor)

staticQrCode.php:169
protected static function RsRemainder(array $data, array $divisor): array
$dataarray
$divisorarray
returnsarrayint> the error correction codewords of $data

Svg($text, $module, $title)

staticQrCode.php:62
static function Svg(string $text, int $module = 4, string $title = 'QR code'): string
$textstringwhat the code says
$module = 4intthe side of a module, in the svg's units
$title = 'QR code'string
returnsstringan <svg> of the code with its quiet zone (4 modules), dark on white, scalable
QrCode::Svg('otpauth://totp/...', 4); // '<svg xmlns=... viewBox="0 0 ...">...</svg>'

toSvg($module, $title)

QrCode.php:66
function toSvg(int $module = 4, string $title = 'QR code'): string
$module = 4int
$title = 'QR code'string
returnsstring

__construct($text)

QrCode.php:30
function __construct(string $text)
$textstring
throwsif $text does not fit in a version 40