Last active
August 1, 2016 07:26
-
-
Save squio/4bc7653144ec3b5d58d73e1b468f68ee to your computer and use it in GitHub Desktop.
Yii2 Legacy MongoRegex, MongoId implementation for backward compatibility with php < 7.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 | |
use MongoDB\BSON\ObjectID; | |
/** | |
* Legacy MongoId implementation for backward compatibility with php < 7.0 | |
* Usage: add this to entry script | |
* if (version_compare(phpversion(), '7.0.0', '>')) { | |
* // php v7 uses different MongoDB classes | |
* Yii::$classMap['MongoId'] = '@app/components/MongoId.php'; | |
* } | |
*/ | |
class MongoId | |
{ | |
private $mongoId; | |
public function __construct($id) | |
{ | |
$this->mongoId = new \MongoDB\BSON\ObjectID($id); | |
return $this->mongoId; | |
} | |
public function __toString() | |
{ | |
return $this->mongoId->__toString(); | |
} | |
} |
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 | |
use MongoDB\BSON\Regex; | |
/** | |
* Legacy MongoRegex implementation for backward compatibility with php < 7.0 | |
* Usage: add this to entry script | |
* if (version_compare(phpversion(), '7.0.0', '>')) { | |
* // php v7 uses different MongoDB classes | |
* Yii::$classMap['MongoRegex'] = '@app/components/MongoRegex.php'; | |
* } | |
*/ | |
class MongoRegex implements MongoDB\BSON\Type | |
{ | |
private $regex; | |
public function __construct($pattern) | |
{ | |
$this->regex = new \MongoDB\BSON\Regex($pattern, null); | |
return $this->regex; | |
} | |
public function getFlags() | |
{ | |
return $this->regex->getFlags(); | |
} | |
public function getPattern() | |
{ | |
return $this->regex->getPattern(); | |
} | |
public function __toString() | |
{ | |
return $this->regex->__toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment