-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use wrapper for MongoCollection, fixes #209
- Loading branch information
1 parent
1c4df65
commit 2dcb459
Showing
5 changed files
with
75 additions
and
51 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,68 @@ | ||
<?php namespace Jenssegers\Mongodb; | ||
|
||
use Exception; | ||
use MongoCollection; | ||
use Jenssegers\Mongodb\Connection; | ||
|
||
class Collection { | ||
|
||
/** | ||
* The connection instance. | ||
* | ||
* @var Connection | ||
*/ | ||
protected $connection; | ||
|
||
/** | ||
* The MongoCollection instance.. | ||
* | ||
* @var MongoCollection | ||
*/ | ||
protected $collection; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct(Connection $connection, MongoCollection $collection) | ||
{ | ||
$this->connection = $connection; | ||
$this->collection = $collection; | ||
} | ||
|
||
/** | ||
* Handle dynamic method calls. | ||
* | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function __call($method, $parameters) | ||
{ | ||
// Build the query string. | ||
$query = $parameters; | ||
foreach ($query as &$param) | ||
{ | ||
try | ||
{ | ||
$param = json_encode($param); | ||
} | ||
catch (Exception $e) | ||
{ | ||
$param = '{...}'; | ||
} | ||
} | ||
|
||
$start = microtime(true); | ||
|
||
// Execute the query. | ||
$result = call_user_func_array(array($this->collection, $method), $parameters); | ||
|
||
// Log the query. | ||
$this->connection->logQuery( | ||
$this->collection->getName() . '.' . $method . '(' . join(',', $query) . ')', | ||
array(), $this->connection->getElapsedTime($start)); | ||
|
||
return $result; | ||
} | ||
|
||
} |
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
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
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
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