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

Bump PHP and mongo version requirements #238

Merged
merged 4 commits into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ sudo: false
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

env:
- MONGO_VERSION=1.2.12 PREFER_LOWEST=""
- MONGO_VERSION=1.3.2 PREFER_LOWEST=""
- MONGO_VERSION=1.3.7 PREFER_LOWEST=""
- MONGO_VERSION=1.4.5 PREFER_LOWEST=""
- MONGO_VERSION=1.5.8 PREFER_LOWEST=""
- MONGO_VERSION=stable PREFER_LOWEST=""
- MONGO_VERSION=stable PREFER_LOWEST="--prefer-lowest"

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
{ "name": "Andreas Braun", "email": "[email protected]" }
],
"require": {
"php": ">=5.3.2",
"ext-mongo": "^1.2.12",
"php": "^5.5",
"ext-mongo": "^1.5",
"doctrine/common": "^2.2"
},
"require-dev": {
Expand Down
31 changes: 1 addition & 30 deletions lib/Doctrine/MongoDB/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Doctrine\MongoDB\Event\NearEventArgs;
use Doctrine\MongoDB\Event\UpdateEventArgs;
use Doctrine\MongoDB\Exception\ResultException;
use Doctrine\MongoDB\Util\ReadPreference;
use GeoJson\Geometry\Point;
use BadMethodCallException;
use MongoCommandCursor;
Expand Down Expand Up @@ -502,7 +501,7 @@ public function getName()
*/
public function getReadPreference()
{
return ReadPreference::convertReadPreference($this->mongoCollection->getReadPreference());
return $this->mongoCollection->getReadPreference();
}

/**
Expand Down Expand Up @@ -535,10 +534,6 @@ public function setReadPreference($readPreference, array $tags = null)
*/
public function getSlaveOkay()
{
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
return $this->mongoCollection->getSlaveOkay();
}

$readPref = $this->getReadPreference();

return \MongoClient::RP_PRIMARY !== $readPref['type'];
Expand All @@ -558,10 +553,6 @@ public function getSlaveOkay()
*/
public function setSlaveOkay($ok = true)
{
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
return $this->mongoCollection->setSlaveOkay($ok);
}

$prevSlaveOkay = $this->getSlaveOkay();

if ($ok) {
Expand Down Expand Up @@ -730,10 +721,6 @@ public function near($near, array $query = array(), array $options = array())
*/
public function parallelCollectionScan($numCursors)
{
if ( ! method_exists('MongoCollection', 'parallelCollectionScan')) {
throw new BadMethodCallException('MongoCollection::parallelCollectionScan() is not available');
}

$mongoCollection = $this->mongoCollection;
$commandCursors = $this->retry(function() use ($mongoCollection, $numCursors) {
return $mongoCollection->parallelCollectionScan($numCursors);
Expand Down Expand Up @@ -937,10 +924,6 @@ protected function doAggregate(array $pipeline, array $options = array())
*/
protected function doAggregateCursor(array $pipeline, array $options = array())
{
if ( ! method_exists('MongoCollection', 'aggregateCursor')) {
throw new BadMethodCallException('MongoCollection::aggregateCursor() is not available');
}

list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
? $this->splitCommandAndClientOptions($options)
: array($options, array());
Expand Down Expand Up @@ -1468,10 +1451,6 @@ protected function wrapCursor(\MongoCursor $cursor, $query, $fields)
*/
protected function convertWriteConcern(array $options)
{
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
return $options;
}

if (isset($options['safe']) && ! isset($options['w'])) {
$options['w'] = is_bool($options['safe']) ? (integer) $options['safe'] : $options['safe'];
unset($options['safe']);
Expand All @@ -1489,10 +1468,6 @@ protected function convertWriteConcern(array $options)
*/
protected function convertWriteTimeout(array $options)
{
if (version_compare(phpversion('mongo'), '1.5.0', '<')) {
return $options;
}

if (isset($options['wtimeout']) && ! isset($options['wTimeoutMS'])) {
$options['wTimeoutMS'] = $options['wtimeout'];
unset($options['wtimeout']);
Expand All @@ -1510,10 +1485,6 @@ protected function convertWriteTimeout(array $options)
*/
protected function convertSocketTimeout(array $options)
{
if (version_compare(phpversion('mongo'), '1.5.0', '<')) {
return $options;
}

if (isset($options['timeout']) && ! isset($options['socketTimeoutMS'])) {
$options['socketTimeoutMS'] = $options['timeout'];
unset($options['timeout']);
Expand Down
22 changes: 3 additions & 19 deletions lib/Doctrine/MongoDB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use Doctrine\Common\EventManager;
use Doctrine\MongoDB\Event\EventArgs;
use Doctrine\MongoDB\Util\ReadPreference;

/**
* Wrapper for the MongoClient class.
Expand Down Expand Up @@ -211,7 +210,7 @@ public function getMongoClient()
public function getReadPreference()
{
$this->initialize();
return ReadPreference::convertReadPreference($this->mongoClient->getReadPreference());
return $this->mongoClient->getReadPreference();
}

/**
Expand Down Expand Up @@ -280,9 +279,7 @@ public function initialize()
$options = isset($options['wTimeout']) ? $this->convertWriteTimeout($options) : $options;

$this->mongoClient = $this->retry(function() use ($server, $options) {
return version_compare(phpversion('mongo'), '1.3.0', '<')
? new \Mongo($server, $options)
: new \MongoClient($server, $options);
return new \MongoClient($server, $options);
});

if ($this->eventManager->hasListeners(Events::postConnect)) {
Expand All @@ -301,12 +298,7 @@ public function isConnected()
return false;
}

/* MongoClient::$connected is deprecated in 1.5.0+, so count the list of
* connected hosts instead.
*/
return version_compare(phpversion('mongo'), '1.5.0', '<')
? $this->mongoClient->connected
: count($this->mongoClient->getHosts()) > 0;
return count($this->mongoClient->getHosts()) > 0;
}

/**
Expand Down Expand Up @@ -463,10 +455,6 @@ protected function retry(\Closure $retry)
*/
protected function convertConnectTimeout(array $options)
{
if (version_compare(phpversion('mongo'), '1.4.0', '<')) {
return $options;
}

if (isset($options['timeout']) && ! isset($options['connectTimeoutMS'])) {
$options['connectTimeoutMS'] = $options['timeout'];
unset($options['timeout']);
Expand All @@ -487,10 +475,6 @@ protected function convertConnectTimeout(array $options)
*/
protected function convertWriteTimeout(array $options)
{
if (version_compare(phpversion('mongo'), '1.4.0', '<')) {
return $options;
}

if (isset($options['wTimeout']) && ! isset($options['wTimeoutMS'])) {
$options['wTimeoutMS'] = $options['wTimeout'];
unset($options['wTimeout']);
Expand Down
17 changes: 1 addition & 16 deletions lib/Doctrine/MongoDB/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

namespace Doctrine\MongoDB;

use Doctrine\MongoDB\Util\ReadPreference;

/**
* Wrapper for the PHP MongoCursor class.
*
Expand Down Expand Up @@ -547,23 +545,10 @@ public function rewind()
*/
public function setMongoCursorSlaveOkay($ok)
{
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
$this->mongoCursor->slaveOkay($ok);
return;
}

/* MongoCursor::setReadPreference() may not exist until 1.4.0. Although
* we could throw an exception here, it's more user-friendly to NOP.
*/
if (!method_exists($this->mongoCursor, 'setReadPreference')) {
return;
}

if ($ok) {
// Preserve existing tags for non-primary read preferences
$readPref = $this->mongoCursor->getReadPreference();
$tags = !empty($readPref['tagsets']) ? ReadPreference::convertTagSets($readPref['tagsets']) : array();
$this->mongoCursor->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, $tags);
$this->mongoCursor->setReadPreference(\MongoClient::RP_SECONDARY_PREFERRED, isset($readPref['tagsets']) ? $readPref['tagsets'] : []);
} else {
$this->mongoCursor->setReadPreference(\MongoClient::RP_PRIMARY);
}
Expand Down
21 changes: 2 additions & 19 deletions lib/Doctrine/MongoDB/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Doctrine\MongoDB\Event\CreateCollectionEventArgs;
use Doctrine\MongoDB\Event\EventArgs;
use Doctrine\MongoDB\Event\MutableEventArgs;
use Doctrine\MongoDB\Util\ReadPreference;

/**
* Wrapper for the MongoDB class.
Expand Down Expand Up @@ -338,7 +337,7 @@ public function setProfilingLevel($level)
*/
public function getReadPreference()
{
return ReadPreference::convertReadPreference($this->mongoDB->getReadPreference());
return $this->mongoDB->getReadPreference();
}

/**
Expand Down Expand Up @@ -371,10 +370,6 @@ public function setReadPreference($readPreference, array $tags = null)
*/
public function getSlaveOkay()
{
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
return $this->mongoDB->getSlaveOkay();
}

$readPref = $this->getReadPreference();

return \MongoClient::RP_PRIMARY !== $readPref['type'];
Expand All @@ -394,10 +389,6 @@ public function getSlaveOkay()
*/
public function setSlaveOkay($ok = true)
{
if (version_compare(phpversion('mongo'), '1.3.0', '<')) {
return $this->mongoDB->setSlaveOkay($ok);
}

$prevSlaveOkay = $this->getSlaveOkay();

if ($ok) {
Expand Down Expand Up @@ -544,11 +535,7 @@ protected function doGetDBRef(array $reference)
*/
protected function doCreateCollection($name, array $options)
{
if (version_compare(phpversion('mongo'), '1.4.0', '>=')) {
$this->mongoDB->createCollection($name, $options);
} else {
$this->mongoDB->createCollection($name, $options['capped'], $options['size'], $options['max']);
}
$this->mongoDB->createCollection($name, $options);

return $this->doSelectCollection($name);
}
Expand Down Expand Up @@ -623,10 +610,6 @@ protected function retry(\Closure $retry)
*/
protected function convertSocketTimeout(array $options)
{
if (version_compare(phpversion('mongo'), '1.5.0', '<')) {
return $options;
}

if (isset($options['timeout']) && ! isset($options['socketTimeoutMS'])) {
$options['socketTimeoutMS'] = $options['timeout'];
unset($options['timeout']);
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/MongoDB/Util/ReadPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*
* @since 1.0
* @author Jeremy Mikola <[email protected]>
* @deprecated 1.3 No longer required; will be removed for 2.0
*/
final class ReadPreference
{
Expand Down
Loading