remove unnecessary instanceof in MongoDbSessionHandler

This commit is contained in:
raplider 2018-07-26 16:17:24 +03:00 committed by Nicolas Grekas
parent a804b915f7
commit 3f013a473a
1 changed files with 4 additions and 13 deletions

View File

@ -24,7 +24,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
private $mongo; private $mongo;
/** /**
* @var \MongoCollection * @var \MongoDB\Collection
*/ */
private $collection; private $collection;
@ -143,21 +143,12 @@ class MongoDbSessionHandler extends AbstractSessionHandler
{ {
$expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000); $expiry = new \MongoDB\BSON\UTCDateTime((time() + (int) ini_get('session.gc_maxlifetime')) * 1000);
if ($this->mongo instanceof \MongoDB\Client) { $this->getCollection()->updateOne(
$methodName = 'updateOne';
$options = array();
} else {
$methodName = 'update';
$options = array('multiple' => false);
}
$this->getCollection()->$methodName(
array($this->options['id_field'] => $sessionId), array($this->options['id_field'] => $sessionId),
array('$set' => array( array('$set' => array(
$this->options['time_field'] => new \MongoDB\BSON\UTCDateTime(), $this->options['time_field'] => new \MongoDB\BSON\UTCDateTime(),
$this->options['expiry_field'] => $expiry, $this->options['expiry_field'] => $expiry,
)), ))
$options
); );
return true; return true;
@ -181,7 +172,7 @@ class MongoDbSessionHandler extends AbstractSessionHandler
} }
/** /**
* @return \MongoCollection * @return \MongoDB\Collection
*/ */
private function getCollection() private function getCollection()
{ {