1 | <?php |
||
15 | class SessionStorage |
||
16 | { |
||
17 | use \Teto\Object\PrivateGetter; |
||
18 | |||
19 | /** @var AuthFactory */ |
||
20 | private $auth_factory; |
||
21 | /** @var Scope */ |
||
22 | private $scope; |
||
23 | /** @var Authorization */ |
||
24 | private $authorization; |
||
25 | |||
26 | /** |
||
27 | * @param AuthFactory $auth_factory |
||
28 | * @param Scope $scope |
||
29 | */ |
||
30 | 2 | public function __construct(AuthFactory $auth_factory, Scope $scope) |
|
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | 1 | public function getAccessToken() |
|
40 | { |
||
41 | 1 | $this->authorize(); |
|
42 | |||
43 | 1 | return $this->authorization->access_token; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param bool $force |
||
48 | * @return Authorization |
||
49 | */ |
||
50 | 1 | public function authorize($force = false) |
|
51 | { |
||
52 | 1 | if ($force || $this->authorization === null) { |
|
53 | $this->authorization = $this->auth_factory->authorize($this->scope); |
||
54 | } |
||
55 | |||
56 | 1 | return $this->authorization; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param Authorization $authorization |
||
61 | * @return void |
||
62 | */ |
||
63 | 2 | public function setAuthorization(Authorization $authorization) |
|
67 | } |
||
68 |