Completed
Push — master ( ec84da...cd9330 )
by Robbie
11s
created
src/HybridSession.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -9,164 +9,164 @@
 block discarded – undo
9 9
 class HybridSession extends BaseStore
10 10
 {
11 11
 
12
-    /**
13
-     * List of session handlers
14
-     *
15
-     * @var array
16
-     */
17
-    protected $handlers = [];
18
-
19
-    /**
20
-     * True if this session store has been initialised
21
-     *
22
-     * @var bool
23
-     */
24
-    protected static $enabled = false;
25
-
26
-    /**
27
-     * @param SessionHandlerInterface[]
28
-     *
29
-     * @return $this
30
-     */
31
-    public function setHandlers($handlers)
32
-    {
33
-        $this->handlers = $handlers;
34
-        $this->setKey($this->getKey());
35
-
36
-        return $this;
37
-    }
38
-
39
-    /**
40
-     * @param string
41
-     *
42
-     * @return $this
43
-     */
44
-    public function setKey($key)
45
-    {
46
-        parent::setKey($key);
47
-
48
-        foreach ($this->handlers as $handler) {
49
-            $handler->setKey($key);
50
-        }
51
-
52
-        return $this;
53
-    }
54
-
55
-    /**
56
-     * @return SessionHandlerInterface[]
57
-     */
58
-    public function getHandlers()
59
-    {
60
-        return $this->handlers;
61
-    }
62
-
63
-    /**
64
-     * @param string $save_path
65
-     * @param string $name
66
-     *
67
-     * @return bool
68
-     */
69
-    public function open($save_path, $name)
70
-    {
71
-        if ($this->handlers) {
72
-            foreach ($this->handlers as $handler) {
73
-                $handler->open($save_path, $name);
74
-            }
75
-        }
76
-
77
-        return true;
78
-    }
79
-
80
-    /**
81
-     * @return bool
82
-     */
83
-    public function close()
84
-    {
85
-        if ($this->handlers) {
86
-            foreach ($this->handlers as $handler) {
87
-                $handler->close();
88
-            }
89
-        }
90
-
91
-        return true;
92
-    }
93
-
94
-    /**
95
-     * @param string $session_id
96
-     *
97
-     * @return string
98
-     */
99
-    public function read($session_id)
100
-    {
101
-        if ($this->handlers) {
102
-            foreach ($this->handlers as $handler) {
103
-                if ($data = $handler->read($session_id)) {
104
-                    return $data;
105
-                }
106
-            }
107
-        }
108
-
109
-        return '';
110
-    }
111
-
112
-
113
-    public function write($session_id, $session_data)
114
-    {
115
-        $result = false;
116
-        if ($this->handlers) {
117
-            foreach ($this->handlers as $handler) {
118
-                if ($handler->write($session_id, $session_data)) {
119
-                    $result = true;
120
-                }
121
-            }
122
-        }
123
-        return $result;
124
-    }
125
-
126
-    public function destroy($session_id)
127
-    {
128
-        if ($this->handlers) {
129
-            foreach ($this->handlers as $handler) {
130
-                $handler->destroy($session_id);
131
-            }
132
-        }
133
-        return true;
134
-    }
135
-
136
-    public function gc($maxlifetime)
137
-    {
138
-        if ($this->handlers) {
139
-            foreach ($this->handlers as $handler) {
140
-                $handler->gc($maxlifetime);
141
-            }
142
-        }
143
-    }
144
-
145
-    /**
146
-     * Register the session handler as the default
147
-     *
148
-     * @param string $key Desired session key
149
-     */
150
-    public static function init($key = null)
151
-    {
152
-        $instance = Injector::inst()->get(__CLASS__);
153
-
154
-        if (empty($key)) {
155
-            user_error(
156
-                'HybridSession::init() was not given a $key. Disabling cookie-based storage',
157
-                E_USER_WARNING
158
-            );
159
-        } else {
160
-            $instance->setKey($key);
161
-        }
162
-
163
-        session_set_save_handler($instance, true);
164
-
165
-        self::$enabled = true;
166
-    }
167
-
168
-    public static function is_enabled()
169
-    {
170
-        return self::$enabled;
171
-    }
12
+	/**
13
+	 * List of session handlers
14
+	 *
15
+	 * @var array
16
+	 */
17
+	protected $handlers = [];
18
+
19
+	/**
20
+	 * True if this session store has been initialised
21
+	 *
22
+	 * @var bool
23
+	 */
24
+	protected static $enabled = false;
25
+
26
+	/**
27
+	 * @param SessionHandlerInterface[]
28
+	 *
29
+	 * @return $this
30
+	 */
31
+	public function setHandlers($handlers)
32
+	{
33
+		$this->handlers = $handlers;
34
+		$this->setKey($this->getKey());
35
+
36
+		return $this;
37
+	}
38
+
39
+	/**
40
+	 * @param string
41
+	 *
42
+	 * @return $this
43
+	 */
44
+	public function setKey($key)
45
+	{
46
+		parent::setKey($key);
47
+
48
+		foreach ($this->handlers as $handler) {
49
+			$handler->setKey($key);
50
+		}
51
+
52
+		return $this;
53
+	}
54
+
55
+	/**
56
+	 * @return SessionHandlerInterface[]
57
+	 */
58
+	public function getHandlers()
59
+	{
60
+		return $this->handlers;
61
+	}
62
+
63
+	/**
64
+	 * @param string $save_path
65
+	 * @param string $name
66
+	 *
67
+	 * @return bool
68
+	 */
69
+	public function open($save_path, $name)
70
+	{
71
+		if ($this->handlers) {
72
+			foreach ($this->handlers as $handler) {
73
+				$handler->open($save_path, $name);
74
+			}
75
+		}
76
+
77
+		return true;
78
+	}
79
+
80
+	/**
81
+	 * @return bool
82
+	 */
83
+	public function close()
84
+	{
85
+		if ($this->handlers) {
86
+			foreach ($this->handlers as $handler) {
87
+				$handler->close();
88
+			}
89
+		}
90
+
91
+		return true;
92
+	}
93
+
94
+	/**
95
+	 * @param string $session_id
96
+	 *
97
+	 * @return string
98
+	 */
99
+	public function read($session_id)
100
+	{
101
+		if ($this->handlers) {
102
+			foreach ($this->handlers as $handler) {
103
+				if ($data = $handler->read($session_id)) {
104
+					return $data;
105
+				}
106
+			}
107
+		}
108
+
109
+		return '';
110
+	}
111
+
112
+
113
+	public function write($session_id, $session_data)
114
+	{
115
+		$result = false;
116
+		if ($this->handlers) {
117
+			foreach ($this->handlers as $handler) {
118
+				if ($handler->write($session_id, $session_data)) {
119
+					$result = true;
120
+				}
121
+			}
122
+		}
123
+		return $result;
124
+	}
125
+
126
+	public function destroy($session_id)
127
+	{
128
+		if ($this->handlers) {
129
+			foreach ($this->handlers as $handler) {
130
+				$handler->destroy($session_id);
131
+			}
132
+		}
133
+		return true;
134
+	}
135
+
136
+	public function gc($maxlifetime)
137
+	{
138
+		if ($this->handlers) {
139
+			foreach ($this->handlers as $handler) {
140
+				$handler->gc($maxlifetime);
141
+			}
142
+		}
143
+	}
144
+
145
+	/**
146
+	 * Register the session handler as the default
147
+	 *
148
+	 * @param string $key Desired session key
149
+	 */
150
+	public static function init($key = null)
151
+	{
152
+		$instance = Injector::inst()->get(__CLASS__);
153
+
154
+		if (empty($key)) {
155
+			user_error(
156
+				'HybridSession::init() was not given a $key. Disabling cookie-based storage',
157
+				E_USER_WARNING
158
+			);
159
+		} else {
160
+			$instance->setKey($key);
161
+		}
162
+
163
+		session_set_save_handler($instance, true);
164
+
165
+		self::$enabled = true;
166
+	}
167
+
168
+	public static function is_enabled()
169
+	{
170
+		return self::$enabled;
171
+	}
172 172
 }
Please login to merge, or discard this patch.