Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed
wants to merge 4 commits into from

Conversation

funyx
Copy link

@funyx funyx commented May 15, 2016

Q A
Branch? 3.0
Bug fix? no
New feature? Yes (MongoDB driver support)
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

Adding support for the new MongoDB php driver in the mongodb sessions' handler.

php-ref : MongoDB driver
mongo-ref : official mongo-php library

@funyx funyx changed the title Bug Fix : Mongo Session [Component][HttpFoundation] Bug Fix : Mongo Session May 15, 2016
@@ -140,7 +140,7 @@ public function write($sessionId, $data)
$this->options['expiry_field'] => $expiry,
);

$this->getCollection()->update(
$this->getCollection()->updateOne(
Copy link
Member

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).

@xabbuh
Copy link
Member

xabbuh commented May 15, 2016

Status: Needs work

@funyx
Copy link
Author

funyx commented May 15, 2016

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');
Copy link
Contributor

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

Copy link
Author

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')){
Copy link
Contributor

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.

@phansys
Copy link
Contributor

phansys commented May 15, 2016

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.

@funyx funyx changed the title [Component][HttpFoundation] Bug Fix : Mongo Session [HTTP][Session][Mongo] New Feature : MongoDB driver support May 15, 2016
@funyx funyx force-pushed the session branch 6 times, most recently from 500c71c to 008ee4c Compare May 15, 2016 21:43
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')){
Copy link
Contributor

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.

@phansys
Copy link
Contributor

phansys commented May 17, 2016

@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.

@xabbuh
Copy link
Member

xabbuh commented May 17, 2016

@phansys I think you have to ask @fabpot about that.

@funyx
Copy link
Author

funyx commented May 17, 2016

patched : running php-cs-fixer-1.11 locally with --level=symfony

'id_field' => '_id',
'data_field' => 'data',
'time_field' => 'time',
'expiry_field' => 'expires_at',
Copy link
Member

@GromNaN GromNaN May 18, 2016

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

@GromNaN
Copy link
Member

GromNaN commented May 18, 2016

Is it possible to add some test cases to MongoDbSessionHandlerTest ?

@@ -120,9 +129,15 @@ public function destroy($sessionId)
*/
public function gc($maxlifetime)
{
$this->getCollection()->remove(array(
Copy link
Member

@nicolas-grekas nicolas-grekas May 19, 2016

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(

@fabpot
Copy link
Member

fabpot commented Jun 15, 2016

@funyx Can you finish this PR by taking comments into account? Thanks.

@javiereguiluz javiereguiluz changed the title [HTTP][Session][Mongo] New Feature : MongoDB driver support [HttpFoundation] MongoDB driver support for sessions Jun 19, 2016
@fabpot
Copy link
Member

fabpot commented Jun 28, 2016

Closing as there is no more feedback here and someone opened a similar one at #19186.

@fabpot fabpot closed this Jun 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants