mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-12 02:36:28 +00:00
:octocat: add QROutputAbstract::getModuleValue() to avoid directly accessing the $moduleValues array
This commit is contained in:
@@ -108,9 +108,10 @@ class QREps extends QROutputAbstract{
|
||||
}
|
||||
|
||||
// 4 values will be interpreted as CMYK, 3 as RGB
|
||||
$format = (count($this->moduleValues[$M_TYPE]) === 4) ? '%f %f %f %f C' : '%f %f %f R';
|
||||
$eps[] = sprintf($format, ...$this->moduleValues[$M_TYPE]);
|
||||
$eps[] = implode("\n", $path);
|
||||
$val = $this->getModuleValue($M_TYPE);
|
||||
$format = (count($val) === 4) ? '%f %f %f %f C' : '%f %f %f R';
|
||||
$eps[] = sprintf($format, ...$val);
|
||||
$eps[] = implode("\n", $path);
|
||||
}
|
||||
|
||||
// end file
|
||||
|
||||
@@ -123,8 +123,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var int $M_TYPE */
|
||||
$color = $this->moduleValues[$M_TYPE];
|
||||
$color = $this->getModuleValue($M_TYPE);
|
||||
|
||||
if($prevColor !== $color){
|
||||
/** @phan-suppress-next-line PhanParamTooFewUnpack */
|
||||
|
||||
@@ -252,7 +252,7 @@ class QRGdImage extends QROutputAbstract{
|
||||
(int)(($y * $this->scale) + ($this->scale / 2)),
|
||||
(int)(2 * $this->options->circleRadius * $this->scale),
|
||||
(int)(2 * $this->options->circleRadius * $this->scale),
|
||||
$this->moduleValues[$M_TYPE]
|
||||
$this->getModuleValue($M_TYPE)
|
||||
)
|
||||
: imagefilledrectangle(
|
||||
$this->image,
|
||||
@@ -260,7 +260,7 @@ class QRGdImage extends QROutputAbstract{
|
||||
($y * $this->scale),
|
||||
(($x + 1) * $this->scale),
|
||||
(($y + 1) * $this->scale),
|
||||
$this->moduleValues[$M_TYPE]
|
||||
$this->getModuleValue($M_TYPE)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ class QRImagick extends QROutputAbstract{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->imagickDraw->setFillColor($this->moduleValues[$M_TYPE]);
|
||||
$this->imagickDraw->setFillColor($this->getModuleValue($M_TYPE));
|
||||
|
||||
$this->options->drawCircularModules && !$this->matrix->checkTypeIn($x, $y, $this->options->keepAsSquare)
|
||||
? $this->imagickDraw->circle(
|
||||
|
||||
@@ -31,7 +31,7 @@ class QRMarkupHTML extends QRMarkup{
|
||||
$html .= '<div>';
|
||||
|
||||
foreach($row as $M_TYPE){
|
||||
$html .= sprintf('<span style="background: %s;"></span>', $this->moduleValues[$M_TYPE]);
|
||||
$html .= sprintf('<span style="background: %s;"></span>', $this->getModuleValue($M_TYPE));
|
||||
}
|
||||
|
||||
$html .= '</div>'.$this->options->eol;
|
||||
|
||||
@@ -124,8 +124,9 @@ class QRMarkupSVG extends QRMarkup{
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path
|
||||
*/
|
||||
protected function path(string $path, int $M_TYPE):string{
|
||||
$val = $this->getModuleValue($M_TYPE);
|
||||
// ignore non-existent module values
|
||||
$format = !isset($this->moduleValues[$M_TYPE]) || empty($this->moduleValues[$M_TYPE])
|
||||
$format = empty($val)
|
||||
? '<path class="%1$s" d="%2$s"/>'
|
||||
: '<path class="%1$s" fill="%3$s" fill-opacity="%4$s" d="%2$s"/>';
|
||||
|
||||
@@ -133,7 +134,7 @@ class QRMarkupSVG extends QRMarkup{
|
||||
$format,
|
||||
$this->getCssClass($M_TYPE),
|
||||
$path,
|
||||
($this->moduleValues[$M_TYPE] ?? ''), // value may or may not exist
|
||||
($val ?? ''), // value may or may not exist
|
||||
$this->options->svgOpacity
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,16 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the final value for the given input (return value depends on the output module)
|
||||
* Returns the prepared value for the given $M_TYPE (return value depends on the output class)
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function getModuleValue(int $M_TYPE){
|
||||
return ($this->moduleValues[$M_TYPE] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the value for the given input (return value depends on the output class)
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
@@ -101,7 +110,7 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
abstract protected function prepareModuleValue($value);
|
||||
|
||||
/**
|
||||
* Returns a default value for either dark or light modules (return value depends on the output module)
|
||||
* Returns a default value for either dark or light modules (return value depends on the output class)
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,7 @@ class QRString extends QROutputAbstract{
|
||||
$r = [];
|
||||
|
||||
foreach($row as $M_TYPE){
|
||||
$r[] = $this->moduleValues[$M_TYPE];
|
||||
$r[] = $this->getModuleValue($M_TYPE);
|
||||
}
|
||||
|
||||
$str[] = implode('', $r);
|
||||
|
||||
Reference in New Issue
Block a user