Completed
Push — master ( 0ca4f0...992805 )
by Damien
07:27
created

Session::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 */
6
7
namespace flipbox\saml\core\services;
8
9
use craft\base\Component;
10
11
class Session extends Component
12
{
13
    const CORE_NAMESPACE = 'saml.core';
14
    const REQUEST_ID_KEY = 'request.id';
15
    const HASH_ALGO = 'sha256';
16
17
    /**
18
     * @param $id
19
     */
20
    public function setRequestId($id)
21
    {
22
        \Craft::$app->getSession()->set(
23
            $this->getName(static::REQUEST_ID_KEY),
24
            $id
25
        );
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getRequestId()
32
    {
33
        return \Craft::$app->getSession()->get(
34
            $this->getName(static::REQUEST_ID_KEY)
35
        );
36
    }
37
    
38
    /**
39
     * @return string
40
     */
41
    public function getId()
42
    {
43
        return hash(static::HASH_ALGO, \Craft::$app->session->getId());
44
    }
45
46
    /**
47
     * @param $key
48
     * @return string
49
     */
50
    protected function getName($key)
51
    {
52
        return static::CORE_NAMESPACE . '/' . $key;
53
    }
54
55
}
56