mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-12 10:46:28 +00:00
:octocat: extract markup css class generation to QRMarkup::getCssClass()
This commit is contained in:
@@ -54,6 +54,11 @@ abstract class QRMarkup extends QROutputAbstract{
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a string with all css classes for the current element
|
||||
*/
|
||||
abstract protected function getCssClass(int $M_TYPE):string;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ class QRMarkupHTML extends QRMarkup{
|
||||
protected function createMarkup(bool $saveToFile):string{
|
||||
$html = empty($this->options->cssClass)
|
||||
? '<div>'
|
||||
: sprintf('<div class="%s">', $this->options->cssClass);
|
||||
: sprintf('<div class="%s">', $this->getCssClass());
|
||||
|
||||
$html .= $this->options->eol;
|
||||
|
||||
@@ -50,4 +50,11 @@ class QRMarkupHTML extends QRMarkup{
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getCssClass(int $M_TYPE):string{
|
||||
return $this->options->cssClass;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -91,22 +91,33 @@ class QRMarkupSVG extends QRMarkup{
|
||||
continue;
|
||||
}
|
||||
|
||||
$cssClass = implode(' ', [
|
||||
'qr-'.$M_TYPE,
|
||||
($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK ? 'dark' : 'light',
|
||||
$this->options->cssClass,
|
||||
]);
|
||||
|
||||
$format = empty($this->moduleValues[$M_TYPE])
|
||||
? '<path class="%1$s" d="%2$s"/>'
|
||||
: '<path class="%1$s" fill="%3$s" fill-opacity="%4$s" d="%2$s"/>';
|
||||
|
||||
$svg[] = sprintf($format, $cssClass, $path, $this->moduleValues[$M_TYPE], $this->options->svgOpacity);
|
||||
$svg[] = sprintf(
|
||||
$format,
|
||||
$this->getCssClass($M_TYPE),
|
||||
$path,
|
||||
$this->moduleValues[$M_TYPE],
|
||||
$this->options->svgOpacity)
|
||||
;
|
||||
}
|
||||
|
||||
return implode($this->options->eol, $svg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getCssClass(int $M_TYPE):string{
|
||||
return implode(' ', [
|
||||
'qr-'.$M_TYPE,
|
||||
($M_TYPE & QRMatrix::IS_DARK) === QRMatrix::IS_DARK ? 'dark' : 'light',
|
||||
$this->options->cssClass,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a path segment for a single module
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user