PluginProbe
Loginizer / 1.9.3
Loginizer v1.9.3
2.1.0 2.0.9 2.0.8 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 74 releases
loginizer / lib / hybridauth / Storage / Session.php

Session.php in Loginizer 1.9.3, at lib/hybridauth/Storage/Session.php

131 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*!
3 * Hybridauth
4 * https://hybridauth.github.io | https://github.com/hybridauth/hybridauth
5 * (c) 2017 Hybridauth authors | https://hybridauth.github.io/license.html
6 */
7
8 namespace Hybridauth\Storage;
9
10 use Hybridauth\Exception\RuntimeException;
11
12 /**
13 * Hybridauth storage manager
14 */
15 class Session implements StorageInterface
16 {
17 /**
18 * Namespace
19 *
20 * @var string
21 */
22 protected $storeNamespace = 'HYBRIDAUTH::STORAGE';
23
24 /**
25 * Key prefix
26 *
27 * @var string
28 */
29 protected $keyPrefix = '';
30
31 /**
32 * Initiate a new session
33 *
34 * @throws RuntimeException
35 */
36 public function __construct()
37 {
38 if (session_id()) {
39 return;
40 }
41
42 if (headers_sent()) {
43 // phpcs:ignore
44 throw new RuntimeException('HTTP headers already sent to browser and Hybridauth won\'t be able to start/resume PHP session. To resolve this, session_start() must be called before outputing any data.');
45 }
46
47 if (!session_start()) {
48 throw new RuntimeException('PHP session failed to start.');
49 }
50 }
51
52 /**
53 * {@inheritdoc}
54 */
55 public function get($key)
56 {
57 $key = $this->keyPrefix . strtolower($key);
58
59 if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
60 $value = $_SESSION[$this->storeNamespace][$key];
61
62 if (is_array($value) && array_key_exists('lateObject', $value)) {
63 $value = unserialize($value['lateObject']);
64 }
65
66 return $value;
67 }
68
69 return null;
70 }
71
72 /**
73 * {@inheritdoc}
74 */
75 public function set($key, $value)
76 {
77 $key = $this->keyPrefix . strtolower($key);
78
79 if (is_object($value)) {
80 // We encapsulate as our classes may be defined after session is initialized.
81 $value = ['lateObject' => serialize($value)];
82 }
83
84 $_SESSION[$this->storeNamespace][$key] = $value;
85 }
86
87 /**
88 * {@inheritdoc}
89 */
90 public function clear()
91 {
92 $_SESSION[$this->storeNamespace] = [];
93 }
94
95 /**
96 * {@inheritdoc}
97 */
98 public function delete($key)
99 {
100 $key = $this->keyPrefix . strtolower($key);
101
102 if (isset($_SESSION[$this->storeNamespace], $_SESSION[$this->storeNamespace][$key])) {
103 $tmp = $_SESSION[$this->storeNamespace];
104
105 unset($tmp[$key]);
106
107 $_SESSION[$this->storeNamespace] = $tmp;
108 }
109 }
110
111 /**
112 * {@inheritdoc}
113 */
114 public function deleteMatch($key)
115 {
116 $key = $this->keyPrefix . strtolower($key);
117
118 if (isset($_SESSION[$this->storeNamespace]) && count($_SESSION[$this->storeNamespace])) {
119 $tmp = $_SESSION[$this->storeNamespace];
120
121 foreach ($tmp as $k => $v) {
122 if (strstr($k, $key)) {
123 unset($tmp[$k]);
124 }
125 }
126
127 $_SESSION[$this->storeNamespace] = $tmp;
128 }
129 }
130 }
131