Completed
Push — master ( 636f13...7ce75f )
by Dmitry
02:00
created

JWTOptions::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace UAPAY;
4
5
use UAPAY\Exception;
6
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()
72
    {
73
        return $this->jwt;
74
    }
75
}
76