1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
5
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
12
|
|
|
* @link https://cakephp.org CakePHP(tm) Project |
13
|
|
|
* @since 1.0.0 |
14
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
declare(strict_types=1); |
18
|
|
|
|
19
|
|
|
namespace Phauthentic\Authentication\Authenticator; |
20
|
|
|
|
21
|
|
|
use ArrayIterator; |
22
|
|
|
use Traversable; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Authenticator Collection |
26
|
|
|
*/ |
27
|
|
|
class AuthenticatorCollection implements AuthenticatorCollectionInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* List of authenticators |
31
|
|
|
* |
32
|
|
|
* @var \Phauthentic\Authentication\Authenticator\AuthenticatorInterface[] |
33
|
|
|
*/ |
34
|
|
|
protected array $authenticators = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor |
38
|
56 |
|
* |
39
|
|
|
* @param iterable<\Phauthentic\Authentication\Authenticator\AuthenticatorInterface> $autheticators Authenticators |
40
|
56 |
|
*/ |
41
|
12 |
|
public function __construct(iterable $autheticators = []) |
42
|
|
|
{ |
43
|
56 |
|
foreach ($autheticators as $authenticator) { |
44
|
|
|
$this->add($authenticator); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Returns true if a collection is empty. |
50
|
40 |
|
* |
51
|
|
|
* @return bool |
52
|
40 |
|
*/ |
53
|
|
|
public function isEmpty(): bool |
54
|
|
|
{ |
55
|
|
|
return empty($this->authenticators); |
56
|
|
|
} |
57
|
|
|
|
58
|
52 |
|
/** |
59
|
|
|
* {@inheritDoc} |
60
|
52 |
|
*/ |
61
|
52 |
|
public function add(AuthenticatorInterface $authenticator): void |
62
|
|
|
{ |
63
|
|
|
$this->authenticators[] = $authenticator; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Retrieve an external iterator |
68
|
|
|
* |
69
|
|
|
* @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
70
|
36 |
|
* @return Traversable<\Phauthentic\Authentication\Authenticator\AuthenticatorInterface> |
71
|
|
|
*/ |
72
|
36 |
|
public function getIterator(): Traversable |
73
|
|
|
{ |
74
|
|
|
return new ArrayIterator($this->authenticators); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|