|
|
@@ -13,7 +13,7 @@
|
|
|
namespace chillerlan\QRCode;
|
|
|
|
|
|
use chillerlan\QRCode\Common\{
|
|
|
- EccLevel, ECICharset, GDLuminanceSource, IMagickLuminanceSource, LuminanceSourceInterface, MaskPattern, Mode, Version
|
|
|
+ ECICharset, GDLuminanceSource, IMagickLuminanceSource, LuminanceSourceInterface, MaskPattern, Mode
|
|
|
};
|
|
|
use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Hanzi, Kanji, Number, QRData, QRDataModeInterface, QRMatrix};
|
|
|
use chillerlan\QRCode\Decoder\{Decoder, DecoderResult};
|
|
|
@@ -32,138 +32,10 @@ use function class_exists, class_implements, in_array, mb_convert_encoding, mb_i
|
|
|
*/
|
|
|
class QRCode{
|
|
|
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use Version::AUTO instead
|
|
|
- * @see \chillerlan\QRCode\Common\Version::AUTO
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public const VERSION_AUTO = Version::AUTO;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use MaskPattern::AUTO instead
|
|
|
- * @see \chillerlan\QRCode\Common\MaskPattern::AUTO
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public const MASK_PATTERN_AUTO = MaskPattern::AUTO;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use EccLevel::L instead
|
|
|
- * @see \chillerlan\QRCode\Common\EccLevel::L
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public const ECC_L = EccLevel::L;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use EccLevel::M instead
|
|
|
- * @see \chillerlan\QRCode\Common\EccLevel::M
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public const ECC_M = EccLevel::M;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use EccLevel::Q instead
|
|
|
- * @see \chillerlan\QRCode\Common\EccLevel::Q
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public const ECC_Q = EccLevel::Q;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use EccLevel::H instead
|
|
|
- * @see \chillerlan\QRCode\Common\EccLevel::H
|
|
|
- * @var int
|
|
|
- */
|
|
|
- public const ECC_H = EccLevel::H;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::MARKUP_HTML instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::MARKUP_HTML
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_MARKUP_HTML = QROutputInterface::MARKUP_HTML;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::MARKUP_SVG instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::MARKUP_SVG
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_MARKUP_SVG = QROutputInterface::MARKUP_SVG;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::GDIMAGE_PNG instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::GDIMAGE_PNG
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_IMAGE_PNG = QROutputInterface::GDIMAGE_PNG;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::GDIMAGE_JPG instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::GDIMAGE_JPG
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_IMAGE_JPG = QROutputInterface::GDIMAGE_JPG;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::GDIMAGE_GIF instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::GDIMAGE_GIF
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_IMAGE_GIF = QROutputInterface::GDIMAGE_GIF;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::STRING_JSON instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::STRING_JSON
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_STRING_JSON = QROutputInterface::STRING_JSON;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::STRING_TEXT instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::STRING_TEXT
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_STRING_TEXT = QROutputInterface::STRING_TEXT;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::IMAGICK instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::IMAGICK
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_IMAGICK = QROutputInterface::IMAGICK;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::FPDF instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::FPDF
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_FPDF = QROutputInterface::FPDF;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::EPS instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::EPS
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_EPS = QROutputInterface::EPS;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::CUSTOM instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::CUSTOM
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public const OUTPUT_CUSTOM = QROutputInterface::CUSTOM;
|
|
|
-
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QROutputInterface::MODES instead
|
|
|
- * @see \chillerlan\QRCode\Output\QROutputInterface::MODES
|
|
|
- * @var string[]
|
|
|
- */
|
|
|
- public const OUTPUT_MODES = QROutputInterface::MODES;
|
|
|
-
|
|
|
/**
|
|
|
* The settings container
|
|
|
- *
|
|
|
- * @var \chillerlan\QRCode\QROptions|\chillerlan\Settings\SettingsContainerInterface
|
|
|
*/
|
|
|
- protected SettingsContainerInterface $options;
|
|
|
+ protected SettingsContainerInterface|QROptions $options;
|
|
|
|
|
|
/**
|
|
|
* A collection of one or more data segments of QRDataModeInterface instances to write
|
|
|
@@ -182,14 +54,14 @@ class QRCode{
|
|
|
*
|
|
|
* PHP8: accept iterable
|
|
|
*/
|
|
|
- public function __construct(SettingsContainerInterface $options = null){
|
|
|
+ public function __construct(SettingsContainerInterface|QROptions $options = null){
|
|
|
$this->setOptions(($options ?? new QROptions));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Sets an options instance
|
|
|
*/
|
|
|
- public function setOptions(SettingsContainerInterface $options):self{
|
|
|
+ public function setOptions(SettingsContainerInterface|QROptions $options):static{
|
|
|
$this->options = $options;
|
|
|
|
|
|
if($this->options->readerUseImagickIfAvailable){
|
|
|
@@ -201,10 +73,8 @@ class QRCode{
|
|
|
|
|
|
/**
|
|
|
* Renders a QR Code for the given $data and QROptions, saves $file optionally
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
*/
|
|
|
- public function render(string $data = null, string $file = null){
|
|
|
+ public function render(string $data = null, string $file = null):mixed{
|
|
|
|
|
|
if($data !== null){
|
|
|
/** @var \chillerlan\QRCode\Data\QRDataModeInterface $dataInterface */
|
|
|
@@ -223,10 +93,8 @@ class QRCode{
|
|
|
|
|
|
/**
|
|
|
* Renders a QR Code for the given QRMatrix and QROptions, saves $file optionally
|
|
|
- *
|
|
|
- * @return mixed
|
|
|
*/
|
|
|
- public function renderMatrix(QRMatrix $matrix, string $file = null){
|
|
|
+ public function renderMatrix(QRMatrix $matrix, string $file = null):mixed{
|
|
|
return $this->initOutputInterface($matrix)->dump($file ?? $this->options->cachefile);
|
|
|
}
|
|
|
|
|
|
@@ -277,29 +145,15 @@ class QRCode{
|
|
|
return $matrix;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @deprecated 5.0.0 use QRCode::getQRMatrix() instead
|
|
|
- * @see \chillerlan\QRCode\QRCode::getQRMatrix()
|
|
|
- * @codeCoverageIgnore
|
|
|
- */
|
|
|
- public function getMatrix():QRMatrix{
|
|
|
- return $this->getQRMatrix();
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* initializes a fresh built-in or custom QROutputInterface
|
|
|
*
|
|
|
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
|
|
*/
|
|
|
protected function initOutputInterface(QRMatrix $matrix):QROutputInterface{
|
|
|
- // @todo: remove custom invocation in v6
|
|
|
- $outputInterface = (QROutputInterface::MODES[$this->options->outputType] ?? null);
|
|
|
-
|
|
|
- if($this->options->outputType === QROutputInterface::CUSTOM){
|
|
|
- $outputInterface = $this->options->outputInterface;
|
|
|
- }
|
|
|
+ $outputInterface = $this->options->outputInterface;
|
|
|
|
|
|
- if(!$outputInterface || !class_exists($outputInterface)){
|
|
|
+ if(empty($outputInterface) || !class_exists($outputInterface)){
|
|
|
throw new QRCodeOutputException('invalid output module');
|
|
|
}
|
|
|
|
|
|
@@ -310,57 +164,13 @@ class QRCode{
|
|
|
return new $outputInterface($this->options, $matrix);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * checks if a string qualifies as numeric (convenience method)
|
|
|
- *
|
|
|
- * @deprecated 5.0.0 use Number::validateString() instead
|
|
|
- * @see \chillerlan\QRCode\Data\Number::validateString()
|
|
|
- * @codeCoverageIgnore
|
|
|
- */
|
|
|
- public function isNumber(string $string):bool{
|
|
|
- return Number::validateString($string);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * checks if a string qualifies as alphanumeric (convenience method)
|
|
|
- *
|
|
|
- * @deprecated 5.0.0 use AlphaNum::validateString() instead
|
|
|
- * @see \chillerlan\QRCode\Data\AlphaNum::validateString()
|
|
|
- * @codeCoverageIgnore
|
|
|
- */
|
|
|
- public function isAlphaNum(string $string):bool{
|
|
|
- return AlphaNum::validateString($string);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * checks if a string qualifies as Kanji (convenience method)
|
|
|
- *
|
|
|
- * @deprecated 5.0.0 use Kanji::validateString() instead
|
|
|
- * @see \chillerlan\QRCode\Data\Kanji::validateString()
|
|
|
- * @codeCoverageIgnore
|
|
|
- */
|
|
|
- public function isKanji(string $string):bool{
|
|
|
- return Kanji::validateString($string);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * a dummy (convenience method)
|
|
|
- *
|
|
|
- * @deprecated 5.0.0 use Byte::validateString() instead
|
|
|
- * @see \chillerlan\QRCode\Data\Byte::validateString()
|
|
|
- * @codeCoverageIgnore
|
|
|
- */
|
|
|
- public function isByte(string $string):bool{
|
|
|
- return Byte::validateString($string);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Adds a data segment
|
|
|
*
|
|
|
* ISO/IEC 18004:2000 8.3.6 - Mixing modes
|
|
|
* ISO/IEC 18004:2000 Annex H - Optimisation of bit stream length
|
|
|
*/
|
|
|
- public function addSegment(QRDataModeInterface $segment):self{
|
|
|
+ public function addSegment(QRDataModeInterface $segment):static{
|
|
|
$this->dataSegments[] = $segment;
|
|
|
|
|
|
return $this;
|
|
|
@@ -371,7 +181,7 @@ class QRCode{
|
|
|
*
|
|
|
* @codeCoverageIgnore
|
|
|
*/
|
|
|
- public function clearSegments():self{
|
|
|
+ public function clearSegments():static{
|
|
|
$this->dataSegments = [];
|
|
|
|
|
|
return $this;
|
|
|
@@ -382,7 +192,7 @@ class QRCode{
|
|
|
*
|
|
|
* ISO/IEC 18004:2000 8.3.2 - Numeric Mode
|
|
|
*/
|
|
|
- public function addNumericSegment(string $data):self{
|
|
|
+ public function addNumericSegment(string $data):static{
|
|
|
return $this->addSegment(new Number($data));
|
|
|
}
|
|
|
|
|
|
@@ -391,7 +201,7 @@ class QRCode{
|
|
|
*
|
|
|
* ISO/IEC 18004:2000 8.3.3 - Alphanumeric Mode
|
|
|
*/
|
|
|
- public function addAlphaNumSegment(string $data):self{
|
|
|
+ public function addAlphaNumSegment(string $data):static{
|
|
|
return $this->addSegment(new AlphaNum($data));
|
|
|
}
|
|
|
|
|
|
@@ -400,7 +210,7 @@ class QRCode{
|
|
|
*
|
|
|
* ISO/IEC 18004:2000 8.3.5 - Kanji Mode
|
|
|
*/
|
|
|
- public function addKanjiSegment(string $data):self{
|
|
|
+ public function addKanjiSegment(string $data):static{
|
|
|
return $this->addSegment(new Kanji($data));
|
|
|
}
|
|
|
|
|
|
@@ -409,7 +219,7 @@ class QRCode{
|
|
|
*
|
|
|
* GBT18284-2000 Hanzi Mode
|
|
|
*/
|
|
|
- public function addHanziSegment(string $data):self{
|
|
|
+ public function addHanziSegment(string $data):static{
|
|
|
return $this->addSegment(new Hanzi($data));
|
|
|
}
|
|
|
|
|
|
@@ -418,7 +228,7 @@ class QRCode{
|
|
|
*
|
|
|
* ISO/IEC 18004:2000 8.3.4 - 8-bit Byte Mode
|
|
|
*/
|
|
|
- public function addByteSegment(string $data):self{
|
|
|
+ public function addByteSegment(string $data):static{
|
|
|
return $this->addSegment(new Byte($data));
|
|
|
}
|
|
|
|
|
|
@@ -429,7 +239,7 @@ class QRCode{
|
|
|
*
|
|
|
* ISO/IEC 18004:2000 8.3.1 - Extended Channel Interpretation (ECI) Mode
|
|
|
*/
|
|
|
- public function addEciDesignator(int $encoding):self{
|
|
|
+ public function addEciDesignator(int $encoding):static{
|
|
|
return $this->addSegment(new ECI($encoding));
|
|
|
}
|
|
|
|
|
|
@@ -442,7 +252,7 @@ class QRCode{
|
|
|
*
|
|
|
* @throws \chillerlan\QRCode\QRCodeException
|
|
|
*/
|
|
|
- public function addEciSegment(int $encoding, string $data):self{
|
|
|
+ public function addEciSegment(int $encoding, string $data):static{
|
|
|
// validate the encoding id
|
|
|
$eciCharset = new ECICharset($encoding);
|
|
|
// get charset name
|