mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-11 10:16:42 +00:00
:octocat: extract custom output module init to spearate method
This commit is contained in:
+23
-5
@@ -14,7 +14,7 @@ use chillerlan\QRCode\Common\{ECICharset, MaskPattern, MaskPatternTester, Mode};
|
||||
use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Kanji, Number, QRData, QRCodeDataException, QRDataModeInterface, QRMatrix};
|
||||
use chillerlan\QRCode\Output\{QRCodeOutputException, QRFpdf, QRImage, QRImagick, QRMarkup, QROutputInterface, QRString};
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
use function class_exists, in_array, mb_convert_encoding, mb_detect_encoding;
|
||||
use function class_exists, class_implements, in_array, mb_convert_encoding, mb_detect_encoding;
|
||||
|
||||
/**
|
||||
* Turns a text string into a Model 2 QR Code
|
||||
@@ -153,7 +153,7 @@ class QRCode{
|
||||
|
||||
$matrix = $this->dataInterface->writeMatrix($maskPattern);
|
||||
|
||||
if((bool)$this->options->addQuietzone){
|
||||
if($this->options->addQuietzone){
|
||||
$matrix->setQuietZone($this->options->quietzoneSize);
|
||||
}
|
||||
|
||||
@@ -167,13 +167,13 @@ class QRCode{
|
||||
*/
|
||||
protected function initOutputInterface():QROutputInterface{
|
||||
|
||||
if($this->options->outputType === $this::OUTPUT_CUSTOM && class_exists($this->options->outputInterface)){
|
||||
return new $this->options->outputInterface($this->options, $this->getMatrix());
|
||||
if($this->options->outputType === $this::OUTPUT_CUSTOM){
|
||||
return $this->initCustomOutputInterface();
|
||||
}
|
||||
|
||||
foreach($this::OUTPUT_MODES as $outputInterface => $modes){
|
||||
|
||||
if(in_array($this->options->outputType, $modes, true) && class_exists($outputInterface)){
|
||||
if(in_array($this->options->outputType, $modes)){
|
||||
return new $outputInterface($this->options, $this->getMatrix());
|
||||
}
|
||||
|
||||
@@ -182,6 +182,24 @@ class QRCode{
|
||||
throw new QRCodeOutputException('invalid output type');
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes a custom output module after checking the existence of the class and if it implemnts the required interface
|
||||
*
|
||||
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
||||
*/
|
||||
protected function initCustomOutputInterface():QROutputInterface{
|
||||
|
||||
if(!class_exists($this->options->outputInterface)){
|
||||
throw new QRCodeOutputException('invalid custom output module');
|
||||
}
|
||||
|
||||
if(!in_array(QROutputInterface::class, class_implements($this->options->outputInterface))){
|
||||
throw new QRCodeOutputException('custom output module does not implement QROutputInterface');
|
||||
}
|
||||
|
||||
return new $this->options->outputInterface($this->options, $this->getMatrix());
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if a string qualifies as numeric (convenience method)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user