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

Commit

Permalink
Remove $cmd args/properties and deprecate mongoCmd option
Browse files Browse the repository at this point in the history
Even if the "mongo.cmd" INI option is customized, the orignal "$" character may still be used. There is no functional reason to support a customizable command character in Doctrine.
  • Loading branch information
jmikola committed Sep 2, 2013
1 parent 97b70b4 commit cd3b601
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 209 deletions.
13 changes: 2 additions & 11 deletions lib/Doctrine/MongoDB/Collection.php
Expand Up @@ -70,13 +70,6 @@ class Collection
*/
protected $eventManager;

/**
* MongoDB command prefix.
*
* @var string
*/
protected $cmd;

/**
* Number of times to retry queries.
*
Expand All @@ -91,16 +84,14 @@ class Collection
* @param string $name The collection name
* @param Database $database Database to which this collection belongs
* @param EventManager $evm EventManager instance
* @param string $cmd MongoDB command prefix
* @param boolean|integer $numRetries Number of times to retry queries
*/
public function __construct(Connection $connection, $name, Database $database, EventManager $evm, $cmd, $numRetries = 0)
public function __construct(Connection $connection, $name, Database $database, EventManager $evm, $numRetries = 0)
{
$this->connection = $connection;
$this->name = $name;
$this->database = $database;
$this->eventManager = $evm;
$this->cmd = $cmd;
$this->numRetries = (integer) $numRetries;
}

Expand Down Expand Up @@ -205,7 +196,7 @@ public function createDBRef($documentOrId)
*/
public function createQueryBuilder()
{
return new Query\Builder($this->database, $this, $this->cmd);
return new Query\Builder($this->database, $this);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/MongoDB/Configuration.php
Expand Up @@ -61,20 +61,24 @@ public function setLoggerCallable($loggerCallable)
/**
* Get the MongoDB command prefix.
*
* @deprecated 1.1 No longer supported; will be removed for 1.2
* @return string
*/
public function getMongoCmd()
{
trigger_error('MongoDB command prefix option is no longer used', E_USER_DEPRECATED);
return $this->attributes['mongoCmd'];
}

/**
* Set the MongoDB command prefix.
*
* @deprecated 1.1 No longer supported; will be removed for 1.2
* @param string $cmd
*/
public function setMongoCmd($cmd)
{
trigger_error('MongoDB command prefix option is no longer used', E_USER_DEPRECATED);
$this->attributes['mongoCmd'] = $cmd;
}

Expand Down
12 changes: 2 additions & 10 deletions lib/Doctrine/MongoDB/Connection.php
Expand Up @@ -65,13 +65,6 @@ class Connection
*/
protected $eventManager;

/**
* MongoDB command prefix.
*
* @var string
*/
protected $cmd;

/**
* Constructor.
*
Expand All @@ -93,7 +86,6 @@ public function __construct($server = null, array $options = array(), Configurat
}
$this->config = $config ? $config : new Configuration();
$this->eventManager = $evm ? $evm : new EventManager();
$this->cmd = $this->config->getMongoCmd();
}

/**
Expand Down Expand Up @@ -416,9 +408,9 @@ protected function wrapDatabase($name)
$numRetries = $this->config->getRetryQuery();
if (null !== $this->config->getLoggerCallable()) {
return new LoggableDatabase(
$this, $name, $this->eventManager, $this->cmd, $numRetries, $this->config->getLoggerCallable()
$this, $name, $this->eventManager, $numRetries, $this->config->getLoggerCallable()
);
}
return new Database($this, $name, $this->eventManager, $this->cmd, $numRetries);
return new Database($this, $name, $this->eventManager, $numRetries);
}
}
15 changes: 3 additions & 12 deletions lib/Doctrine/MongoDB/Database.php
Expand Up @@ -58,13 +58,6 @@ class Database
*/
protected $eventManager;

/**
* MongoDB command prefix.
*
* @var string
*/
protected $cmd;

/**
* Number of times to retry queries.
*
Expand All @@ -78,15 +71,13 @@ class Database
* @param Connection $connection Connection used to create Collections
* @param string $name The database name
* @param EventManager $evm EventManager instance
* @param string $cmd MongoDB command prefix
* @param boolean|integer $numRetries Number of times to retry queries
*/
public function __construct(Connection $connection, $name, EventManager $evm, $cmd, $numRetries = 0)
public function __construct(Connection $connection, $name, EventManager $evm, $numRetries = 0)
{
$this->connection = $connection;
$this->name = $name;
$this->eventManager = $evm;
$this->cmd = $cmd;
$this->numRetries = (integer) $numRetries;
}

Expand Down Expand Up @@ -551,7 +542,7 @@ protected function doCreateCollection($name, array $options)
*/
protected function doGetGridFS($prefix)
{
return new GridFS($this->connection, $prefix, $this, $this->eventManager, $this->cmd);
return new GridFS($this->connection, $prefix, $this, $this->eventManager);
}

/**
Expand All @@ -563,7 +554,7 @@ protected function doGetGridFS($prefix)
*/
protected function doSelectCollection($name)
{
return new Collection($this->connection, $name, $this, $this->eventManager, $this->cmd, $this->numRetries);
return new Collection($this->connection, $name, $this, $this->eventManager, $this->numRetries);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/MongoDB/GridFS.php
Expand Up @@ -196,8 +196,8 @@ protected function doSave(array &$a, array $options = array())
*/
protected function doUpdate(array $query, array $newObj, array $options = array())
{
$file = isset($newObj[$this->cmd.'set']['file']) ? $newObj[$this->cmd.'set']['file'] : null;
unset($newObj[$this->cmd.'set']['file']);
$file = isset($newObj['$set']['file']) ? $newObj['$set']['file'] : null;
unset($newObj['$set']['file']);

if ($file === null) {
$file = isset($newObj['file']) ? $newObj['file'] : null;
Expand All @@ -207,8 +207,8 @@ protected function doUpdate(array $query, array $newObj, array $options = array(
/* Before we inspect $newObj, remove an empty $set operator we may have
* left behind due to extracting the file field above.
*/
if (empty($newObj[$this->cmd.'set'])) {
unset($newObj[$this->cmd.'set']);
if (empty($newObj['$set'])) {
unset($newObj['$set']);
}

/* Determine if $newObj includes atomic modifiers, which will tell us if
Expand All @@ -218,7 +218,7 @@ protected function doUpdate(array $query, array $newObj, array $options = array(
$newObjHasModifiers = false;

foreach (array_keys($newObj) as $key) {
if ($this->cmd === $key[0]) {
if ('$' === $key[0]) {
$newObjHasModifiers = true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Doctrine/MongoDB/LoggableCollection.php
Expand Up @@ -44,17 +44,16 @@ class LoggableCollection extends Collection implements Loggable
* @param string $name The collection name
* @param Database $database Database to which this collection belongs
* @param EventManager $evm EventManager instance
* @param string $cmd MongoDB command prefix
* @param callable $loggerCallable The logger callable
* @param boolean|integer $numRetries Number of times to retry queries
*/
public function __construct(Connection $connection, $name, Database $database, EventManager $evm, $cmd, $loggerCallable, $numRetries = 0)
public function __construct(Connection $connection, $name, Database $database, EventManager $evm, $loggerCallable, $numRetries = 0)
{
if ( ! is_callable($loggerCallable)) {
throw new \InvalidArgumentException('$loggerCallable must be a valid callback');
}
$this->loggerCallable = $loggerCallable;
parent::__construct($connection, $name, $database, $evm, $cmd, $numRetries);
parent::__construct($connection, $name, $database, $evm, $numRetries);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/MongoDB/LoggableDatabase.php
Expand Up @@ -43,16 +43,15 @@ class LoggableDatabase extends Database implements Loggable
* @param Connection $connection Connection used to create Collections
* @param string $name The database name
* @param EventManager $evm EventManager instance
* @param string $cmd MongoDB command prefix
* @param boolean|integer $numRetries Number of times to retry queries
* @param callable $loggerCallable The logger callable
*/
public function __construct(Connection $connection, $name, EventManager $evm, $cmd, $numRetries, $loggerCallable)
public function __construct(Connection $connection, $name, EventManager $evm, $numRetries, $loggerCallable)
{
if ( ! is_callable($loggerCallable)) {
throw new \InvalidArgumentException('$loggerCallable must be a valid callback');
}
parent::__construct($connection, $name, $evm, $cmd, $numRetries);
parent::__construct($connection, $name, $evm, $numRetries);
$this->loggerCallable = $loggerCallable;
}

Expand Down Expand Up @@ -165,7 +164,7 @@ public function getDBRef(array $ref)
protected function doSelectCollection($name)
{
return new LoggableCollection(
$this->connection, $name, $this, $this->eventManager, $this->cmd, $this->loggerCallable, $this->numRetries
$this->connection, $name, $this, $this->eventManager, $this->loggerCallable, $this->numRetries
);
}
}
22 changes: 6 additions & 16 deletions lib/Doctrine/MongoDB/Query/Builder.php
Expand Up @@ -54,13 +54,6 @@ class Builder
*/
protected $query = array('type' => Query::TYPE_FIND);

/**
* Mongo command prefix
*
* @var string
*/
protected $cmd;

/**
* The Expr instance used for building this query.
*
Expand All @@ -75,15 +68,12 @@ class Builder
* Create a new query builder.
*
* @param Database $database
* @param Collection $collection
* @param string $cmd
*/
public function __construct(Database $database, Collection $collection, $cmd)
public function __construct(Database $database, Collection $collection)
{
$this->database = $database;
$this->collection = $collection;
$this->expr = new Expr($cmd);
$this->cmd = $cmd;
$this->expr = new Expr();
}

/**
Expand Down Expand Up @@ -336,7 +326,7 @@ public function exists($bool)
*/
public function expr()
{
return new Expr($this->cmd);
return new Expr();
}

/**
Expand Down Expand Up @@ -598,7 +588,7 @@ public function getQuery(array $options = array())
$query = $this->query;
$query['query'] = $this->expr->getQuery();
$query['newObj'] = $this->expr->getNewObj();
return new Query($this->database, $this->collection, $query, $options, $this->cmd);
return new Query($this->database, $this->collection, $query, $options);
}

/**
Expand Down Expand Up @@ -1221,7 +1211,7 @@ public function selectElemMatch($fieldName, $expression)
if ($expression instanceof Expr) {
$expression = $expression->getQuery();
}
$this->query['select'][$fieldName] = array($this->cmd . 'elemMatch' => $expression);
$this->query['select'][$fieldName] = array('$elemMatch' => $expression);
return $this;
}

Expand All @@ -1248,7 +1238,7 @@ public function selectSlice($fieldName, $countOrSkip, $limit = null)
if ($limit !== null) {
$slice = array($slice, $limit);
}
$this->query['select'][$fieldName] = array($this->cmd . 'slice' => $slice);
$this->query['select'][$fieldName] = array('$slice' => $slice);
return $this;
}

Expand Down

0 comments on commit cd3b601

Please sign in to comment.