mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-18 01:53:12 +00:00
🚿
This commit is contained in:
+15
-12
@@ -18,7 +18,10 @@ use function array_chunk, implode, is_string, preg_match, sprintf, trim;
|
||||
* @see https://github.com/codemasher/php-qrcode/pull/5
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/SVG
|
||||
* @see https://www.sarasoueidan.com/demos/interactive-svg-coordinate-system/
|
||||
* @see http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html
|
||||
* @see https://lea.verou.me/blog/2019/05/utility-convert-svg-path-to-all-relative-or-all-absolute-commands/
|
||||
* @see https://codepen.io/leaverou/full/RmwzKv
|
||||
* @see https://jakearchibald.github.io/svgomg/
|
||||
* @see https://web.archive.org/web/20200220211445/http://apex.infogridpacific.com/SVG/svg-tutorial-contents.html
|
||||
*/
|
||||
class QRMarkupSVG extends QRMarkup{
|
||||
|
||||
@@ -54,6 +57,17 @@ class QRMarkupSVG extends QRMarkup{
|
||||
return [$this->moduleCount, $this->moduleCount];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getCssClass(int $M_TYPE = 0):string{
|
||||
return implode(' ', [
|
||||
'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE),
|
||||
$this->matrix->isDark($M_TYPE) ? 'dark' : 'light',
|
||||
$this->options->cssClass,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -159,17 +173,6 @@ class QRMarkupSVG extends QRMarkup{
|
||||
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getCssClass(int $M_TYPE = 0):string{
|
||||
return implode(' ', [
|
||||
'qr-'.($this::LAYERNAMES[$M_TYPE] ?? $M_TYPE),
|
||||
$this->matrix->isDark($M_TYPE) ? 'dark' : 'light',
|
||||
$this->options->cssClass,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a path segment for a single module
|
||||
*
|
||||
|
||||
@@ -146,6 +146,16 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the value for the given input (return value depends on the output class)
|
||||
*/
|
||||
abstract protected function prepareModuleValue(mixed $value):mixed;
|
||||
|
||||
/**
|
||||
* Returns a default value for either dark or light modules (return value depends on the output class)
|
||||
*/
|
||||
abstract protected function getDefaultModuleValue(bool $isDark):mixed;
|
||||
|
||||
/**
|
||||
* Returns the prepared value for the given $M_TYPE
|
||||
*
|
||||
@@ -167,16 +177,6 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
return $this->getModuleValue($this->matrix->get($x, $y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the value for the given input (return value depends on the output class)
|
||||
*/
|
||||
abstract protected function prepareModuleValue(mixed $value):mixed;
|
||||
|
||||
/**
|
||||
* Returns a default value for either dark or light modules (return value depends on the output class)
|
||||
*/
|
||||
abstract protected function getDefaultModuleValue(bool $isDark):mixed;
|
||||
|
||||
/**
|
||||
* Returns a base64 data URI for the given string and mime type
|
||||
*/
|
||||
|
||||
+2
-4
@@ -100,8 +100,6 @@ class QRCode{
|
||||
|
||||
/**
|
||||
* Returns a QRMatrix object for the given $data and current QROptions
|
||||
*
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
*/
|
||||
public function getQRMatrix():QRMatrix{
|
||||
$matrix = (new QRData($this->options, $this->dataSegments))->writeMatrix();
|
||||
@@ -149,11 +147,11 @@ class QRCode{
|
||||
$outputInterface = $this->options->outputInterface;
|
||||
|
||||
if(empty($outputInterface) || !class_exists($outputInterface)){
|
||||
throw new QRCodeOutputException('invalid output module');
|
||||
throw new QRCodeOutputException('invalid output class');
|
||||
}
|
||||
|
||||
if(!in_array(QROutputInterface::class, class_implements($outputInterface))){
|
||||
throw new QRCodeOutputException('output module does not implement QROutputInterface');
|
||||
throw new QRCodeOutputException('output class does not implement QROutputInterface');
|
||||
}
|
||||
|
||||
return new $outputInterface($this->options, $matrix);
|
||||
|
||||
@@ -204,12 +204,23 @@ trait QROptionsTrait{
|
||||
/**
|
||||
* Whether to connect the paths for the several module types to avoid weird glitches when using gradients etc.
|
||||
*
|
||||
* This option is exclusive to output classes that use the module collector `QROutputAbstract::collectModules()`,
|
||||
* which converts the `$M_TYPE` of all modules to `QRMatrix::M_DATA` and `QRMatrix::M_DATA_DARK` respectively.
|
||||
*
|
||||
* Module types that should not be added to the connected path can be excluded via `QROptions::$excludeFromConnect`.
|
||||
*
|
||||
* Currentty used in `QREps` and `QRMarkupSVG`.
|
||||
*
|
||||
* @see \chillerlan\QRCode\Output\QROutputAbstract::collectModules()
|
||||
* @see \chillerlan\QRCode\QROptionsTrait::$excludeFromConnect
|
||||
* @see https://github.com/chillerlan/php-qrcode/issues/57
|
||||
*/
|
||||
protected bool $connectPaths = false;
|
||||
|
||||
/**
|
||||
* Specify which paths/patterns to exclude from connecting if `QROptions::$connectPaths` is set to `true`
|
||||
*
|
||||
* @see \chillerlan\QRCode\QROptionsTrait::$connectPaths
|
||||
*/
|
||||
protected array $excludeFromConnect = [];
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ final class QRCodeTest extends TestCase{
|
||||
*/
|
||||
public function testInitCustomOutputInterfaceNotExistsException():void{
|
||||
$this->expectException(QRCodeOutputException::class);
|
||||
$this->expectExceptionMessage('invalid output module');
|
||||
$this->expectExceptionMessage('invalid output class');
|
||||
|
||||
$this->options->outputInterface = 'foo';
|
||||
|
||||
@@ -51,7 +51,7 @@ final class QRCodeTest extends TestCase{
|
||||
*/
|
||||
public function testInitCustomOutputInterfaceNotImplementsException():void{
|
||||
$this->expectException(QRCodeOutputException::class);
|
||||
$this->expectExceptionMessage('output module does not implement QROutputInterface');
|
||||
$this->expectExceptionMessage('output class does not implement QROutputInterface');
|
||||
|
||||
$this->options->outputInterface = stdClass::class;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user