Total Complexity | 7 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
7 | class JWTOptions |
||
8 | { |
||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $jwt = array( |
||
13 | 'using' => false, |
||
14 | 'UAPAY_pubkey' => '', |
||
15 | 'our_privkey' => '', |
||
16 | ); |
||
17 | |||
18 | /** |
||
19 | * Constructor |
||
20 | * |
||
21 | * @param array $options array of options |
||
22 | * @throws Exception\Data |
||
23 | */ |
||
24 | public function __construct($options) |
||
25 | { |
||
26 | if (isset($options['jwt'])) |
||
27 | { |
||
28 | $this->is_valid_using($options); |
||
29 | $this->is_present_option($options, 'UAPAY_pubkey'); |
||
30 | $this->is_present_option($options, 'our_privkey'); |
||
31 | |||
32 | $this->jwt = $options['jwt']; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Check is valid 'using' option |
||
38 | * |
||
39 | * @param array $options |
||
40 | * @throws Exception\Data |
||
41 | */ |
||
42 | protected function is_valid_using($options) |
||
43 | { |
||
44 | $this->is_present_option($options, 'using'); |
||
45 | if ( ! is_bool($options['jwt']['using'])) |
||
46 | { |
||
47 | throw new Exception\Data('parameter jwt/using is incorrect'); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Check is present option |
||
53 | * |
||
54 | * @param array $options |
||
55 | * @param string $name |
||
56 | * @throws Exception\Data |
||
57 | */ |
||
58 | protected function is_present_option($options, $name) |
||
59 | { |
||
60 | if ( ! isset($options['jwt'][$name])) |
||
61 | { |
||
62 | throw new Exception\Data('parameter jwt/'.$name.' is not specified'); |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get jwt options |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | public function get() |
||
74 | } |
||
75 | } |
||
76 |