Completed
Push — master ( af89b1...61c24d )
by recca
03:07
created

LaravelSession::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Recca0120\Elfinder;
4
5
use elFinderSessionInterface;
6
use Illuminate\Session\SessionManager;
7
8
class LaravelSession implements elFinderSessionInterface
9
{
10
    /**
11
     * $session.
12
     *
13
     * @var \Illuminate\Session\SessionInterface
14
     */
15
    protected $session;
16
17
    /**
18
     * __construct.
19
     *
20
     * @param \Illuminate\Session\SessionManager $sessionManager
21
     */
22 6
    public function __construct(SessionManager $sessionManager)
23
    {
24 6
        $this->session = $sessionManager->driver();
25 6
    }
26
27
    /**
28
     * Session start.
29
     *
30
     * @return $this
31
     **/
32 1
    public function start()
33
    {
34 1
        if ($this->session->isStarted() === false) {
35 1
            $this->session->start();
36 1
        }
37
38 1
        return $this;
39
    }
40
41
    /**
42
     * Session write & close.
43
     *
44
     * @return $this
45
     **/
46 1
    public function close()
47
    {
48 1
        if ($this->session->isStarted() === true) {
49 1
            $this->session->save();
50 1
        }
51
52 1
        return $this;
53
    }
54
55
    /**
56
     * Get session data.
57
     *
58
     * This method must be equipped with an automatic start / close.
59
     *
60
     * @param string $key
61
     * @param mixed $default
62
     * @return mixed
63
     **/
64 1
    public function get($key, $default = '')
65
    {
66 1
        return $this->session->get($key, $default);
67
    }
68
69
    /**
70
     * Set session data.
71
     *
72
     * This method must be equipped with an automatic start / close.
73
     *
74
     * @param string $key
75
     * @param mixed $data
76
     * @return $this
77
     **/
78 1
    public function set($key, $data)
79
    {
80 1
        $this->session->put($key, $data);
81
82 1
        return $this;
83
    }
84
85
    /**
86
     * Get session data.
87
     *
88
     * @param string $key
89
     * @return $this
90
     **/
91 1
    public function remove($key)
92
    {
93 1
        $this->session->remove($key);
94
95 1
        return $this;
96
    }
97
}
98