:octocat: allow invocation with options iterable for the public facing classes

This commit is contained in:
smiley
2025-11-17 18:38:10 +01:00
parent 490cc43b47
commit d0462ee466
7 changed files with 35 additions and 14 deletions
+8 -1
View File
@@ -28,8 +28,15 @@ require_once __DIR__.'/../vendor/autoload.php';
class QRGdRounded extends QRGdImagePNG{
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
public function __construct(SettingsContainerInterface|QROptions|iterable $options, QRMatrix $matrix){
if(is_iterable($options)){
$options = new QROptions($options);
}
// enable the internal scaling for better rounding results at scale < 20
// we need to do this before calling the parent constructor as these values are used there
$options->gdImageUseUpscale = true;
$options->drawCircularModules = true;
parent::__construct($options, $matrix);
+7 -2
View File
@@ -18,7 +18,7 @@ use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Hanzi, Kanji, Number};
use chillerlan\QRCode\Detector\Detector;
use chillerlan\Settings\SettingsContainerInterface;
use Throwable;
use function chr, str_replace;
use function chr, is_iterable, str_replace;
/**
* The main class which implements QR Code decoding -- as opposed to locating and extracting
@@ -36,7 +36,12 @@ final class Decoder{
private BitBuffer $bitBuffer;
private Detector $detector;
public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){
public function __construct(SettingsContainerInterface|QROptions|iterable $options = new QROptions){
if(is_iterable($options)){
$options = new QROptions($options);
}
$this->options = $options;
}
+1 -1
View File
@@ -39,7 +39,7 @@ class QRFpdf extends QROutputAbstract{
*
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
*/
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
public function __construct(SettingsContainerInterface|QROptions|iterable $options, QRMatrix $matrix){
if(!class_exists(FPDF::class)){
// @codeCoverageIgnoreStart
+9 -5
View File
@@ -17,10 +17,9 @@ use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\Settings\SettingsContainerInterface;
use GdImage;
use function extension_loaded, imagecolorallocate, imagecolortransparent,
imagecreatetruecolor, imagefilledellipse, imagefilledrectangle,
imagescale, imagetypes, intdiv, intval, max, min, ob_end_clean, ob_get_contents, ob_start,
sprintf;
use function extension_loaded, imagecolorallocate, imagecolortransparent, imagecreatetruecolor,
imagefilledellipse, imagefilledrectangle, imagescale, imagetypes, intdiv, intval, is_iterable,
max, min, ob_end_clean, ob_get_contents, ob_start, sprintf;
use const IMG_AVIF, IMG_BMP, IMG_GIF, IMG_JPG, IMG_PNG, IMG_WEBP;
/**
@@ -57,7 +56,12 @@ abstract class QRGdImage extends QROutputAbstract{
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
* @noinspection PhpMissingParentConstructorInspection
*/
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
public function __construct(SettingsContainerInterface|QROptions|iterable $options, QRMatrix $matrix){
if(is_iterable($options)){
$options = new QROptions($options);
}
$this->options = $options;
$this->matrix = $matrix;
+1 -1
View File
@@ -47,7 +47,7 @@ class QRImagick extends QROutputAbstract{
*
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
*/
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
public function __construct(SettingsContainerInterface|QROptions|iterable $options, QRMatrix $matrix){
foreach(['fileinfo', 'imagick'] as $ext){
if(!extension_loaded($ext)){
+1 -1
View File
@@ -48,7 +48,7 @@ class QRInterventionImage extends QROutputAbstract{
*
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
*/
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
public function __construct(SettingsContainerInterface|QROptions|iterable $options, QRMatrix $matrix){
if(!class_exists(ImageManager::class)){
// @codeCoverageIgnoreStart
+8 -3
View File
@@ -17,7 +17,7 @@ use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\Settings\SettingsContainerInterface;
use finfo;
use function base64_encode, dirname, extension_loaded, file_put_contents, is_writable, ksort, sprintf;
use function base64_encode, dirname, extension_loaded, file_put_contents, is_iterable, is_writable, ksort, sprintf;
use const FILEINFO_MIME_TYPE;
/**
@@ -81,7 +81,12 @@ abstract class QROutputAbstract implements QROutputInterface{
/**
* QROutputAbstract constructor.
*/
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
public function __construct(SettingsContainerInterface|QROptions|iterable $options, QRMatrix $matrix){
if(is_iterable($options)){
$options = new QROptions($options);
}
$this->options = $options;
$this->matrix = $matrix;
@@ -95,7 +100,7 @@ abstract class QROutputAbstract implements QROutputInterface{
}
/**
* Creates copies of several QROptions values to avoid calling the magic getters
* Creates copies of several QROptions values to avoid calling the magic getters/property hooks
* in long loops for a significant performance increase.
*
* These variables are usually used in the "module" methods and are called up to 31329 times (at version 40).