Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/SaveHandler/MongoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ class MongoDB implements SaveHandlerInterface
/**
* Constructor
*
* @param Mongo $mongo
* @param Mongo|MongoClient $mongo
* @param MongoDBOptions $options
* @throws Zend\Session\Exception\InvalidArgumentException
*/
public function __construct(Mongo $mongo, MongoDBOptions $options)
public function __construct($mongo, MongoDBOptions $options)
{
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo)) {
throw new InvalidArgumentException(
'Parameter of type %s is invalid; must be MongoClient or Mongo',
(is_object($mongo) ? get_class($mongo) : gettype($mongo))
);
}

if (null === ($database = $options->getDatabase())) {
throw new InvalidArgumentException('The database option cannot be emtpy');
}
Expand Down
6 changes: 4 additions & 2 deletions test/SaveHandler/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class MongoDBTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Mongo
* @var Mongo|MongoClient
*/
protected $mongo;

Expand Down Expand Up @@ -55,7 +55,9 @@ public function setUp()
'collection' => 'sessions',
));

$this->mongo = new Mongo();
$mongoClass = (version_compare(phpversion('mongo'), '1.3.0', '<')) ? '\Mongo' : '\MongoClient';

$this->mongo = new $mongoClass();
$this->mongoCollection = $this->mongo->selectCollection($this->options->getDatabase(), $this->options->getCollection());
}

Expand Down

0 comments on commit 674fa66

Please sign in to comment.