forked from alcaeus/mongo-php-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ab26669
Showing
48 changed files
with
3,789 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
composer.lock | ||
vendor/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
sudo: false | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.6 | ||
- 7.0 | ||
|
||
env: | ||
matrix: | ||
- DRIVER_VERSION=1.1.1 | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- mongodb-upstart | ||
packages: | ||
- mongodb-org-server | ||
|
||
before_script: | ||
- pecl install -f mongodb-${DRIVER_VERSION} | ||
- composer install --dev | ||
|
||
script: | ||
- vendor/bin/phpunit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2006-2015 Doctrine Project | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Mongo PHP Adapter | ||
|
||
The Mongo PHP Adapter is a userland library designed to act as an adapter | ||
between applications relying on ext-mongo and the new driver (ext-mongodb). | ||
|
||
It provides the API of ext-mongo built on top of mongo-php-library, thus being | ||
compatible with PHP7. | ||
|
||
# Stability | ||
|
||
This library is not yet stable enough to be used in production. Use at your own | ||
risk. | ||
|
||
# Installation | ||
|
||
This library requires you to have the mongodb extension installed and conflicts | ||
with the legacy mongo extension. | ||
|
||
The preferred method of installing this library is with | ||
[Composer](https://getcomposer.org/) by running the following from your project | ||
root: | ||
|
||
$ composer require "alcaeus/mongo-php-adapter=dev-master" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "alcaeus/mongo-php-adapter", | ||
"type": "library", | ||
"description": "Adapter to provide ext-mongo interface on top of mongo-php-libary", | ||
"keywords": ["mongodb", "database"], | ||
"authors": [ | ||
{ "name": "alcaeus", "email": "[email protected]" } | ||
], | ||
"require": { | ||
"php": "^5.5 || ^7.0", | ||
"mongodb/mongodb": "1.0.0-beta2" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^4.8 || ^5.0" | ||
}, | ||
"conflict": { | ||
"ext-mongo": "*" | ||
}, | ||
"replace": { | ||
"ext-mongo": "self.version" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"": "lib/Mongo", | ||
"Alcaeus\\MongoDbAdapter\\": "lib/Alcaeus/MongoDbAdapter" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { "Alcaeus\\MongoDbAdapter\\Tests\\": "tests/Alcaeus/MongoDbAdapter" } | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
namespace Alcaeus\MongoDbAdapter; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class TypeConverter | ||
{ | ||
public static function convertLegacyArrayToObject($array) | ||
{ | ||
// TODO: provide actual class | ||
$result = new \stdClass(); | ||
|
||
foreach ($array as $key => $value) { | ||
$result->$key = (is_array($value)) ? static::convertLegacyArrayToObject($value) : static::convertToModernType($value); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public static function convertObjectToLegacyArray($object) | ||
{ | ||
$result = []; | ||
|
||
foreach ($object as $key => $value) { | ||
// TODO: maybe add a more meaningful check instead of stdClass? | ||
$result[$key] = ($value instanceof \stdClass) ? static::convertObjectToLegacyArray($value) : static::convertToLegacyType($value); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public static function convertToLegacyType($value) | ||
{ | ||
switch (true) { | ||
case $value instanceof \MongoDB\Driver\ObjectID: | ||
return new \MongoId($value); | ||
|
||
default: | ||
return $value; | ||
} | ||
} | ||
|
||
public static function convertToModernType($value) | ||
{ | ||
switch (true) { | ||
case $value instanceof \MongoId: | ||
return $value->getObjectID(); | ||
|
||
default: | ||
return $value; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/** | ||
* The connection point between MongoDB and PHP. | ||
* This class is used to initiate a connection and for database server commands. | ||
* @link http://www.php.net/manual/en/class.mongo.php | ||
* @deprecated This class has been DEPRECATED as of version 1.3.0. | ||
* Relying on this feature is highly discouraged. Please use MongoClient instead. | ||
* @see MongoClient | ||
*/ | ||
class Mongo extends MongoClient { | ||
/** | ||
* @deprecated This feature has been DEPRECATED as of version 1.2.3. Relying on this feature is highly discouraged. Please use MongoPool::getSize() instead. | ||
* (PECL mongo >= 1.2.0)<br/> | ||
* Get pool size for connection pools | ||
* @link http://php.net/manual/en/mongo.getpoolsize.php | ||
* @return int Returns the current pool size. | ||
*/ | ||
public function getPoolSize() {} | ||
/** | ||
* (PECL mongo >= 1.1.0)<br/> | ||
* Returns the address being used by this for slaveOkay reads | ||
* @link http://php.net/manual/en/mongo.getslave.php | ||
* @return bool <p>The address of the secondary this connection is using for reads. | ||
* </p> | ||
* <p> | ||
* This returns <b>NULL</b> if this is not connected to a replica set or not yet | ||
* initialized. | ||
* </p> | ||
*/ | ||
public function getSlave() {} | ||
/** | ||
* (PECL mongo >= 1.1.0)<br/> | ||
* Get slaveOkay setting for this connection | ||
* @link http://php.net/manual/en/mongo.getslaveokay.php | ||
* @return bool Returns the value of slaveOkay for this instance. | ||
*/ | ||
public function getSlaveOkay() {} | ||
/** | ||
* Connects to paired database server | ||
* @deprecated Pass a string of the form "mongodb://server1,server2" to the constructor instead of using this method. | ||
* @link http://www.php.net/manual/en/mongo.pairconnect.php | ||
* @throws MongoConnectionException | ||
* @return boolean | ||
*/ | ||
public function pairConnect() {} | ||
|
||
/** | ||
* (PECL mongo >= 1.2.0)<br/> | ||
* @deprecated This feature has been DEPRECATED as of version 1.2.3. Relying on this feature is highly discouraged. Please use MongoPool::info() instead. | ||
* Returns information about all connection pools. | ||
* @link http://php.net/manual/en/mongo.pooldebug.php | ||
* @return array Each connection pool has an identifier, which starts with the host. For each pool, this function shows the following fields: | ||
* <p><b>in use</b></p> | ||
* <p>The number of connections currently being used by MongoClient instances. | ||
* in pool | ||
* The number of connections currently in the pool (not being used).</p> | ||
* <p><b>remaining</b></p> | ||
* | ||
* <p>The number of connections that could be created by this pool. For example, suppose a pool had 5 connections remaining and 3 connections in the pool. We could create 8 new instances of MongoClient before we exhausted this pool (assuming no instances of MongoClient went out of scope, returning their connections to the pool). | ||
* | ||
* A negative number means that this pool will spawn unlimited connections. | ||
* | ||
* Before a pool is created, you can change the max number of connections by calling Mongo::setPoolSize(). Once a pool is showing up in the output of this function, its size cannot be changed.</p> | ||
* <p><b>timeout</b></p> | ||
* | ||
* <p>The socket timeout for connections in this pool. This is how long connections in this pool will attempt to connect to a server before giving up.</p> | ||
* | ||
*/ | ||
public function poolDebug() {} | ||
|
||
/** | ||
* (PECL mongo >= 1.1.0)<br/> | ||
* Change slaveOkay setting for this connection | ||
* @link http://php.net/manual/en/mongo.setslaveokay.php | ||
* @param bool $ok [optional] <p class="para"> | ||
* If reads should be sent to secondary members of a replica set for all | ||
* possible queries using this {@see MongoClient} instance. | ||
* </p> | ||
* @return bool returns the former value of slaveOkay for this instance. | ||
*/ | ||
public function setSlaveOkay ($ok) {} | ||
/** | ||
* @deprecated Relying on this feature is highly discouraged. Please use MongoPool::setSize() instead. | ||
*(PECL mongo >= 1.2.0)<br/> | ||
* Set the size for future connection pools. | ||
* @link http://php.net/manual/en/mongo.setpoolsize.php | ||
* @param $size <p>The max number of connections future pools will be able to create. Negative numbers mean that the pool will spawn an infinite number of connections.</p> | ||
* @return bool Returns the former value of pool size. | ||
*/ | ||
public function setPoolSize($size) {} | ||
/** | ||
* Creates a persistent connection with a database server | ||
* @link http://www.php.net/manual/en/mongo.persistconnect.php | ||
* @deprecated Pass array("persist" => $id) to the constructor instead of using this method. | ||
* @param string $username A username used to identify the connection. | ||
* @param string $password A password used to identify the connection. | ||
* @throws MongoConnectionException | ||
* @return boolean If the connection was successful. | ||
*/ | ||
public function persistConnect($username = "", $password = "") {} | ||
|
||
/** | ||
* Creates a persistent connection with paired database servers | ||
* @deprecated Pass "mongodb://server1,server2" and array("persist" => $id) to the constructor instead of using this method. | ||
* @link http://www.php.net/manual/en/mongo.pairpersistconnect.php | ||
* @param string $username A username used to identify the connection. | ||
* @param string $password A password used to identify the connection. | ||
* @throws MongoConnectionException | ||
* @return boolean If the connection was successful. | ||
*/ | ||
public function pairPersistConnect($username = "", $password = "") {} | ||
|
||
/** | ||
* Connects with a database server | ||
* | ||
* @link http://www.php.net/manual/en/mongo.connectutil.php | ||
* @throws MongoConnectionException | ||
* @return boolean If the connection was successful. | ||
*/ | ||
protected function connectUtil() {} | ||
|
||
/** | ||
* Check if there was an error on the most recent db operation performed | ||
* @deprecated Use MongoDB::lastError() instead. | ||
* @link http://www.php.net/manual/en/mongo.lasterror.php | ||
* @return array|null Returns the error, if there was one, or NULL. | ||
*/ | ||
public function lastError() {} | ||
|
||
/** | ||
* Checks for the last error thrown during a database operation | ||
* @deprecated Use MongoDB::prevError() instead. | ||
* @link http://www.php.net/manual/en/mongo.preverror.php | ||
* @return array Returns the error and the number of operations ago it occurred. | ||
*/ | ||
public function prevError() {} | ||
|
||
/** | ||
* Clears any flagged errors on the connection | ||
* @deprecated Use MongoDB::resetError() instead. | ||
* @link http://www.php.net/manual/en/mongo.reseterror.php | ||
* @return array Returns the database response. | ||
*/ | ||
public function resetError() {} | ||
|
||
/** | ||
* Creates a database error on the database. | ||
* @deprecated Use MongoDB::forceError() instead. | ||
* @link http://www.php.net/manual/en/mongo.forceerror.php | ||
* @return boolean The database response. | ||
*/ | ||
public function forceError() {} | ||
} |
Oops, something went wrong.