Created
July 1, 2013 07:14
-
-
Save MirkoBonadei/5898913 to your computer and use it in GitHub Desktop.
DriverFactory for PHP MongoDB Driver to manage the upgrade from version < 1.3.0 to version >= 1.3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DriverFactory | |
{ | |
private $server; | |
private $options; | |
public function __construct($server = 'localhost:27017', array $options = array()) | |
{ | |
$this->server = $server; | |
$this->options = $options; | |
} | |
public function connection() | |
{ | |
$currentVersion = \Mongo::VERSION; | |
if (version_compare($currentVersion, '1.3.0') === -1) { | |
return new \Mongo($this->server, $this->options); | |
} | |
$upgradedOptions = $this->validOptionsFromLegacyOptions($this->options); | |
return new \MongoClient($this->server, $upgradedOptions); | |
} | |
private function validOptionsFromLegacyOptions(array $options) | |
{ | |
// here some logic as remove 'safe' or 'persist' key or | |
// change the name of deprecated keys | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment