Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
LoggedInUserMode | |
0.00% |
0 / 3 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
getModeIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MobileFrontend\Features; |
4 | |
5 | use MediaWiki\User\User; |
6 | |
7 | /** |
8 | * An easy way to enable features only for logged in users. |
9 | * This class is an Adapter for the User object to fulfill FeaturesManager requirements. |
10 | * Instead of hardcoding ` if ( $user->isRegistered() ) { ` logic in each feature code, |
11 | * we can re-use this mode and have `isRegistered` check only in one place for all features. |
12 | * |
13 | * To use it please define feature like that: |
14 | * |
15 | * $wgMFMyNewFeature => [ |
16 | * ... |
17 | * 'loggedin' => true, |
18 | * ]; |
19 | * |
20 | * @package MobileFrontend\Features |
21 | */ |
22 | class LoggedInUserMode implements IUserMode { |
23 | |
24 | /** |
25 | * @var User |
26 | */ |
27 | private $user; |
28 | |
29 | /** |
30 | * @param User $user |
31 | */ |
32 | public function __construct( User $user ) { |
33 | $this->user = $user; |
34 | } |
35 | |
36 | /** |
37 | * @inheritDoc |
38 | */ |
39 | public function isEnabled() { |
40 | return $this->user->isSafeToLoad() && $this->user->isRegistered(); |
41 | } |
42 | |
43 | /** |
44 | * @inheritDoc |
45 | */ |
46 | public function getModeIdentifier() { |
47 | return 'loggedin'; |
48 | } |
49 | } |