1 | <?php |
||
18 | class User extends \yii\web\User |
||
19 | { |
||
20 | public $isGuestAllowed = false; |
||
21 | |||
22 | /** |
||
23 | * @var string the seller login |
||
24 | */ |
||
25 | public $seller; |
||
26 | |||
27 | public function init() |
||
28 | { |
||
29 | parent::init(); |
||
30 | if (empty($this->seller)) { |
||
31 | throw new InvalidConfigException('User "seller" must be set'); |
||
32 | } |
||
33 | } |
||
34 | |||
35 | public function not($key) |
||
36 | { |
||
37 | $identity = $this->getIdentity(); |
||
38 | if (!$identity) { |
||
|
|||
39 | throw new InvalidCallException(); |
||
40 | } |
||
41 | |||
42 | return $identity->not($key); |
||
43 | } |
||
44 | |||
45 | public function is($key) |
||
46 | { |
||
47 | $identity = $this->getIdentity(); |
||
48 | if (!$identity) { |
||
49 | throw new InvalidCallException(); |
||
50 | } |
||
51 | |||
52 | return $identity->is($key); |
||
53 | } |
||
54 | /** |
||
55 | * @inheritdoc |
||
56 | * XXX fixes redirect loop when identity is set but the object is empty |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function getIsGuest() |
||
63 | |||
64 | /** |
||
65 | * Prepares authorization data. |
||
66 | * Redirects to authorization if necessary. |
||
67 | * @return array |
||
68 | */ |
||
69 | public function getAuthData() |
||
91 | |||
92 | public function redirectLogin() |
||
97 | } |
||
98 |
If an expression can have both
false
, andnull
as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.