SessionSection::__get()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
/**
3
 * SessionSection.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        http://www.ipublikuj.eu
7
 * @author         Adam Kadlec http://www.ipublikuj.eu
8
 * @package        iPublikuj:WebSocketSession!
9
 * @subpackage     Session
10
 * @since          1.0.0
11
 *
12
 * @date           23.02.17
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\WebSocketsSession\Session;
18
19
use Nette\Http;
20
21
use IPub;
22
use IPub\WebSocketsSession\Exceptions;
23
24
/**
25
 * WebSocket connection session section for user storage
26
 *
27
 * @package        iPublikuj:WebSocketSession!
28
 * @subpackage     Session
29
 *
30
 * @author         Adam Kadlec <[email protected]>
31
 */
32
class SessionSection extends Http\SessionSection
33
{
34
	/**
35
	 * @var string
36
	 */
37
	private $name;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
38
39
	/**
40
	 * @var SwitchableSession
41
	 */
42
	private $session;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
43
44
	/**
45
	 * @param SwitchableSession $session
46
	 * @param $name
47
	 */
48
	public function __construct(SwitchableSession $session, $name)
49
	{
50
		parent::__construct($session, $name);
51
52
		$this->session = $session;
53
		$this->name = $name;
54
	}
55
56
	/**
57
	 * @return \ArrayIterator
58
	 */
59
	public function getIterator() : \ArrayIterator
60
	{
61
		$data = $this->start();
62
63
		return new \ArrayIterator($data);
64
	}
65
66
	/**
67
	 * @param string $name
68
	 * @param mixed $value
69
	 *
70
	 * @return void
71
	 */
72
	public function __set($name, $value)
73
	{
74
		//
75
	}
76
77
	/**
78
	 * @param string $name
79
	 *
80
	 * @return mixed
81
	 */
82
	public function &__get($name)
83
	{
84
		$data = $this->start();
85
86
		if ($this->warnOnUndefined && !array_key_exists($name, $data)) {
87
			trigger_error(sprintf('The variable "%s" does not exist in session section', $name), E_USER_NOTICE);
88
		}
89
90
		return $data[$name];
91
	}
92
93
	/**
94
	 * @param string $name
95
	 *
96
	 * @return bool
97
	 */
98
	public function __isset($name)
99
	{
100
		$data = $this->start();
101
102
		return isset($data[$name]);
103
	}
104
105
	/**
106
	 * @param string $name
107
	 *
108
	 * @return void
109
	 *
110
	 * @throws Exceptions\NotImplementedException
111
	 */
112
	public function __unset($name)
113
	{
114
		//
115
	}
116
117
	/**
118
	 * @param \DateTimeInterface|int|string $time
119
	 * @param string|array|NULL $variables
120
	 *
121
	 * @return void
122
	 */
123
	public function setExpiration($time, $variables = NULL)
124
	{
125
		//
126
	}
127
128
	/**
129
	 * @param string|array|NULL $variables
130
	 *
131
	 * @return void
132
	 */
133
	public function removeExpiration($variables = NULL)
134
	{
135
		//
136
	}
137
138
	/**
139
	 * @return void
140
	 */
141
	public function remove()
142
	{
143
		//
144
	}
145
146
	/**
147
	 * @return array
148
	 */
149
	protected function start() : array
150
	{
151
		$this->session->start();
152
153
		return $this->session->getData($this->name);
154
	}
155
}
156