diff options
author | Roeland Douma <rullzer@users.noreply.github.com> | 2016-05-02 16:49:38 +0200 |
---|---|---|
committer | Roeland Douma <rullzer@users.noreply.github.com> | 2016-05-02 16:49:38 +0200 |
commit | b84825f0301fb073bfcc6e05132675d104afcfe3 (patch) | |
tree | ae63c55f897761e5fd068bc328fcb9d19ffd4bcc /lib/private | |
parent | fd844f3eb3bdfe1186c42df382b3de2e02c98cd4 (diff) | |
parent | e93bf80b29cde236c5d78023b49435283e4b2562 (diff) | |
download | nextcloud-server-b84825f0301fb073bfcc6e05132675d104afcfe3.tar.gz nextcloud-server-b84825f0301fb073bfcc6e05132675d104afcfe3.zip |
Merge pull request #24229 from owncloud/session-id-wrapper
add ISession::getId() wrapper for session_id
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Session/CryptoSessionData.php | 12 | ||||
-rw-r--r-- | lib/private/Session/Internal.php | 17 | ||||
-rw-r--r-- | lib/private/Session/Memory.php | 18 |
3 files changed, 45 insertions, 2 deletions
diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php index f6c585c1611..629e6af5412 100644 --- a/lib/private/Session/CryptoSessionData.php +++ b/lib/private/Session/CryptoSessionData.php @@ -24,6 +24,7 @@ namespace OC\Session; use OCP\ISession; use OCP\Security\ICrypto; +use OCP\Session\Exceptions\SessionNotAvailableException; /** * Class CryptoSessionData @@ -142,6 +143,17 @@ class CryptoSessionData implements \ArrayAccess, ISession { } /** + * Wrapper around session_id + * + * @return string + * @throws SessionNotAvailableException + * @since 9.1.0 + */ + public function getId() { + return $this->session->getId(); + } + + /** * Close the session and release the lock, also writes all changed data in batch */ public function close() { diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php index 09175bf1f2f..a24aec55222 100644 --- a/lib/private/Session/Internal.php +++ b/lib/private/Session/Internal.php @@ -26,6 +26,8 @@ namespace OC\Session; +use OCP\Session\Exceptions\SessionNotAvailableException; + /** * Class Internal * @@ -112,6 +114,21 @@ class Internal extends Session { } /** + * Wrapper around session_id + * + * @return string + * @throws SessionNotAvailableException + * @since 9.1.0 + */ + public function getId() { + $id = @session_id(); + if ($id === '') { + throw new SessionNotAvailableException(); + } + return $id; + } + + /** * @throws \Exception */ public function reopen() { diff --git a/lib/private/Session/Memory.php b/lib/private/Session/Memory.php index 777458a9aa5..bcb1f1d950c 100644 --- a/lib/private/Session/Memory.php +++ b/lib/private/Session/Memory.php @@ -26,6 +26,9 @@ namespace OC\Session; +use Exception; +use OCP\Session\Exceptions\SessionNotAvailableException; + /** * Class Internal * @@ -89,6 +92,17 @@ class Memory extends Session { public function regenerateId($deleteOldSession = true) {} /** + * Wrapper around session_id + * + * @return string + * @throws SessionNotAvailableException + * @since 9.1.0 + */ + public function getId() { + throw new SessionNotAvailableException('Memory session does not have an ID'); + } + + /** * Helper function for PHPUnit execution - don't use in non-test code */ public function reopen() { @@ -98,11 +112,11 @@ class Memory extends Session { /** * In case the session has already been locked an exception will be thrown * - * @throws \Exception + * @throws Exception */ private function validateSession() { if ($this->sessionClosed) { - throw new \Exception('Session has been closed - no further changes to the session are allowed'); + throw new Exception('Session has been closed - no further changes to the session are allowed'); } } } |