Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UserModes | |
0.00% |
0 / 5 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
registerMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMode | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getIterator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MobileFrontend\Features; |
4 | |
5 | use ArrayIterator; |
6 | use IteratorAggregate; |
7 | use Traversable; |
8 | |
9 | /** |
10 | * User Modes collection |
11 | * |
12 | * This class exists to provide a safe collection of IUserModes |
13 | * @package MobileFrontend\Features |
14 | */ |
15 | class UserModes implements IteratorAggregate { |
16 | |
17 | /** |
18 | * @var array<string,IUserMode> |
19 | */ |
20 | private $modes = []; |
21 | |
22 | /** |
23 | * Register new User Mode |
24 | * @param IUserMode $mode |
25 | */ |
26 | public function registerMode( IUserMode $mode ) { |
27 | $this->modes[$mode->getModeIdentifier()] = $mode; |
28 | } |
29 | |
30 | /** |
31 | * Retrieve registered mode |
32 | * |
33 | * @param string $modeIdentifier |
34 | * @return IUserMode |
35 | */ |
36 | public function getMode( $modeIdentifier ) { |
37 | if ( !array_key_exists( $modeIdentifier, $this->modes ) ) { |
38 | throw new \RuntimeException( "$modeIdentifier User mode is undefined" ); |
39 | } |
40 | return $this->modes[$modeIdentifier]; |
41 | } |
42 | |
43 | /** |
44 | * @return ArrayIterator |
45 | */ |
46 | public function getIterator(): Traversable { |
47 | return new ArrayIterator( $this->modes ); |
48 | } |
49 | |
50 | } |