1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the tiqr project. |
5
|
|
|
* |
6
|
|
|
* The tiqr project aims to provide an open implementation for |
7
|
|
|
* authentication using mobile devices. It was initiated by |
8
|
|
|
* SURFnet and developed by Egeniq. |
9
|
|
|
* |
10
|
|
|
* More information: http://www.tiqr.org |
11
|
|
|
* |
12
|
|
|
* @author Ivo Jansch <[email protected]> |
13
|
|
|
* |
14
|
|
|
* @package tiqr |
15
|
|
|
* |
16
|
|
|
* @license New BSD License - See LICENSE file for details. |
17
|
|
|
* |
18
|
|
|
* @copyright (C) 2010-2011 SURFnet BV |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @internal includes |
24
|
|
|
*/ |
25
|
1 |
|
require_once("Tiqr/StateStorage/Abstract.php"); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Utility class to create specific StateStorage instances. |
29
|
|
|
* StateStorage is used to store temporary information used during |
30
|
|
|
* enrollment and authentication sessions. |
31
|
|
|
* @author ivo |
32
|
|
|
* |
33
|
|
|
*/ |
34
|
|
|
class Tiqr_StateStorage |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Get a storage of a certain type (default: 'file') |
38
|
|
|
* @param String $type The type of storage to create. Supported |
39
|
|
|
* types are 'file' and 'memcache'. |
40
|
|
|
* @param array $options The options to pass to the storage |
41
|
|
|
* instance. See the documentation |
42
|
|
|
* in the StateStorage/ subdirectory for |
43
|
|
|
* options per type. |
44
|
|
|
* @throws Exception If an unknown type is requested. |
45
|
|
|
*/ |
46
|
7 |
|
public static function getStorage($type="file", $options=array()) |
47
|
|
|
{ |
48
|
7 |
|
switch ($type) { |
49
|
7 |
|
case "file": |
50
|
5 |
|
require_once("Tiqr/StateStorage/File.php"); |
51
|
5 |
|
$instance = new Tiqr_StateStorage_File($options); |
52
|
5 |
|
break; |
53
|
2 |
|
case "memcache": |
54
|
|
|
require_once("Tiqr/StateStorage/Memcache.php"); |
55
|
|
|
$instance = new Tiqr_StateStorage_Memcache($options); |
56
|
|
|
break; |
57
|
2 |
|
case "pdo": |
58
|
1 |
|
require_once("Tiqr/StateStorage/Pdo.php"); |
59
|
1 |
|
$instance = new Tiqr_StateStorage_Pdo($options); |
60
|
1 |
|
break; |
61
|
|
|
default: |
62
|
1 |
|
if (!isset($type)) { |
63
|
|
|
throw new Exception('Class name not set'); |
64
|
1 |
|
} elseif (!class_exists($type)) { |
65
|
1 |
|
throw new Exception('Class not found: ' . var_export($type, TRUE)); |
66
|
|
|
} elseif (!is_subclass_of($type, 'Tiqr_StateStorage_Abstract')) { |
67
|
|
|
throw new Exception('Class ' . $type . ' not subclass of Tiqr_StateStorage_Abstract'); |
68
|
|
|
} |
69
|
|
|
$instance = new $type($options); |
70
|
|
|
} |
71
|
|
|
|
72
|
6 |
|
$instance->init(); |
73
|
6 |
|
return $instance; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|