Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/http-foundation/Session/Storage/Handler/MongoDbSessionHandler.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
81 throw new \InvalidArgumentException('You must provide the "database" and "collection" option for MongoDBSessionHandler'); | 81 throw new \InvalidArgumentException('You must provide the "database" and "collection" option for MongoDBSessionHandler'); |
82 } | 82 } |
83 | 83 |
84 $this->mongo = $mongo; | 84 $this->mongo = $mongo; |
85 | 85 |
86 $this->options = array_merge(array( | 86 $this->options = array_merge([ |
87 'id_field' => '_id', | 87 'id_field' => '_id', |
88 'data_field' => 'data', | 88 'data_field' => 'data', |
89 'time_field' => 'time', | 89 'time_field' => 'time', |
90 'expiry_field' => 'expires_at', | 90 'expiry_field' => 'expires_at', |
91 ), $options); | 91 ], $options); |
92 } | 92 } |
93 | 93 |
94 /** | 94 /** |
95 * {@inheritdoc} | 95 * {@inheritdoc} |
96 */ | 96 */ |
104 */ | 104 */ |
105 protected function doDestroy($sessionId) | 105 protected function doDestroy($sessionId) |
106 { | 106 { |
107 $methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteOne' : 'remove'; | 107 $methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteOne' : 'remove'; |
108 | 108 |
109 $this->getCollection()->$methodName(array( | 109 $this->getCollection()->$methodName([ |
110 $this->options['id_field'] => $sessionId, | 110 $this->options['id_field'] => $sessionId, |
111 )); | 111 ]); |
112 | 112 |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 /** | 116 /** |
118 */ | 118 */ |
119 public function gc($maxlifetime) | 119 public function gc($maxlifetime) |
120 { | 120 { |
121 $methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteMany' : 'remove'; | 121 $methodName = $this->mongo instanceof \MongoDB\Client ? 'deleteMany' : 'remove'; |
122 | 122 |
123 $this->getCollection()->$methodName(array( | 123 $this->getCollection()->$methodName([ |
124 $this->options['expiry_field'] => array('$lt' => $this->createDateTime()), | 124 $this->options['expiry_field'] => ['$lt' => $this->createDateTime()], |
125 )); | 125 ]); |
126 | 126 |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 /** | 130 /** |
132 */ | 132 */ |
133 protected function doWrite($sessionId, $data) | 133 protected function doWrite($sessionId, $data) |
134 { | 134 { |
135 $expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime')); | 135 $expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime')); |
136 | 136 |
137 $fields = array( | 137 $fields = [ |
138 $this->options['time_field'] => $this->createDateTime(), | 138 $this->options['time_field'] => $this->createDateTime(), |
139 $this->options['expiry_field'] => $expiry, | 139 $this->options['expiry_field'] => $expiry, |
140 ); | 140 ]; |
141 | 141 |
142 $options = array('upsert' => true); | 142 $options = ['upsert' => true]; |
143 | 143 |
144 if ($this->mongo instanceof \MongoDB\Client) { | 144 if ($this->mongo instanceof \MongoDB\Client) { |
145 $fields[$this->options['data_field']] = new \MongoDB\BSON\Binary($data, \MongoDB\BSON\Binary::TYPE_OLD_BINARY); | 145 $fields[$this->options['data_field']] = new \MongoDB\BSON\Binary($data, \MongoDB\BSON\Binary::TYPE_OLD_BINARY); |
146 } else { | 146 } else { |
147 $fields[$this->options['data_field']] = new \MongoBinData($data, \MongoBinData::BYTE_ARRAY); | 147 $fields[$this->options['data_field']] = new \MongoBinData($data, \MongoBinData::BYTE_ARRAY); |
149 } | 149 } |
150 | 150 |
151 $methodName = $this->mongo instanceof \MongoDB\Client ? 'updateOne' : 'update'; | 151 $methodName = $this->mongo instanceof \MongoDB\Client ? 'updateOne' : 'update'; |
152 | 152 |
153 $this->getCollection()->$methodName( | 153 $this->getCollection()->$methodName( |
154 array($this->options['id_field'] => $sessionId), | 154 [$this->options['id_field'] => $sessionId], |
155 array('$set' => $fields), | 155 ['$set' => $fields], |
156 $options | 156 $options |
157 ); | 157 ); |
158 | 158 |
159 return true; | 159 return true; |
160 } | 160 } |
166 { | 166 { |
167 $expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime')); | 167 $expiry = $this->createDateTime(time() + (int) ini_get('session.gc_maxlifetime')); |
168 | 168 |
169 if ($this->mongo instanceof \MongoDB\Client) { | 169 if ($this->mongo instanceof \MongoDB\Client) { |
170 $methodName = 'updateOne'; | 170 $methodName = 'updateOne'; |
171 $options = array(); | 171 $options = []; |
172 } else { | 172 } else { |
173 $methodName = 'update'; | 173 $methodName = 'update'; |
174 $options = array('multiple' => false); | 174 $options = ['multiple' => false]; |
175 } | 175 } |
176 | 176 |
177 $this->getCollection()->$methodName( | 177 $this->getCollection()->$methodName( |
178 array($this->options['id_field'] => $sessionId), | 178 [$this->options['id_field'] => $sessionId], |
179 array('$set' => array( | 179 ['$set' => [ |
180 $this->options['time_field'] => $this->createDateTime(), | 180 $this->options['time_field'] => $this->createDateTime(), |
181 $this->options['expiry_field'] => $expiry, | 181 $this->options['expiry_field'] => $expiry, |
182 )), | 182 ]], |
183 $options | 183 $options |
184 ); | 184 ); |
185 | 185 |
186 return true; | 186 return true; |
187 } | 187 } |
189 /** | 189 /** |
190 * {@inheritdoc} | 190 * {@inheritdoc} |
191 */ | 191 */ |
192 protected function doRead($sessionId) | 192 protected function doRead($sessionId) |
193 { | 193 { |
194 $dbData = $this->getCollection()->findOne(array( | 194 $dbData = $this->getCollection()->findOne([ |
195 $this->options['id_field'] => $sessionId, | 195 $this->options['id_field'] => $sessionId, |
196 $this->options['expiry_field'] => array('$gte' => $this->createDateTime()), | 196 $this->options['expiry_field'] => ['$gte' => $this->createDateTime()], |
197 )); | 197 ]); |
198 | 198 |
199 if (null === $dbData) { | 199 if (null === $dbData) { |
200 return ''; | 200 return ''; |
201 } | 201 } |
202 | 202 |