|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the tiqr project. |
|
4
|
|
|
* |
|
5
|
|
|
* The tiqr project aims to provide an open implementation for |
|
6
|
|
|
* authentication using mobile devices. It was initiated by |
|
7
|
|
|
* SURFnet and developed by Egeniq. |
|
8
|
|
|
* |
|
9
|
|
|
* More information: http://www.tiqr.org |
|
10
|
|
|
* |
|
11
|
|
|
* @author Ivo Jansch <[email protected]> |
|
12
|
|
|
* |
|
13
|
|
|
* @package tiqr |
|
14
|
|
|
* |
|
15
|
|
|
* @license New BSD License - See LICENSE file for details. |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright (C) 2010-2011 SURFnet BV |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @internal includes |
|
23
|
|
|
*/ |
|
24
|
1 |
|
require_once("Tiqr/DeviceStorage/Abstract.php"); |
|
25
|
|
|
|
|
26
|
|
|
use Psr\Log\LoggerInterface; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* A utility class to create an instance of a specific type of storage that |
|
30
|
|
|
* can retrieve deviceTokens. |
|
31
|
|
|
* @author ivo |
|
32
|
|
|
*/ |
|
33
|
|
|
class Tiqr_DeviceStorage |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Return a storage instance of a certain type. |
|
37
|
|
|
* Supported types are dummy: stores the device token |
|
38
|
|
|
* @param String $type The type of storage to return. Supported are: |
|
39
|
|
|
* - dummy: treats a notificationToken as a deviceToken |
|
40
|
|
|
* - tokenexchange: uses a tokenexchange service to |
|
41
|
|
|
* exchange notificationTokens for deviceTokens. |
|
42
|
|
|
* @param array $options Options for the device storage. See the |
|
43
|
|
|
* documentation in DeviceStorage/ for specific |
|
44
|
|
|
* config options per type. |
|
45
|
|
|
* @param LoggerInterface $logger |
|
46
|
|
|
* @throws Exception An exception if an unknown storage is requested. |
|
47
|
|
|
*/ |
|
48
|
7 |
|
public static function getStorage($type="dummy", $options=array(), LoggerInterface $logger) |
|
49
|
|
|
{ |
|
50
|
7 |
|
switch ($type) { |
|
51
|
7 |
|
case "dummy": |
|
52
|
5 |
|
require_once("Tiqr/DeviceStorage/Dummy.php"); |
|
53
|
5 |
|
$instance = new Tiqr_DeviceStorage_Dummy($options, $logger); |
|
54
|
5 |
|
$instance->init(); |
|
55
|
5 |
|
return $instance; |
|
56
|
2 |
|
case "tokenexchange": |
|
57
|
1 |
|
require_once("Tiqr/DeviceStorage/TokenExchange.php"); |
|
58
|
1 |
|
$instance = new Tiqr_DeviceStorage_TokenExchange($options, $logger); |
|
59
|
1 |
|
$instance->init(); |
|
60
|
1 |
|
return $instance; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
throw new RuntimeException(sprintf('Unable to create a DeviceStorage instance of type: %s', $type)); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|