RedisTicketStore::addTicket()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
declare(strict_types=1);
25
26
namespace SimpleSAML\Module\casserver\Cas\Ticket;
27
28
use SimpleSAML\Configuration;
29
use SimpleSAML\Store\RedisStore;
30
31
class RedisTicketStore extends TicketStore
32
{
33
    /** @var string $prefix */
34
    private string $prefix = '';
35
36
    /** @var \SimpleSAML\Store\RedisStore $redis */
37
    private RedisStore $redis;
38
39
40
    /**
41
     * @param \SimpleSAML\Configuration $config
42
     */
43
    public function __construct(Configuration $config)
44
    {
45
        parent::__construct($config);
46
47
        $storeConfig = $config->getOptionalValue('ticketstore', []);
48
49
        if (array_key_exists('prefix', $storeConfig)) {
50
            $this->prefix = $storeConfig['prefix'];
51
        }
52
53
        $this->redis = new RedisStore();
54
    }
55
56
57
    /**
58
     * @param string $ticketId
59
     * @return array|null
60
     */
61
    public function getTicket(string $ticketId): ?array
62
    {
63
        return $this->redis->get($this->prefix, $ticketId);
64
    }
65
66
67
    /**
68
     * @param array $ticket
69
     */
70
    public function addTicket(array $ticket): void
71
    {
72
        $this->redis->set($this->prefix, $ticket['id'], $ticket, $ticket['validBefore']);
73
    }
74
75
76
    /**
77
     * @param string $ticketId
78
     */
79
    public function deleteTicket(string $ticketId): void
80
    {
81
        $this->redis->delete($this->prefix, $ticketId);
82
    }
83
}
84