Passed
Push — master ( 1c7137...b5ef5e )
by Pieter van der
03:26 queued 14s
created

Tiqr_DeviceStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getStorage() 0 20 4
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
require_once("Tiqr/DeviceStorage/Abstract.php");
25
26
/**
27
 * A utility class to create an instance of a specific type of storage that 
28
 * can retrieve deviceTokens.
29
 * @author ivo
30
 */
31
class Tiqr_DeviceStorage
32
{
33
    /**
34
     * Return a storage instance of a certain type.
35
     * Supported types are dummy: stores the device token 
36
     * @param String $type The type of storage to return. Supported are:
37
     *                     - dummy: treats a notificationToken as a deviceToken
38
     *                     - tokenexchange: uses a tokenexchange service to 
39
     *                       exchange notificationTokens for deviceTokens. 
40
     * @param array $options Options for the device storage. See the
41
     *                       documentation in DeviceStorage/ for specific 
42
     *                       config options per type.
43
     * @throws Exception An exception if an unknown storage is requested.
44
     */
45
    public static function getStorage($type="dummy", $options=array())
46
    {
47
        switch ($type) {
48
            case "dummy":
49
                require_once("Tiqr/DeviceStorage/Dummy.php");
50
                $instance = new Tiqr_DeviceStorage_Dummy($options);
51
                break;
52
            case "tokenexchange":
53
                require_once("Tiqr/DeviceStorage/TokenExchange.php");
54
                $instance = new Tiqr_DeviceStorage_TokenExchange($options);           
55
                break;
56
 
57
            default:
58
                $instance = NULL;
59
        }
60
        if ($instance!=NULL) {
61
            $instance->init();
62
            return $instance;
63
        }
64
        throw new Exception("Unknown device storage type");
65
    }
66
}