-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] MongoDB driver support for sessions #18788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -140,7 +140,7 @@ public function write($sessionId, $data) | |||
$this->options['expiry_field'] => $expiry, | |||
); | |||
|
|||
$this->getCollection()->update( | |||
$this->getCollection()->updateOne( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method does not always exist (see the failing test).
Status: Needs work |
what am i doing wrong why cant i pass fabbot.io :/ |
@@ -69,7 +69,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface | |||
*/ | |||
public function __construct($mongo, array $options) | |||
{ | |||
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo)) { | |||
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client)) { | |||
throw new \InvalidArgumentException('MongoClient or Mongo instance required'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add the new case here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$mongo instanceof \MongoDB\Client
-> MongoDB is available
any alternatives ?
throw new \InvalidArgumentException('MongoClient or Mongo instance required'); | ||
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client)) { | ||
throw new \InvalidArgumentException('MongoClient, Mongo or MongoDB instance required'); | ||
}elseif($mongo instanceof \MongoDB\Client && !class_exists('\MongoDB\Collection')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elseif
seems weird after throw an exception which is uncaught.
You need to respect CS in order to pass fabbot.io checks successfully. You can apply directly the patch proposed by the tool and push the changes again. |
500c71c
to
008ee4c
Compare
throw new \InvalidArgumentException('MongoClient or Mongo instance required'); | ||
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo || $mongo instanceof \MongoDB\Client)) { | ||
throw new \InvalidArgumentException('MongoClient, Mongo or MongoDB instance required'); | ||
}elseif($mongo instanceof \MongoDB\Client && !class_exists('\MongoDB\Collection')){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, put this check in a separated if
statement.
@xabbuh, do you know which version of PHP-CS-Fixer is fabbot.io using? I don't know how the current status of these changes could be passed the CS checks. |
patched : running php-cs-fixer-1.11 locally with --level=symfony |
'id_field' => '_id', | ||
'data_field' => 'data', | ||
'time_field' => 'time', | ||
'expiry_field' => 'expires_at', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation should remain at 4 spaces
Is it possible to add some test cases to |
@@ -120,9 +129,15 @@ public function destroy($sessionId) | |||
*/ | |||
public function gc($maxlifetime) | |||
{ | |||
$this->getCollection()->remove(array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about doing this (same below and above)?
$collection = $this->getCollection();
$method = $collection instanceof \MongoDB\Collection ? 'deleteMany' : 'remove';
$collection->$method(array(
@funyx Can you finish this PR by taking comments into account? Thanks. |
Closing as there is no more feedback here and someone opened a similar one at #19186. |
Adding support for the new MongoDB php driver in the mongodb sessions' handler.
php-ref : MongoDB driver
mongo-ref : official mongo-php library