Skip to content

Commit dc1c337

Browse files
committed
:octocat: allow options iterable
1 parent 92e5721 commit dc1c337

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Authenticator.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use chillerlan\Authenticator\Authenticators\AuthenticatorInterface;
1515
use chillerlan\Settings\SettingsContainerInterface;
1616
use SensitiveParameter;
17+
use function is_iterable;
1718

1819
/**
1920
* Yet another Google authenticator implementation!
@@ -36,7 +37,7 @@ class Authenticator{
3637
* Authenticator constructor
3738
*/
3839
public function __construct(
39-
SettingsContainerInterface|AuthenticatorOptions $options = new AuthenticatorOptions,
40+
SettingsContainerInterface|AuthenticatorOptions|iterable $options = new AuthenticatorOptions,
4041
#[SensitiveParameter] string|null $secret = null,
4142
){
4243
// phpcs:ignore
@@ -54,7 +55,12 @@ public function __construct(
5455
* Please note that this will reset the secret phrase stored with the authenticator instance
5556
* if a different mode than the current is given.
5657
*/
57-
public function setOptions(SettingsContainerInterface|AuthenticatorOptions $options):static{
58+
public function setOptions(SettingsContainerInterface|AuthenticatorOptions|iterable $options):static{
59+
60+
if(is_iterable($options)){
61+
$options = new AuthenticatorOptions($options); // @codeCoverageIgnore
62+
}
63+
5864
$this->options = $options;
5965

6066
// invoke a new authenticator interface if necessary

src/Authenticators/AuthenticatorAbstract.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use RuntimeException;
1919
use SensitiveParameter;
2020
use function http_build_query;
21+
use function is_iterable;
2122
use function random_bytes;
2223
use function rawurlencode;
2324
use function sprintf;
@@ -37,11 +38,16 @@ abstract class AuthenticatorAbstract implements AuthenticatorInterface{
3738
/**
3839
* AuthenticatorInterface constructor
3940
*/
40-
public function __construct(SettingsContainerInterface|AuthenticatorOptions $options = new AuthenticatorOptions){
41+
public function __construct(SettingsContainerInterface|AuthenticatorOptions|iterable $options = new AuthenticatorOptions){
4142
$this->setOptions($options);
4243
}
4344

44-
public function setOptions(SettingsContainerInterface $options):static{
45+
public function setOptions(SettingsContainerInterface|AuthenticatorOptions|iterable $options):static{
46+
47+
if(is_iterable($options)){
48+
$options = new AuthenticatorOptions($options);
49+
}
50+
4551
$this->options = $options;
4652

4753
return $this;

0 commit comments

Comments
 (0)