mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-17 12:13:05 +00:00
:octocat: QROutputAbstract: remove property copies of previously magic properties
This commit is contained in:
@@ -41,7 +41,7 @@ class MeltedSVGQRCodeOutput extends QRMarkupSVG{
|
||||
foreach($row as $x => $M_TYPE){
|
||||
$M_TYPE_LAYER = $M_TYPE;
|
||||
|
||||
if($this->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->excludeFromConnect)){
|
||||
if($this->options->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->options->excludeFromConnect)){
|
||||
// to connect paths we'll redeclare the $M_TYPE_LAYER to data only
|
||||
$M_TYPE_LAYER = QRMatrix::M_DATA;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class GroupShapeSVGQRCodeOutput extends QRMarkupSVG{
|
||||
foreach($row as $x => $M_TYPE){
|
||||
$M_TYPE_LAYER = $M_TYPE;
|
||||
|
||||
if($this->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->excludeFromConnect)){
|
||||
if($this->options->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->options->excludeFromConnect)){
|
||||
// to connect paths we'll redeclare the $M_TYPE_LAYER to data only
|
||||
$M_TYPE_LAYER = QRMatrix::M_DATA;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class RandomDotsSVGOutput extends QRMarkupSVG{
|
||||
foreach($row as $x => $M_TYPE){
|
||||
$M_TYPE_LAYER = $M_TYPE;
|
||||
|
||||
if($this->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->excludeFromConnect)){
|
||||
if($this->options->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->options->excludeFromConnect)){
|
||||
// to connect paths we'll redeclare the $M_TYPE_LAYER to data only
|
||||
$M_TYPE_LAYER = QRMatrix::M_DATA;
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
foreach($row as $x => $M_TYPE){
|
||||
$M_TYPE_LAYER = $M_TYPE;
|
||||
|
||||
if($this->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->excludeFromConnect)){
|
||||
if($this->options->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->options->excludeFromConnect)){
|
||||
// to connect paths we'll redeclare the $M_TYPE_LAYER to data only
|
||||
$M_TYPE_LAYER = QRMatrix::M_DATA;
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ class QREps extends QROutputAbstract{
|
||||
*/
|
||||
protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYER):string|null{
|
||||
|
||||
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
*/
|
||||
protected function module(int $x, int $y, int $M_TYPE):void{
|
||||
|
||||
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ abstract class QRGdImage extends QROutputAbstract{
|
||||
$this->matrix->invert();
|
||||
}
|
||||
|
||||
$this->copyVars();
|
||||
$this->setMatrixDimensions();
|
||||
}
|
||||
|
||||
@@ -200,7 +199,7 @@ abstract class QRGdImage extends QROutputAbstract{
|
||||
*/
|
||||
protected function createImage():GdImage{
|
||||
|
||||
if($this->drawCircularModules && $this->options->gdImageUseUpscale && $this->options->scale < 20){
|
||||
if($this->options->drawCircularModules && $this->options->gdImageUseUpscale && $this->options->scale < 20){
|
||||
// increase the initial image size by 10
|
||||
$this->length *= 10;
|
||||
$this->scale *= 10;
|
||||
@@ -275,19 +274,19 @@ abstract class QRGdImage extends QROutputAbstract{
|
||||
*/
|
||||
protected function module(int $x, int $y, int $M_TYPE):void{
|
||||
|
||||
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
return;
|
||||
}
|
||||
|
||||
$color = $this->getModuleValue($M_TYPE);
|
||||
|
||||
if($this->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->keepAsSquare)){
|
||||
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
|
||||
imagefilledellipse(
|
||||
$this->image,
|
||||
(($x * $this->scale) + intdiv($this->scale, 2)),
|
||||
(($y * $this->scale) + intdiv($this->scale, 2)),
|
||||
(int)($this->circleDiameter * $this->scale),
|
||||
(int)($this->circleDiameter * $this->scale),
|
||||
(int)($this->options->circleRadius * 2 * $this->scale),
|
||||
(int)($this->options->circleRadius * 2 * $this->scale),
|
||||
$color,
|
||||
);
|
||||
|
||||
|
||||
@@ -197,17 +197,17 @@ class QRImagick extends QROutputAbstract{
|
||||
*/
|
||||
protected function module(int $x, int $y, int $M_TYPE):void{
|
||||
|
||||
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
return;
|
||||
}
|
||||
|
||||
$this->imagickDraw->setFillColor($this->getModuleValue($M_TYPE));
|
||||
|
||||
if($this->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->keepAsSquare)){
|
||||
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
|
||||
$this->imagickDraw->circle(
|
||||
(($x + 0.5) * $this->scale),
|
||||
(($y + 0.5) * $this->scale),
|
||||
(($x + 0.5 + $this->circleRadius) * $this->scale),
|
||||
(($x + 0.5 + $this->options->circleRadius) * $this->scale),
|
||||
(($y + 0.5) * $this->scale),
|
||||
);
|
||||
|
||||
|
||||
@@ -129,19 +129,19 @@ class QRInterventionImage extends QROutputAbstract{
|
||||
*/
|
||||
protected function module(int $x, int $y, int $M_TYPE):void{
|
||||
|
||||
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
return;
|
||||
}
|
||||
|
||||
$color = $this->getModuleValue($M_TYPE);
|
||||
|
||||
if($this->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->keepAsSquare)){
|
||||
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
|
||||
|
||||
$this->image->drawCircle(
|
||||
(($x * $this->scale) + intdiv($this->scale, 2)),
|
||||
(($y * $this->scale) + intdiv($this->scale, 2)),
|
||||
function(CircleFactory $circle) use ($color):void{
|
||||
$circle->radius((int)($this->circleRadius * $this->scale));
|
||||
$circle->radius((int)($this->options->circleRadius * $this->scale));
|
||||
$circle->background($color);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -28,10 +28,10 @@ class QRMarkupHTML extends QRMarkup{
|
||||
$element = '<span style="background: %s;"></span>';
|
||||
$modules = array_map(fn(int $M_TYPE):string => sprintf($element, $this->getModuleValue($M_TYPE)), $row);
|
||||
|
||||
$rows[] = sprintf('<div>%s</div>%s', implode('', $modules), $this->eol);
|
||||
$rows[] = sprintf('<div>%s</div>%s', implode('', $modules), $this->options->eol);
|
||||
}
|
||||
|
||||
$html = sprintf('<div class="%1$s">%3$s%2$s</div>%3$s', $cssClass, implode('', $rows), $this->eol);
|
||||
$html = sprintf('<div class="%1$s">%3$s%2$s</div>%3$s', $cssClass, implode('', $rows), $this->options->eol);
|
||||
|
||||
// wrap the snippet into a body when saving to file
|
||||
if($saveToFile){
|
||||
@@ -39,7 +39,7 @@ class QRMarkupHTML extends QRMarkup{
|
||||
'<!DOCTYPE html><html lang="none">%2$s<head>%2$s<meta charset="UTF-8">%2$s'.
|
||||
'<title>QR Code</title></head>%2$s<body>%1$s</body>%2$s</html>',
|
||||
$html,
|
||||
$this->eol,
|
||||
$this->options->eol,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+12
-10
@@ -67,13 +67,13 @@ class QRMarkupSVG extends QRMarkup{
|
||||
$svg = $this->header();
|
||||
|
||||
if($this->options->svgDefs !== ''){
|
||||
$svg .= sprintf('<defs>%1$s%2$s</defs>%2$s', $this->options->svgDefs, $this->eol);
|
||||
$svg .= sprintf('<defs>%1$s%2$s</defs>%2$s', $this->options->svgDefs, $this->options->eol);
|
||||
}
|
||||
|
||||
$svg .= $this->paths();
|
||||
|
||||
// close svg
|
||||
$svg .= sprintf('%1$s</svg>%1$s', $this->eol);
|
||||
$svg .= sprintf('%1$s</svg>%1$s', $this->options->eol);
|
||||
|
||||
return $svg;
|
||||
}
|
||||
@@ -102,11 +102,11 @@ class QRMarkupSVG extends QRMarkup{
|
||||
$this->options->cssClass,
|
||||
$this->getViewBox(),
|
||||
$this->options->svgPreserveAspectRatio,
|
||||
$this->eol,
|
||||
$this->options->eol,
|
||||
);
|
||||
|
||||
if($this->options->svgAddXmlHeader){
|
||||
$header = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s%s', $this->eol, $header);
|
||||
$header = sprintf('<?xml version="1.0" encoding="UTF-8"?>%s%s', $this->options->eol, $header);
|
||||
}
|
||||
|
||||
return $header;
|
||||
@@ -129,7 +129,7 @@ class QRMarkupSVG extends QRMarkup{
|
||||
$chonks[] = implode(' ', $chunk);
|
||||
}
|
||||
|
||||
$path = implode($this->eol, $chonks);
|
||||
$path = implode($this->options->eol, $chonks);
|
||||
|
||||
if($path === ''){
|
||||
continue;
|
||||
@@ -138,7 +138,7 @@ class QRMarkupSVG extends QRMarkup{
|
||||
$svg[] = $this->path($path, $M_TYPE);
|
||||
}
|
||||
|
||||
return implode($this->eol, $svg);
|
||||
return implode($this->options->eol, $svg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,17 +167,19 @@ class QRMarkupSVG extends QRMarkup{
|
||||
*/
|
||||
protected function moduleTransform(int $x, int $y, int $M_TYPE, int $M_TYPE_LAYER):string|null{
|
||||
|
||||
if(!$this->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
if(!$this->options->drawLightModules && !$this->matrix->isDark($M_TYPE)){
|
||||
return null;
|
||||
}
|
||||
|
||||
if($this->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->keepAsSquare)){
|
||||
if($this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)){
|
||||
// string interpolation: ugly and fast
|
||||
$ix = ($x + 0.5 - $this->circleRadius);
|
||||
$r = $this->options->circleRadius;
|
||||
$d = $r * 2;
|
||||
$ix = ($x + 0.5 - $r);
|
||||
$iy = ($y + 0.5);
|
||||
|
||||
// phpcs:ignore
|
||||
return "M$ix $iy a$this->circleRadius $this->circleRadius 0 1 0 $this->circleDiameter 0 a$this->circleRadius $this->circleRadius 0 1 0 -$this->circleDiameter 0Z";
|
||||
return "M$ix $iy a$r $r 0 1 0 $d 0 a$r $r 0 1 0 -$d 0Z";
|
||||
}
|
||||
|
||||
// phpcs:ignore
|
||||
|
||||
@@ -128,7 +128,7 @@ class QRMarkupXML extends QRMarkup{
|
||||
protected function module(int $x, int $y, int $M_TYPE):DOMElement|null{
|
||||
$isDark = $this->matrix->isDark($M_TYPE);
|
||||
|
||||
if(!$this->drawLightModules && !$isDark){
|
||||
if(!$this->options->drawLightModules && !$isDark){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,28 +55,11 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
protected SettingsContainerInterface|QROptions $options;
|
||||
|
||||
/**
|
||||
* @see \chillerlan\QRCode\QROptions::$excludeFromConnect
|
||||
* @var int[]
|
||||
* The current module scale value (might have been modified)
|
||||
*
|
||||
* @see \chillerlan\QRCode\QROptions::$scale
|
||||
*/
|
||||
protected array $excludeFromConnect;
|
||||
/**
|
||||
* @see \chillerlan\QRCode\QROptions::$keepAsSquare
|
||||
* @var int[]
|
||||
*/
|
||||
protected array $keepAsSquare;
|
||||
/** @see \chillerlan\QRCode\QROptions::$scale */
|
||||
protected int $scale;
|
||||
/** @see \chillerlan\QRCode\QROptions::$connectPaths */
|
||||
protected bool $connectPaths;
|
||||
/** @see \chillerlan\QRCode\QROptions::$eol */
|
||||
protected string $eol;
|
||||
/** @see \chillerlan\QRCode\QROptions::$drawLightModules */
|
||||
protected bool $drawLightModules;
|
||||
/** @see \chillerlan\QRCode\QROptions::$drawCircularModules */
|
||||
protected bool $drawCircularModules;
|
||||
/** @see \chillerlan\QRCode\QROptions::$circleRadius */
|
||||
protected float $circleRadius;
|
||||
protected float $circleDiameter;
|
||||
|
||||
/**
|
||||
* QROutputAbstract constructor.
|
||||
@@ -94,36 +77,10 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
$this->matrix->invert();
|
||||
}
|
||||
|
||||
$this->copyVars();
|
||||
$this->setMatrixDimensions();
|
||||
$this->setModuleValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates copies of several QROptions values to avoid calling the magic getters/property hooks
|
||||
* in long loops for a significant performance increase.
|
||||
*
|
||||
* These variables are usually used in the "module" methods and are called up to 31329 times (at version 40).
|
||||
*/
|
||||
protected function copyVars():void{
|
||||
|
||||
$vars = [
|
||||
'connectPaths',
|
||||
'excludeFromConnect',
|
||||
'eol',
|
||||
'drawLightModules',
|
||||
'drawCircularModules',
|
||||
'keepAsSquare',
|
||||
'circleRadius',
|
||||
];
|
||||
|
||||
foreach($vars as $property){
|
||||
$this->{$property} = $this->options->{$property};
|
||||
}
|
||||
|
||||
$this->circleDiameter = ($this->circleRadius * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets/updates the matrix dimensions
|
||||
*
|
||||
@@ -272,7 +229,7 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
foreach($row as $x => $M_TYPE){
|
||||
$M_TYPE_LAYER = $M_TYPE;
|
||||
|
||||
if($this->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->excludeFromConnect)){
|
||||
if($this->options->connectPaths && !$this->matrix->checkTypeIn($x, $y, $this->options->excludeFromConnect)){
|
||||
// to connect paths we'll redeclare the $M_TYPE_LAYER to data only
|
||||
$M_TYPE_LAYER = QRMatrix::M_DATA;
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ class QRStringJSON extends QROutputAbstract{
|
||||
protected function module(int $x, int $y, int $M_TYPE):array|null{
|
||||
$isDark = $this->matrix->isDark($M_TYPE);
|
||||
|
||||
if(!$this->drawLightModules && !$isDark){
|
||||
if(!$this->options->drawLightModules && !$isDark){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class QRStringText extends QROutputAbstract{
|
||||
$lines[] = $linestart.implode('', array_map($this->getModuleValue(...), $row));
|
||||
}
|
||||
|
||||
$data = implode($this->eol, $lines);
|
||||
$data = implode($this->options->eol, $lines);
|
||||
|
||||
$this->saveToFile($data, $file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user