Passed
Push — master ( 928979...f2daf3 )
by
unknown
03:38
created

__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
/*
4
*    simpleSAMLphp-casserver is a CAS 1.0 and 2.0 compliant CAS server in the form of a simpleSAMLphp module
5
*
6
*    Copyright (C) 2013  Bjorn R. Jensen
7
*
8
*    This library is free software; you can redistribute it and/or
9
*    modify it under the terms of the GNU Lesser General Public
10
*    License as published by the Free Software Foundation; either
11
*    version 2.1 of the License, or (at your option) any later version.
12
*
13
*    This library is distributed in the hope that it will be useful,
14
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
*    Lesser General Public License for more details.
17
*
18
*    You should have received a copy of the GNU Lesser General Public
19
*    License along with this library; if not, write to the Free Software
20
*    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
*
22
*/
23
24
class sspmod_casserver_Cas_Ticket_RedisTicketStore extends sspmod_casserver_Cas_Ticket_TicketStore
25
{
26
    private $prefix = '';
27
    private $redis;
28
29
    public function __construct(\SimpleSAML_Configuration $config)
30
    {
31
        parent::__construct($config);
32
33
        $storeConfig = $config->getValue('ticketstore');
34
35
        if (array_key_exists('prefix', $storeConfig)) {
36
            $this->prefix = $storeConfig['prefix'];
37
        }
38
39
        $this->redis = new \SimpleSAML\Store\Redis();
40
    }
41
42
    /**
43
     * @param $ticketId string
44
     * @return array|null
45
     */
46
    public function getTicket($ticketId)
47
    {
48
        return $this->redis->get($this->prefix, $ticketId);
49
    }
50
51
    public function addTicket(array $ticket)
52
    {
53
        $this->redis->set($this->prefix, $ticket['id'], $ticket, $ticket['validBefore']);
54
    }
55
56
    /**
57
     * @param $ticketId string
58
     */
59
    public function deleteTicket($ticketId)
60
    {
61
        $this->redis->delete($this->prefix, $ticketId);
62
    }
63
}
64