Completed
Push — master ( 056db7...ec84da )
by Robbie
13s
created
src/HybridSession.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -9,162 +9,162 @@
 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
-        if ($this->handlers) {
116
-            foreach ($this->handlers as $handler) {
117
-                if ($handler->write($session_id, $session_data)) {
118
-                    return true;
119
-                }
120
-            }
121
-        }
122
-    }
123
-
124
-    public function destroy($session_id)
125
-    {
126
-        if ($this->handlers) {
127
-            foreach ($this->handlers as $handler) {
128
-                $handler->destroy($session_id);
129
-            }
130
-        }
131
-        return true;
132
-    }
133
-
134
-    public function gc($maxlifetime)
135
-    {
136
-        if ($this->handlers) {
137
-            foreach ($this->handlers as $handler) {
138
-                $handler->gc($maxlifetime);
139
-            }
140
-        }
141
-    }
142
-
143
-    /**
144
-     * Register the session handler as the default
145
-     *
146
-     * @param string $key Desired session key
147
-     */
148
-    public static function init($key = null)
149
-    {
150
-        $instance = Injector::inst()->get(__CLASS__);
151
-
152
-        if (empty($key)) {
153
-            user_error(
154
-                'HybridSession::init() was not given a $key. Disabling cookie-based storage',
155
-                E_USER_WARNING
156
-            );
157
-        } else {
158
-            $instance->setKey($key);
159
-        }
160
-
161
-        session_set_save_handler($instance, true);
162
-
163
-        self::$enabled = true;
164
-    }
165
-
166
-    public static function is_enabled()
167
-    {
168
-        return self::$enabled;
169
-    }
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
+		if ($this->handlers) {
116
+			foreach ($this->handlers as $handler) {
117
+				if ($handler->write($session_id, $session_data)) {
118
+					return true;
119
+				}
120
+			}
121
+		}
122
+	}
123
+
124
+	public function destroy($session_id)
125
+	{
126
+		if ($this->handlers) {
127
+			foreach ($this->handlers as $handler) {
128
+				$handler->destroy($session_id);
129
+			}
130
+		}
131
+		return true;
132
+	}
133
+
134
+	public function gc($maxlifetime)
135
+	{
136
+		if ($this->handlers) {
137
+			foreach ($this->handlers as $handler) {
138
+				$handler->gc($maxlifetime);
139
+			}
140
+		}
141
+	}
142
+
143
+	/**
144
+	 * Register the session handler as the default
145
+	 *
146
+	 * @param string $key Desired session key
147
+	 */
148
+	public static function init($key = null)
149
+	{
150
+		$instance = Injector::inst()->get(__CLASS__);
151
+
152
+		if (empty($key)) {
153
+			user_error(
154
+				'HybridSession::init() was not given a $key. Disabling cookie-based storage',
155
+				E_USER_WARNING
156
+			);
157
+		} else {
158
+			$instance->setKey($key);
159
+		}
160
+
161
+		session_set_save_handler($instance, true);
162
+
163
+		self::$enabled = true;
164
+	}
165
+
166
+	public static function is_enabled()
167
+	{
168
+		return self::$enabled;
169
+	}
170 170
 }
Please login to merge, or discard this patch.