Skip to content

Commit eb590f6

Browse files
committed
:octocat: QRCode constructor: accept iterable as options
1 parent d14a3ad commit eb590f6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/QRCode.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use chillerlan\QRCode\Decoder\{Decoder, DecoderResult};
2020
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
2121
use chillerlan\Settings\SettingsContainerInterface;
22-
use function class_exists, class_implements, in_array, mb_convert_encoding, mb_internal_encoding;
22+
use function class_exists, class_implements, in_array, is_iterable, mb_convert_encoding, mb_internal_encoding;
2323

2424
/**
2525
* Turns a text string into a Model 2 QR Code
@@ -51,17 +51,20 @@ class QRCode{
5151

5252
/**
5353
* QRCode constructor.
54-
*
55-
* PHP8: accept iterable
5654
*/
57-
public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){
55+
public function __construct(SettingsContainerInterface|QROptions|iterable $options = new QROptions){
5856
$this->setOptions($options);
5957
}
6058

6159
/**
6260
* Sets an options instance
6361
*/
64-
public function setOptions(SettingsContainerInterface|QROptions $options):static{
62+
public function setOptions(SettingsContainerInterface|QROptions|iterable $options):static{
63+
64+
if(is_iterable($options)){
65+
$options = new QROptions($options);
66+
}
67+
6568
$this->options = $options;
6669

6770
if($this->options->readerUseImagickIfAvailable){
@@ -265,17 +268,13 @@ public function addEciSegment(int $encoding, string $data):static{
265268

266269
/**
267270
* Reads a QR Code from a given file
268-
*
269-
* @noinspection PhpUndefinedMethodInspection
270271
*/
271272
public function readFromFile(string $path):DecoderResult{
272273
return $this->readFromSource($this->luminanceSourceFQN::fromFile($path, $this->options));
273274
}
274275

275276
/**
276277
* Reads a QR Code from the given data blob
277-
*
278-
* @noinspection PhpUndefinedMethodInspection
279278
*/
280279
public function readFromBlob(string $blob):DecoderResult{
281280
return $this->readFromSource($this->luminanceSourceFQN::fromBlob($blob, $this->options));

0 commit comments

Comments
 (0)