Completed
Pull Request — master (#4495)
by Joas
52:44 queued 33:18
created
lib/private/Session/Internal.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -38,120 +38,120 @@
 block discarded – undo
38 38
  * @package OC\Session
39 39
  */
40 40
 class Internal extends Session {
41
-	/**
42
-	 * @param string $name
43
-	 * @throws \Exception
44
-	 */
45
-	public function __construct($name) {
46
-		session_name($name);
47
-		set_error_handler(array($this, 'trapError'));
48
-		try {
49
-			session_start();
50
-		} catch (\Exception $e) {
51
-			setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/');
52
-		}
53
-		restore_error_handler();
54
-		if (!isset($_SESSION)) {
55
-			throw new \Exception('Failed to start session');
56
-		}
57
-	}
41
+    /**
42
+     * @param string $name
43
+     * @throws \Exception
44
+     */
45
+    public function __construct($name) {
46
+        session_name($name);
47
+        set_error_handler(array($this, 'trapError'));
48
+        try {
49
+            session_start();
50
+        } catch (\Exception $e) {
51
+            setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/');
52
+        }
53
+        restore_error_handler();
54
+        if (!isset($_SESSION)) {
55
+            throw new \Exception('Failed to start session');
56
+        }
57
+    }
58 58
 
59
-	/**
60
-	 * @param string $key
61
-	 * @param integer $value
62
-	 */
63
-	public function set($key, $value) {
64
-		$this->validateSession();
65
-		$_SESSION[$key] = $value;
66
-	}
59
+    /**
60
+     * @param string $key
61
+     * @param integer $value
62
+     */
63
+    public function set($key, $value) {
64
+        $this->validateSession();
65
+        $_SESSION[$key] = $value;
66
+    }
67 67
 
68
-	/**
69
-	 * @param string $key
70
-	 * @return mixed
71
-	 */
72
-	public function get($key) {
73
-		if (!$this->exists($key)) {
74
-			return null;
75
-		}
76
-		return $_SESSION[$key];
77
-	}
68
+    /**
69
+     * @param string $key
70
+     * @return mixed
71
+     */
72
+    public function get($key) {
73
+        if (!$this->exists($key)) {
74
+            return null;
75
+        }
76
+        return $_SESSION[$key];
77
+    }
78 78
 
79
-	/**
80
-	 * @param string $key
81
-	 * @return bool
82
-	 */
83
-	public function exists($key) {
84
-		return isset($_SESSION[$key]);
85
-	}
79
+    /**
80
+     * @param string $key
81
+     * @return bool
82
+     */
83
+    public function exists($key) {
84
+        return isset($_SESSION[$key]);
85
+    }
86 86
 
87
-	/**
88
-	 * @param string $key
89
-	 */
90
-	public function remove($key) {
91
-		if (isset($_SESSION[$key])) {
92
-			unset($_SESSION[$key]);
93
-		}
94
-	}
87
+    /**
88
+     * @param string $key
89
+     */
90
+    public function remove($key) {
91
+        if (isset($_SESSION[$key])) {
92
+            unset($_SESSION[$key]);
93
+        }
94
+    }
95 95
 
96
-	public function clear() {
97
-		session_unset();
98
-		$this->regenerateId();
99
-		@session_start();
100
-		$_SESSION = array();
101
-	}
96
+    public function clear() {
97
+        session_unset();
98
+        $this->regenerateId();
99
+        @session_start();
100
+        $_SESSION = array();
101
+    }
102 102
 
103
-	public function close() {
104
-		session_write_close();
105
-		parent::close();
106
-	}
103
+    public function close() {
104
+        session_write_close();
105
+        parent::close();
106
+    }
107 107
 
108
-	/**
109
-	 * Wrapper around session_regenerate_id
110
-	 *
111
-	 * @param bool $deleteOldSession Whether to delete the old associated session file or not.
112
-	 * @return void
113
-	 */
114
-	public function regenerateId($deleteOldSession = true) {
115
-		@session_regenerate_id($deleteOldSession);
116
-	}
108
+    /**
109
+     * Wrapper around session_regenerate_id
110
+     *
111
+     * @param bool $deleteOldSession Whether to delete the old associated session file or not.
112
+     * @return void
113
+     */
114
+    public function regenerateId($deleteOldSession = true) {
115
+        @session_regenerate_id($deleteOldSession);
116
+    }
117 117
 
118
-	/**
119
-	 * Wrapper around session_id
120
-	 *
121
-	 * @return string
122
-	 * @throws SessionNotAvailableException
123
-	 * @since 9.1.0
124
-	 */
125
-	public function getId() {
126
-		$id = @session_id();
127
-		if ($id === '') {
128
-			throw new SessionNotAvailableException();
129
-		}
130
-		return $id;
131
-	}
118
+    /**
119
+     * Wrapper around session_id
120
+     *
121
+     * @return string
122
+     * @throws SessionNotAvailableException
123
+     * @since 9.1.0
124
+     */
125
+    public function getId() {
126
+        $id = @session_id();
127
+        if ($id === '') {
128
+            throw new SessionNotAvailableException();
129
+        }
130
+        return $id;
131
+    }
132 132
 
133
-	/**
134
-	 * @throws \Exception
135
-	 */
136
-	public function reopen() {
137
-		throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.');
138
-	}
133
+    /**
134
+     * @throws \Exception
135
+     */
136
+    public function reopen() {
137
+        throw new \Exception('The session cannot be reopened - reopen() is ony to be used in unit testing.');
138
+    }
139 139
 
140
-	/**
141
-	 * @param int $errorNumber
142
-	 * @param string $errorString
143
-	 * @throws \ErrorException
144
-	 */
145
-	public function trapError($errorNumber, $errorString) {
146
-		throw new \ErrorException($errorString);
147
-	}
140
+    /**
141
+     * @param int $errorNumber
142
+     * @param string $errorString
143
+     * @throws \ErrorException
144
+     */
145
+    public function trapError($errorNumber, $errorString) {
146
+        throw new \ErrorException($errorString);
147
+    }
148 148
 
149
-	/**
150
-	 * @throws \Exception
151
-	 */
152
-	private function validateSession() {
153
-		if ($this->sessionClosed) {
154
-			throw new SessionNotAvailableException('Session has been closed - no further changes to the session are allowed');
155
-		}
156
-	}
149
+    /**
150
+     * @throws \Exception
151
+     */
152
+    private function validateSession() {
153
+        if ($this->sessionClosed) {
154
+            throw new SessionNotAvailableException('Session has been closed - no further changes to the session are allowed');
155
+        }
156
+    }
157 157
 }
Please login to merge, or discard this patch.
lib/private/Session/CryptoSessionData.php 2 patches
Indentation   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -34,176 +34,176 @@
 block discarded – undo
34 34
  * @package OC\Session
35 35
  */
36 36
 class CryptoSessionData implements \ArrayAccess, ISession {
37
-	/** @var ISession */
38
-	protected $session;
39
-	/** @var \OCP\Security\ICrypto */
40
-	protected $crypto;
41
-	/** @var string */
42
-	protected $passphrase;
43
-	/** @var array */
44
-	protected $sessionValues;
45
-	/** @var bool */
46
-	protected $isModified = false;
47
-	CONST encryptedSessionName = 'encrypted_session_data';
48
-
49
-	/**
50
-	 * @param ISession $session
51
-	 * @param ICrypto $crypto
52
-	 * @param string $passphrase
53
-	 */
54
-	public function __construct(ISession $session,
55
-								ICrypto $crypto,
56
-								$passphrase) {
57
-		$this->crypto = $crypto;
58
-		$this->session = $session;
59
-		$this->passphrase = $passphrase;
60
-		$this->initializeSession();
61
-	}
62
-
63
-	/**
64
-	 * Close session if class gets destructed
65
-	 */
66
-	public function __destruct() {
67
-		try {
68
-			$this->close();
69
-		} catch (SessionNotAvailableException $e){
70
-			// This exception can occur if session is already closed
71
-			// So it is safe to ignore it and let the garbage collector to proceed
72
-		}
73
-	}
74
-
75
-	protected function initializeSession() {
76
-		$encryptedSessionData = $this->session->get(self::encryptedSessionName);
77
-		try {
78
-			$this->sessionValues = json_decode(
79
-				$this->crypto->decrypt($encryptedSessionData, $this->passphrase),
80
-				true
81
-			);
82
-		} catch (\Exception $e) {
83
-			$this->sessionValues = [];
84
-		}
85
-	}
86
-
87
-	/**
88
-	 * Set a value in the session
89
-	 *
90
-	 * @param string $key
91
-	 * @param mixed $value
92
-	 */
93
-	public function set($key, $value) {
94
-		$this->sessionValues[$key] = $value;
95
-		$this->isModified = true;
96
-	}
97
-
98
-	/**
99
-	 * Get a value from the session
100
-	 *
101
-	 * @param string $key
102
-	 * @return string|null Either the value or null
103
-	 */
104
-	public function get($key) {
105
-		if(isset($this->sessionValues[$key])) {
106
-			return $this->sessionValues[$key];
107
-		}
108
-
109
-		return null;
110
-	}
111
-
112
-	/**
113
-	 * Check if a named key exists in the session
114
-	 *
115
-	 * @param string $key
116
-	 * @return bool
117
-	 */
118
-	public function exists($key) {
119
-		return isset($this->sessionValues[$key]);
120
-	}
121
-
122
-	/**
123
-	 * Remove a $key/$value pair from the session
124
-	 *
125
-	 * @param string $key
126
-	 */
127
-	public function remove($key) {
128
-		$this->isModified = true;
129
-		unset($this->sessionValues[$key]);
130
-		$this->session->remove(self::encryptedSessionName);
131
-	}
132
-
133
-	/**
134
-	 * Reset and recreate the session
135
-	 */
136
-	public function clear() {
137
-		$requesttoken = $this->get('requesttoken');
138
-		$this->sessionValues = [];
139
-		if ($requesttoken !== null) {
140
-			$this->set('requesttoken', $requesttoken);
141
-		}
142
-		$this->isModified = true;
143
-		$this->session->clear();
144
-	}
145
-
146
-	/**
147
-	 * Wrapper around session_regenerate_id
148
-	 *
149
-	 * @param bool $deleteOldSession Whether to delete the old associated session file or not.
150
-	 * @return void
151
-	 */
152
-	public function regenerateId($deleteOldSession = true) {
153
-		$this->session->regenerateId($deleteOldSession);
154
-	}
155
-
156
-	/**
157
-	 * Wrapper around session_id
158
-	 *
159
-	 * @return string
160
-	 * @throws SessionNotAvailableException
161
-	 * @since 9.1.0
162
-	 */
163
-	public function getId() {
164
-		return $this->session->getId();
165
-	}
166
-
167
-	/**
168
-	 * Close the session and release the lock, also writes all changed data in batch
169
-	 */
170
-	public function close() {
171
-		if($this->isModified) {
172
-			$encryptedValue = $this->crypto->encrypt(json_encode($this->sessionValues), $this->passphrase);
173
-			$this->session->set(self::encryptedSessionName, $encryptedValue);
174
-			$this->isModified = false;
175
-		}
176
-		$this->session->close();
177
-	}
178
-
179
-	/**
180
-	 * @param mixed $offset
181
-	 * @return bool
182
-	 */
183
-	public function offsetExists($offset) {
184
-		return $this->exists($offset);
185
-	}
186
-
187
-	/**
188
-	 * @param mixed $offset
189
-	 * @return mixed
190
-	 */
191
-	public function offsetGet($offset) {
192
-		return $this->get($offset);
193
-	}
194
-
195
-	/**
196
-	 * @param mixed $offset
197
-	 * @param mixed $value
198
-	 */
199
-	public function offsetSet($offset, $value) {
200
-		$this->set($offset, $value);
201
-	}
202
-
203
-	/**
204
-	 * @param mixed $offset
205
-	 */
206
-	public function offsetUnset($offset) {
207
-		$this->remove($offset);
208
-	}
37
+    /** @var ISession */
38
+    protected $session;
39
+    /** @var \OCP\Security\ICrypto */
40
+    protected $crypto;
41
+    /** @var string */
42
+    protected $passphrase;
43
+    /** @var array */
44
+    protected $sessionValues;
45
+    /** @var bool */
46
+    protected $isModified = false;
47
+    CONST encryptedSessionName = 'encrypted_session_data';
48
+
49
+    /**
50
+     * @param ISession $session
51
+     * @param ICrypto $crypto
52
+     * @param string $passphrase
53
+     */
54
+    public function __construct(ISession $session,
55
+                                ICrypto $crypto,
56
+                                $passphrase) {
57
+        $this->crypto = $crypto;
58
+        $this->session = $session;
59
+        $this->passphrase = $passphrase;
60
+        $this->initializeSession();
61
+    }
62
+
63
+    /**
64
+     * Close session if class gets destructed
65
+     */
66
+    public function __destruct() {
67
+        try {
68
+            $this->close();
69
+        } catch (SessionNotAvailableException $e){
70
+            // This exception can occur if session is already closed
71
+            // So it is safe to ignore it and let the garbage collector to proceed
72
+        }
73
+    }
74
+
75
+    protected function initializeSession() {
76
+        $encryptedSessionData = $this->session->get(self::encryptedSessionName);
77
+        try {
78
+            $this->sessionValues = json_decode(
79
+                $this->crypto->decrypt($encryptedSessionData, $this->passphrase),
80
+                true
81
+            );
82
+        } catch (\Exception $e) {
83
+            $this->sessionValues = [];
84
+        }
85
+    }
86
+
87
+    /**
88
+     * Set a value in the session
89
+     *
90
+     * @param string $key
91
+     * @param mixed $value
92
+     */
93
+    public function set($key, $value) {
94
+        $this->sessionValues[$key] = $value;
95
+        $this->isModified = true;
96
+    }
97
+
98
+    /**
99
+     * Get a value from the session
100
+     *
101
+     * @param string $key
102
+     * @return string|null Either the value or null
103
+     */
104
+    public function get($key) {
105
+        if(isset($this->sessionValues[$key])) {
106
+            return $this->sessionValues[$key];
107
+        }
108
+
109
+        return null;
110
+    }
111
+
112
+    /**
113
+     * Check if a named key exists in the session
114
+     *
115
+     * @param string $key
116
+     * @return bool
117
+     */
118
+    public function exists($key) {
119
+        return isset($this->sessionValues[$key]);
120
+    }
121
+
122
+    /**
123
+     * Remove a $key/$value pair from the session
124
+     *
125
+     * @param string $key
126
+     */
127
+    public function remove($key) {
128
+        $this->isModified = true;
129
+        unset($this->sessionValues[$key]);
130
+        $this->session->remove(self::encryptedSessionName);
131
+    }
132
+
133
+    /**
134
+     * Reset and recreate the session
135
+     */
136
+    public function clear() {
137
+        $requesttoken = $this->get('requesttoken');
138
+        $this->sessionValues = [];
139
+        if ($requesttoken !== null) {
140
+            $this->set('requesttoken', $requesttoken);
141
+        }
142
+        $this->isModified = true;
143
+        $this->session->clear();
144
+    }
145
+
146
+    /**
147
+     * Wrapper around session_regenerate_id
148
+     *
149
+     * @param bool $deleteOldSession Whether to delete the old associated session file or not.
150
+     * @return void
151
+     */
152
+    public function regenerateId($deleteOldSession = true) {
153
+        $this->session->regenerateId($deleteOldSession);
154
+    }
155
+
156
+    /**
157
+     * Wrapper around session_id
158
+     *
159
+     * @return string
160
+     * @throws SessionNotAvailableException
161
+     * @since 9.1.0
162
+     */
163
+    public function getId() {
164
+        return $this->session->getId();
165
+    }
166
+
167
+    /**
168
+     * Close the session and release the lock, also writes all changed data in batch
169
+     */
170
+    public function close() {
171
+        if($this->isModified) {
172
+            $encryptedValue = $this->crypto->encrypt(json_encode($this->sessionValues), $this->passphrase);
173
+            $this->session->set(self::encryptedSessionName, $encryptedValue);
174
+            $this->isModified = false;
175
+        }
176
+        $this->session->close();
177
+    }
178
+
179
+    /**
180
+     * @param mixed $offset
181
+     * @return bool
182
+     */
183
+    public function offsetExists($offset) {
184
+        return $this->exists($offset);
185
+    }
186
+
187
+    /**
188
+     * @param mixed $offset
189
+     * @return mixed
190
+     */
191
+    public function offsetGet($offset) {
192
+        return $this->get($offset);
193
+    }
194
+
195
+    /**
196
+     * @param mixed $offset
197
+     * @param mixed $value
198
+     */
199
+    public function offsetSet($offset, $value) {
200
+        $this->set($offset, $value);
201
+    }
202
+
203
+    /**
204
+     * @param mixed $offset
205
+     */
206
+    public function offsetUnset($offset) {
207
+        $this->remove($offset);
208
+    }
209 209
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	public function __destruct() {
67 67
 		try {
68 68
 			$this->close();
69
-		} catch (SessionNotAvailableException $e){
69
+		} catch (SessionNotAvailableException $e) {
70 70
 			// This exception can occur if session is already closed
71 71
 			// So it is safe to ignore it and let the garbage collector to proceed
72 72
 		}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @return string|null Either the value or null
103 103
 	 */
104 104
 	public function get($key) {
105
-		if(isset($this->sessionValues[$key])) {
105
+		if (isset($this->sessionValues[$key])) {
106 106
 			return $this->sessionValues[$key];
107 107
 		}
108 108
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * Close the session and release the lock, also writes all changed data in batch
169 169
 	 */
170 170
 	public function close() {
171
-		if($this->isModified) {
171
+		if ($this->isModified) {
172 172
 			$encryptedValue = $this->crypto->encrypt(json_encode($this->sessionValues), $this->passphrase);
173 173
 			$this->session->set(self::encryptedSessionName, $encryptedValue);
174 174
 			$this->isModified = false;
Please login to merge, or discard this patch.