Skip to content

Commit 0578456

Browse files
committed
🚿
1 parent e9743c0 commit 0578456

File tree

5 files changed

+40
-28
lines changed

5 files changed

+40
-28
lines changed

src/Output/QRMarkupSVG.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
* @see https://github.com/codemasher/php-qrcode/pull/5
1919
* @see https://developer.mozilla.org/en-US/docs/Web/SVG
2020
* @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/
21-
* @see http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html
21+
* @see https://lea.verou.me/blog/2019/05/utility-convert-svg-path-to-all-relative-or-all-absolute-commands/
22+
* @see https://codepen.io/leaverou/full/RmwzKv
23+
* @see https://jakearchibald.github.io/svgomg/
24+
* @see https://web.archive.org/web/20200220211445/http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html
2225
*/
2326
class QRMarkupSVG extends QRMarkup{
2427

@@ -54,6 +57,17 @@ protected function getOutputDimensions():array{
5457
return [$this->moduleCount, $this->moduleCount];
5558
}
5659

60+
/**
61+
* @inheritDoc
62+
*/
63+
protected function getCssClass(int $M_TYPE = 0):string{
64+
return implode(' ', [
65+
'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE),
66+
$this->matrix->isDark($M_TYPE) ? 'dark' : 'light',
67+
$this->options->cssClass,
68+
]);
69+
}
70+
5771
/**
5872
* @inheritDoc
5973
*/
@@ -159,17 +173,6 @@ protected function path(string $path, int $M_TYPE):string{
159173
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
160174
}
161175

162-
/**
163-
* @inheritDoc
164-
*/
165-
protected function getCssClass(int $M_TYPE = 0):string{
166-
return implode(' ', [
167-
'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE),
168-
$this->matrix->isDark($M_TYPE) ? 'dark' : 'light',
169-
$this->options->cssClass,
170-
]);
171-
}
172-
173176
/**
174177
* returns a path segment for a single module
175178
*

src/Output/QROutputAbstract.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ protected function setModuleValues():void{
146146

147147
}
148148

149+
/**
150+
* Prepares the value for the given input (return value depends on the output class)
151+
*/
152+
abstract protected function prepareModuleValue(mixed $value):mixed;
153+
154+
/**
155+
* Returns a default value for either dark or light modules (return value depends on the output class)
156+
*/
157+
abstract protected function getDefaultModuleValue(bool $isDark):mixed;
158+
149159
/**
150160
* Returns the prepared value for the given $M_TYPE
151161
*
@@ -167,16 +177,6 @@ protected function getModuleValueAt(int $x, int $y):mixed{
167177
return $this->getModuleValue($this->matrix->get($x, $y));
168178
}
169179

170-
/**
171-
* Prepares the value for the given input (return value depends on the output class)
172-
*/
173-
abstract protected function prepareModuleValue(mixed $value):mixed;
174-
175-
/**
176-
* Returns a default value for either dark or light modules (return value depends on the output class)
177-
*/
178-
abstract protected function getDefaultModuleValue(bool $isDark):mixed;
179-
180180
/**
181181
* Returns a base64 data URI for the given string and mime type
182182
*/

src/QRCode.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ public function renderMatrix(QRMatrix $matrix, string $file = null):mixed{
100100

101101
/**
102102
* Returns a QRMatrix object for the given $data and current QROptions
103-
*
104-
* @throws \chillerlan\QRCode\Data\QRCodeDataException
105103
*/
106104
public function getQRMatrix():QRMatrix{
107105
$matrix = (new QRData($this->options, $this->dataSegments))->writeMatrix();
@@ -149,11 +147,11 @@ protected function initOutputInterface(QRMatrix $matrix):QROutputInterface{
149147
$outputInterface = $this->options->outputInterface;
150148

151149
if(empty($outputInterface) || !class_exists($outputInterface)){
152-
throw new QRCodeOutputException('invalid output module');
150+
throw new QRCodeOutputException('invalid output class');
153151
}
154152

155153
if(!in_array(QROutputInterface::class, class_implements($outputInterface))){
156-
throw new QRCodeOutputException('output module does not implement QROutputInterface');
154+
throw new QRCodeOutputException('output class does not implement QROutputInterface');
157155
}
158156

159157
return new $outputInterface($this->options, $matrix);

src/QROptionsTrait.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,23 @@ trait QROptionsTrait{
204204
/**
205205
* Whether to connect the paths for the several module types to avoid weird glitches when using gradients etc.
206206
*
207+
* This option is exclusive to output classes that use the module collector `QROutputAbstract::collectModules()`,
208+
* which converts the `$M_TYPE` of all modules to `QRMatrix::M_DATA` and `QRMatrix::M_DATA_DARK` respectively.
209+
*
210+
* Module types that should not be added to the connected path can be excluded via `QROptions::$excludeFromConnect`.
211+
*
212+
* Currentty used in `QREps` and `QRMarkupSVG`.
213+
*
214+
* @see \chillerlan\QRCode\Output\QROutputAbstract::collectModules()
215+
* @see \chillerlan\QRCode\QROptionsTrait::$excludeFromConnect
207216
* @see https://github.com/chillerlan/php-qrcode/issues/57
208217
*/
209218
protected bool $connectPaths = false;
210219

211220
/**
212221
* Specify which paths/patterns to exclude from connecting if `QROptions::$connectPaths` is set to `true`
222+
*
223+
* @see \chillerlan\QRCode\QROptionsTrait::$connectPaths
213224
*/
214225
protected array $excludeFromConnect = [];
215226

tests/QRCodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setUp():void{
3939
*/
4040
public function testInitCustomOutputInterfaceNotExistsException():void{
4141
$this->expectException(QRCodeOutputException::class);
42-
$this->expectExceptionMessage('invalid output module');
42+
$this->expectExceptionMessage('invalid output class');
4343

4444
$this->options->outputInterface = 'foo';
4545

@@ -51,7 +51,7 @@ public function testInitCustomOutputInterfaceNotExistsException():void{
5151
*/
5252
public function testInitCustomOutputInterfaceNotImplementsException():void{
5353
$this->expectException(QRCodeOutputException::class);
54-
$this->expectExceptionMessage('output module does not implement QROutputInterface');
54+
$this->expectExceptionMessage('output class does not implement QROutputInterface');
5555

5656
$this->options->outputInterface = stdClass::class;
5757

0 commit comments

Comments
 (0)