<?php
declare(strict_types = 1);
namespace BaconQrCode\Encoder;
use BaconQrCode\Common\ErrorCorrectionLevel;
use BaconQrCode\Common\Mode;
use BaconQrCode\Common\Version;
final class QrCode
{
public const NUM_MASK_PATTERNS = 8;
private $mode;
private $errorCorrectionLevel;
private $version;
private $maskPattern = -1;
private $matrix;
public function __construct(
Mode $mode,
ErrorCorrectionLevel $errorCorrectionLevel,
Version $version,
int $maskPattern,
ByteMatrix $matrix
) {
$this->mode = $mode;
$this->errorCorrectionLevel = $errorCorrectionLevel;
$this->version = $version;
$this->maskPattern = $maskPattern;
$this->matrix = $matrix;
}
public function getMode() : Mode
{
return $this->mode;
}
public function getErrorCorrectionLevel() : ErrorCorrectionLevel
{
return $this->errorCorrectionLevel;
}
public function getVersion() : Version
{
return $this->version;
}
public function getMaskPattern() : int
{
return $this->maskPattern;
}
public function getMatrix()
{
return $this->matrix;
}
public static function isValidMaskPattern(int $maskPattern) : bool
{
return $maskPattern > 0 && $maskPattern < self::NUM_MASK_PATTERNS;
}
public function __toString() : string
{
$result = "<<\n"
. ' mode: ' . $this->mode . "\n"
. ' ecLevel: ' . $this->errorCorrectionLevel . "\n"
. ' version: ' . $this->version . "\n"
. ' maskPattern: ' . $this->maskPattern . "\n";
if ($this->matrix === null) {
$result .= " matrix: null\n";
} else {
$result .= " matrix:\n";
$result .= $this->matrix;
}
$result .= ">>\n";
return $result;
}
}