1 | <?php |
||
21 | class Api |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * JWT helper class instance |
||
26 | * @var \gplcart\modules\oauth\helpers\Jwt $jwt |
||
27 | */ |
||
28 | protected $jwt; |
||
29 | |||
30 | /** |
||
31 | * User model class instance |
||
32 | * @var \gplcart\modules\api\models\User $user |
||
33 | */ |
||
34 | protected $user; |
||
35 | |||
36 | /** |
||
37 | * Server helper class instance |
||
38 | * @var \gplcart\core\helpers\Server $server |
||
39 | */ |
||
40 | protected $server; |
||
41 | |||
42 | /** |
||
43 | * Module class instance |
||
44 | * @var \gplcart\core\Module $module |
||
45 | */ |
||
46 | protected $module; |
||
47 | |||
48 | /** |
||
49 | * @param Module $module |
||
50 | * @param Server $server |
||
51 | * @param User $user |
||
52 | * @param Jwt $jwt |
||
53 | */ |
||
54 | public function __construct(Module $module, Server $server, User $user, Jwt $jwt) |
||
61 | |||
62 | /** |
||
63 | * Returns encoded JWT token |
||
64 | * @param int $user_id |
||
65 | * @return array |
||
66 | */ |
||
67 | public function getToken($user_id) |
||
87 | |||
88 | /** |
||
89 | * Returns an array of user data from the token |
||
90 | * @param string $token |
||
91 | * @return array |
||
92 | * @throws UnexpectedValueException |
||
93 | * @throws InvalidArgumentException |
||
94 | */ |
||
95 | public function getUserFromToken($token) |
||
111 | |||
112 | /** |
||
113 | * Returns the secret key from the module settings |
||
114 | * @return string |
||
115 | * @throws InvalidArgumentException |
||
116 | */ |
||
117 | public function getSecret() |
||
127 | |||
128 | /** |
||
129 | * Returns the hashing algorithm from the module settings |
||
130 | * @return string |
||
131 | * @throws InvalidArgumentException |
||
132 | */ |
||
133 | public function getAlg() |
||
143 | |||
144 | /** |
||
145 | * Returns the token lifetime |
||
146 | * @return int |
||
147 | */ |
||
148 | public function getLifetime() |
||
152 | |||
153 | /** |
||
154 | * Whether API access is allowed |
||
155 | * @return bool |
||
156 | */ |
||
157 | public function getStatus() |
||
161 | } |
||
162 |