Permalink
Browse files

Remove $cmd args/properties

  • Loading branch information...
1 parent 37dad5e commit 338cf06c6614dcf536e3c03bb19645fb3fa94840 @jmikola jmikola committed Nov 1, 2013
View
21 lib/Doctrine/ODM/MongoDB/DocumentManager.php
@@ -121,13 +121,6 @@ class DocumentManager implements ObjectManager
private $closed = false;
/**
- * Mongo command character
- *
- * @var string
- */
- private $cmd;
-
- /**
* Collection of query filters.
*
* @var \Doctrine\ODM\MongoDB\Query\FilterCollection
@@ -145,7 +138,6 @@ class DocumentManager implements ObjectManager
protected function __construct(Connection $conn = null, Configuration $config = null, EventManager $eventManager = null) {
$this->config = $config ?: new Configuration();
$this->eventManager = $eventManager ?: new EventManager();
- $this->cmd = $this->config->getMongoCmd();
$this->connection = $conn ?: new Connection(null, array(), $this->config, $this->eventManager);
$metadataFactoryClassName = $this->config->getClassMetadataFactoryName();
@@ -163,11 +155,10 @@ protected function __construct(Connection $conn = null, Configuration $config =
$this->eventManager,
$hydratorDir,
$hydratorNs,
- $this->config->getAutoGenerateHydratorClasses(),
- $this->config->getMongoCmd()
+ $this->config->getAutoGenerateHydratorClasses()
);
- $this->unitOfWork = new UnitOfWork($this, $this->eventManager, $this->hydratorFactory, $this->cmd);
+ $this->unitOfWork = new UnitOfWork($this, $this->eventManager, $this->hydratorFactory);
$this->hydratorFactory->setUnitOfWork($this->unitOfWork);
$this->schemaManager = new SchemaManager($this, $this->metadataFactory);
$this->proxyFactory = new ProxyFactory($this,
@@ -369,7 +360,7 @@ public function getDocumentCollections()
*/
public function createQueryBuilder($documentName = null)
{
- return new Query\Builder($this, $this->cmd, $documentName);
+ return new Query\Builder($this, $documentName);
}
/**
@@ -710,9 +701,9 @@ public function createDBRef($document, array $referenceMapping = null)
}
$dbRef = array(
- $this->cmd . 'ref' => $class->getCollection(),
- $this->cmd . 'id' => $class->getDatabaseIdentifierValue($id),
- $this->cmd . 'db' => $this->getDocumentDatabase($className)->getName()
+ '$ref' => $class->getCollection(),
+ '$id' => $class->getDatabaseIdentifierValue($id),
+ '$db' => $this->getDocumentDatabase($className)->getName()
);
if ($class->discriminatorField) {
View
11 lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
@@ -88,22 +88,14 @@ class HydratorFactory
private $hydrators = array();
/**
- * Mongo command prefix
- *
- * @var string
- */
- private $cmd;
-
- /**
* @param DocumentManager $dm
* @param EventManager $evm
* @param string $hydratorDir
* @param string $hydratorNs
* @param boolean $autoGenerate
- * @param string $cmd
* @throws HydratorException
*/
- public function __construct(DocumentManager $dm, EventManager $evm, $hydratorDir, $hydratorNs, $autoGenerate, $cmd)
+ public function __construct(DocumentManager $dm, EventManager $evm, $hydratorDir, $hydratorNs, $autoGenerate)
{
if ( ! $hydratorDir) {
throw HydratorException::hydratorDirectoryRequired();
@@ -116,7 +108,6 @@ public function __construct(DocumentManager $dm, EventManager $evm, $hydratorDir
$this->hydratorDir = $hydratorDir;
$this->hydratorNamespace = $hydratorNs;
$this->autoGenerate = $autoGenerate;
- $this->cmd = $cmd;
}
/**
View
11 lib/Doctrine/ODM/MongoDB/PersistentCollection.php
@@ -88,13 +88,6 @@ class PersistentCollection implements BaseCollection
private $uow;
/**
- * Mongo command prefix
- *
- * @var string
- */
- private $cmd;
-
- /**
* The raw mongo data that will be used to initialize this collection.
*
* @var array
@@ -112,14 +105,12 @@ class PersistentCollection implements BaseCollection
* @param BaseCollection $coll
* @param DocumentManager $dm
* @param UnitOfWork $uow
- * @param string $cmd
*/
- public function __construct(BaseCollection $coll, DocumentManager $dm, UnitOfWork $uow, $cmd)
+ public function __construct(BaseCollection $coll, DocumentManager $dm, UnitOfWork $uow)
{
$this->coll = $coll;
$this->dm = $dm;
$this->uow = $uow;
- $this->cmd = $cmd;
}
/**
View
25 lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php
@@ -57,26 +57,17 @@ class CollectionPersister
private $pb;
/**
- * Mongo command prefix
- *
- * @var string
- */
- private $cmd;
-
- /**
* Constructs a new CollectionPersister instance.
*
* @param DocumentManager $dm
* @param PersistenceBuilder $pb
* @param UnitOfWork $uow
- * @param string $cmd
*/
- public function __construct(DocumentManager $dm, PersistenceBuilder $pb, UnitOfWork $uow, $cmd)
+ public function __construct(DocumentManager $dm, PersistenceBuilder $pb, UnitOfWork $uow)
{
$this->dm = $dm;
$this->pb = $pb;
$this->uow = $uow;
- $this->cmd = $cmd;
}
/**
@@ -92,7 +83,7 @@ public function delete(PersistentCollection $coll, array $options)
return; // ignore inverse side
}
list($propertyPath, $parent) = $this->getPathAndParent($coll);
- $query = array($this->cmd . 'unset' => array($propertyPath => true));
+ $query = array('$unset' => array($propertyPath => true));
$this->executeQuery($parent, $query, $options);
}
@@ -156,7 +147,7 @@ private function setCollection(PersistentCollection $coll, array $options)
$setData = array_values($setData);
}
- $query = array($this->cmd.'set' => array($propertyPath => $setData));
+ $query = array('$set' => array($propertyPath => $setData));
$this->executeQuery($parent, $query, $options);
}
@@ -180,10 +171,10 @@ private function deleteElements(PersistentCollection $coll, array $options)
list($propertyPath, $parent) = $this->getPathAndParent($coll);
- $query = array($this->cmd . 'unset' => array());
+ $query = array('$unset' => array());
foreach ($deleteDiff as $key => $document) {
- $query[$this->cmd . 'unset'][$propertyPath . '.' . $key] = true;
+ $query['$unset'][$propertyPath . '.' . $key] = true;
}
$this->executeQuery($parent, $query, $options);
@@ -194,7 +185,7 @@ private function deleteElements(PersistentCollection $coll, array $options)
* in the element being left in the array as null so we have to pull
* null values.
*/
- $this->executeQuery($parent, array($this->cmd . 'pull' => array($propertyPath => null)), $options);
+ $this->executeQuery($parent, array('$pull' => array($propertyPath => null)), $options);
}
/**
@@ -226,10 +217,10 @@ private function insertElements(PersistentCollection $coll, array $options)
$value = array_values(array_map($callback, $insertDiff));
if ($mapping['strategy'] !== 'pushAll') {
- $value = array($this->cmd . 'each' => $value);
+ $value = array('$each' => $value);
}
- $query = array($this->cmd . $mapping['strategy'] => array($propertyPath => $value));
+ $query = array('$' . $mapping['strategy'] => array($propertyPath => $value));
$this->executeQuery($parent, $query, $options);
}
View
57 lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
@@ -105,13 +105,6 @@ class DocumentPersister
private $queuedInserts = array();
/**
- * Mongo command prefix
- *
- * @var string
- */
- private $cmd;
-
- /**
* The CriteriaMerger instance.
*
* @var CriteriaMerger
@@ -127,14 +120,12 @@ class DocumentPersister
* @param UnitOfWork $uow
* @param HydratorFactory $hydratorFactory
* @param ClassMetadata $class
- * @param string $cmd
*/
- public function __construct(PersistenceBuilder $pb, DocumentManager $dm, EventManager $evm, UnitOfWork $uow, HydratorFactory $hydratorFactory, ClassMetadata $class, $cmd, CriteriaMerger $cm = null)
+ public function __construct(PersistenceBuilder $pb, DocumentManager $dm, EventManager $evm, UnitOfWork $uow, HydratorFactory $hydratorFactory, ClassMetadata $class, CriteriaMerger $cm = null)
{
$this->pb = $pb;
$this->dm = $dm;
$this->evm = $evm;
- $this->cmd = $cmd;
$this->cm = $cm ?: new CriteriaMerger();
$this->uow = $uow;
$this->hydratorFactory = $hydratorFactory;
@@ -251,11 +242,11 @@ public function executeInserts(array $options = array())
$upsertOptions = $options;
$upsertOptions['upsert'] = true;
foreach ($upserts as $oid => $data) {
- $criteria = array('_id' => $data[$this->cmd . 'set']['_id']);
- unset($data[$this->cmd . 'set']['_id']);
+ $criteria = array('_id' => $data['$set']['_id']);
+ unset($data['$set']['_id']);
// stupid php
- if (empty($data[$this->cmd . 'set'])) {
- $data[$this->cmd . 'set'] = new \stdClass;
+ if (empty($data['$set'])) {
+ $data['$set'] = new \stdClass;
}
$this->collection->update($criteria, $data, $upsertOptions);
}
@@ -289,12 +280,12 @@ public function update($document, array $options = array())
$currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
if ($versionMapping['type'] === 'int') {
$nextVersion = $currentVersion + 1;
- $update[$this->cmd . 'inc'][$versionMapping['name']] = 1;
+ $update['$inc'][$versionMapping['name']] = 1;
$query[$versionMapping['name']] = $currentVersion;
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersion = new \DateTime();
- $update[$this->cmd . 'set'][$versionMapping['name']] = new \MongoDate($nextVersion->getTimestamp());
+ $update['$set'][$versionMapping['name']] = new \MongoDate($nextVersion->getTimestamp());
$query[$versionMapping['name']] = new \MongoDate($currentVersion->getTimestamp());
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
}
@@ -307,13 +298,13 @@ public function update($document, array $options = array())
$isLocked = $this->class->reflFields[$this->class->lockField]->getValue($document);
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
if ($isLocked) {
- $update[$this->cmd . 'unset'] = array($lockMapping['name'] => true);
+ $update['$unset'] = array($lockMapping['name'] => true);
} else {
- $query[$lockMapping['name']] = array($this->cmd . 'exists' => false);
+ $query[$lockMapping['name']] = array('$exists' => false);
}
}
- unset($update[$this->cmd . 'set']['_id']);
+ unset($update['$set']['_id']);
$result = $this->collection->update($query, $update, $options);
if (($this->class->isVersioned || $this->class->isLockable) && ! $result['n']) {
@@ -335,7 +326,7 @@ public function delete($document, array $options = array())
$query = array('_id' => $this->class->getDatabaseIdentifierValue($id));
if ($this->class->isLockable) {
- $query[$this->class->lockField] = array($this->cmd . 'exists' => false);
+ $query[$this->class->lockField] = array('$exists' => false);
$options['safe'] = true;
}
@@ -500,7 +491,7 @@ public function lock($document, $lockMode)
$id = $this->uow->getDocumentIdentifier($document);
$criteria = array('_id' => $this->class->getDatabaseIdentifierValue($id));
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
- $this->collection->update($criteria, array($this->cmd . 'set' => array($lockMapping['name'] => $lockMode)));
+ $this->collection->update($criteria, array('$set' => array($lockMapping['name'] => $lockMode)));
$this->class->reflFields[$this->class->lockField]->setValue($document, $lockMode);
}
@@ -514,7 +505,7 @@ public function unlock($document)
$id = $this->uow->getDocumentIdentifier($document);
$criteria = array('_id' => $this->class->getDatabaseIdentifierValue($id));
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
- $this->collection->update($criteria, array($this->cmd . 'unset' => array($lockMapping['name'] => true)));
+ $this->collection->update($criteria, array('$unset' => array($lockMapping['name'] => true)));
$this->class->reflFields[$this->class->lockField]->setValue($document, null);
}
@@ -560,7 +551,6 @@ public function primeCollection(Iterator $collection, $fieldName, $primer, array
$fieldMapping = $collectionMetaData->fieldMappings[$fieldName];
- $cmd = $this->cmd;
$groupedIds = array();
foreach ($collection as $element) {
@@ -573,7 +563,7 @@ public function primeCollection(Iterator $collection, $fieldName, $primer, array
$mongoId = $reference;
} else {
$className = $this->dm->getClassNameFromDiscriminatorValue($fieldMapping, $reference);
- $mongoId = $reference[$cmd . 'id'];
+ $mongoId = $reference['$id'];
}
$id = $this->dm->getClassMetadata($className)->getPHPIdentifierValue($mongoId);
$document = $this->uow->tryGetById($id, $className);
@@ -665,7 +655,6 @@ private function loadReferenceManyCollectionOwningSide(PersistentCollection $col
{
$hints = $collection->getHints();
$mapping = $collection->getMapping();
- $cmd = $this->cmd;
$groupedIds = array();
$sorted = isset($mapping['sort']) && $mapping['sort'];
@@ -676,7 +665,7 @@ private function loadReferenceManyCollectionOwningSide(PersistentCollection $col
$mongoId = $reference;
} else {
$className = $this->dm->getClassNameFromDiscriminatorValue($mapping, $reference);
- $mongoId = $reference[$cmd . 'id'];
+ $mongoId = $reference['$id'];
}
$id = $this->dm->getClassMetadata($className)->getPHPIdentifierValue($mongoId);
if ( ! $id) {
@@ -704,7 +693,7 @@ private function loadReferenceManyCollectionOwningSide(PersistentCollection $col
$class = $this->dm->getClassMetadata($className);
$mongoCollection = $this->dm->getDocumentCollection($className);
$criteria = $this->cm->merge(
- array('_id' => array($cmd . 'in' => $ids)),
+ array('_id' => array('$in' => $ids)),
$this->dm->getFilterCollection()->getFilterCriteria($class),
isset($mapping['criteria']) ? $mapping['criteria'] : array()
);
@@ -918,14 +907,14 @@ public function prepareQueryOrNewObj(array $query)
foreach ($query as $key => $value) {
// Recursively prepare logical query clauses
- if (in_array($key, array($this->cmd . 'and', $this->cmd . 'or', $this->cmd . 'nor')) && is_array($value)) {
+ if (in_array($key, array('$and', '$or', '$nor')) && is_array($value)) {
foreach ($value as $k2 => $v2) {
$preparedQuery[$key][$k2] = $this->prepareQueryOrNewObj($v2);
}
continue;
}
- if (isset($key[0]) && $key[0] === $this->cmd && is_array($value)) {
+ if (isset($key[0]) && $key[0] === '$' && is_array($value)) {
$preparedQuery[$key] = $this->prepareQueryOrNewObj($value);
continue;
}
@@ -987,12 +976,12 @@ private function prepareQueryElement($fieldName, $value = null, $class = null, $
foreach ($value as $k => $v) {
// Ignore query operators whose arguments need no type conversion
- if (in_array($k, array($this->cmd . 'exists', $this->cmd . 'type', $this->cmd . 'mod', $this->cmd . 'size'))) {
+ if (in_array($k, array('$exists', '$type', '$mod', '$size'))) {
continue;
}
// Process query operators whose arguments need type conversion (e.g. "$in")
- if (isset($k[0]) && $k[0] === $this->cmd && is_array($v)) {
+ if (isset($k[0]) && $k[0] === '$' && is_array($v)) {
foreach ($v as $k2 => $v2) {
$value[$k][$k2] = $targetClass->getDatabaseIdentifierValue($v2);
}
@@ -1019,12 +1008,12 @@ private function prepareQueryElement($fieldName, $value = null, $class = null, $
foreach ($value as $k => $v) {
// Ignore query operators whose arguments need no type conversion
- if (in_array($k, array($this->cmd . 'exists', $this->cmd . 'type', $this->cmd . 'mod', $this->cmd . 'size'))) {
+ if (in_array($k, array('$exists', '$type', '$mod', '$size'))) {
continue;
}
// Process query operators whose arguments need type conversion (e.g. "$in")
- if (isset($k[0]) && $k[0] === $this->cmd && is_array($v)) {
+ if (isset($k[0]) && $k[0] === '$' && is_array($v)) {
foreach ($v as $k2 => $v2) {
$value[$k][$k2] = $class->getDatabaseIdentifierValue($v2);
}
@@ -1125,7 +1114,7 @@ private function prepareQueryElement($fieldName, $value = null, $class = null, $
foreach ($value as $k => $v) {
// Process query operators (e.g. "$in")
- if (isset($k[0]) && $k[0] === $this->cmd && is_array($v)) {
+ if (isset($k[0]) && $k[0] === '$' && is_array($v)) {
foreach ($v as $k2 => $v2) {
$value[$k][$k2] = $class->getDatabaseIdentifierValue($v2);
}
View
36 lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php
@@ -53,13 +53,11 @@ class PersistenceBuilder
*
* @param DocumentManager $dm
* @param UnitOfWork $uow
- * @param string $cmd
*/
- public function __construct(DocumentManager $dm, UnitOfWork $uow, $cmd)
+ public function __construct(DocumentManager $dm, UnitOfWork $uow)
{
$this->dm = $dm;
$this->uow = $uow;
- $this->cmd = $cmd;
}
/**
@@ -173,33 +171,33 @@ public function prepareUpdateData($document)
if ($mapping['type'] === 'increment') {
if ($new === null) {
if ($mapping['nullable'] === true) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = null;
+ $updateData['$set'][$mapping['name']] = null;
} else {
- $updateData[$this->cmd . 'unset'][$mapping['name']] = true;
+ $updateData['$unset'][$mapping['name']] = true;
}
} elseif ($new >= $old) {
- $updateData[$this->cmd . 'inc'][$mapping['name']] = $new - $old;
+ $updateData['$inc'][$mapping['name']] = $new - $old;
} else {
- $updateData[$this->cmd . 'inc'][$mapping['name']] = ($old - $new) * -1;
+ $updateData['$inc'][$mapping['name']] = ($old - $new) * -1;
}
// @Field, @String, @Date, etc.
} elseif ( ! isset($mapping['association'])) {
if (isset($new) || $mapping['nullable'] === true) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = (is_null($new) ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new));
+ $updateData['$set'][$mapping['name']] = (is_null($new) ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new));
} else {
- $updateData[$this->cmd . 'unset'][$mapping['name']] = true;
+ $updateData['$unset'][$mapping['name']] = true;
}
// @EmbedOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
// If we have a new embedded document then lets set the whole thing
if ($new && $this->uow->isScheduledForInsert($new)) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
+ $updateData['$set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
// If we don't have a new value then lets unset the embedded document
} elseif ( ! $new) {
- $updateData[$this->cmd . 'unset'][$mapping['name']] = true;
+ $updateData['$unset'][$mapping['name']] = true;
// Update existing embedded document
} else {
@@ -229,9 +227,9 @@ public function prepareUpdateData($document)
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) {
if (isset($new) || $mapping['nullable'] === true) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = (is_null($new) ? null : $this->prepareReferencedDocumentValue($mapping, $new));
+ $updateData['$set'][$mapping['name']] = (is_null($new) ? null : $this->prepareReferencedDocumentValue($mapping, $new));
} else {
- $updateData[$this->cmd . 'unset'][$mapping['name']] = true;
+ $updateData['$unset'][$mapping['name']] = true;
}
// @ReferenceMany
@@ -262,22 +260,22 @@ public function prepareUpsertData($document)
// @Inc
if ($mapping['type'] === 'increment') {
if ($new >= $old) {
- $updateData[$this->cmd . 'inc'][$mapping['name']] = $new - $old;
+ $updateData['$inc'][$mapping['name']] = $new - $old;
} else {
- $updateData[$this->cmd . 'inc'][$mapping['name']] = ($old - $new) * -1;
+ $updateData['$inc'][$mapping['name']] = ($old - $new) * -1;
}
// @Field, @String, @Date, etc.
} elseif ( ! isset($mapping['association'])) {
if (isset($new) || $mapping['nullable'] === true) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = (is_null($new) ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new));
+ $updateData['$set'][$mapping['name']] = (is_null($new) ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new));
}
// @EmbedOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
// If we have a new embedded document then lets set the whole thing
if ($new && $this->uow->isScheduledForInsert($new)) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
+ $updateData['$set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
// If we don't have a new value then do nothing on upsert
} elseif ( ! $new) {
@@ -308,7 +306,7 @@ public function prepareUpsertData($document)
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE && $mapping['isOwningSide']) {
if (isset($new) || $mapping['nullable'] === true) {
- $updateData[$this->cmd . 'set'][$mapping['name']] = (is_null($new) ? null : $this->prepareReferencedDocumentValue($mapping, $new));
+ $updateData['$set'][$mapping['name']] = (is_null($new) ? null : $this->prepareReferencedDocumentValue($mapping, $new));
}
// @ReferenceMany
@@ -319,7 +317,7 @@ public function prepareUpsertData($document)
// add discriminator if the class has one
if ($class->hasDiscriminator()) {
- $updateData[$this->cmd . 'set'][$class->discriminatorField['name']] = $class->discriminatorValue;
+ $updateData['$set'][$class->discriminatorField['name']] = $class->discriminatorValue;
}
return $updateData;
View
9 lib/Doctrine/ODM/MongoDB/Query/Builder.php
@@ -86,14 +86,12 @@ class Builder extends \Doctrine\MongoDB\Query\Builder
* Construct a Builder
*
* @param DocumentManager $dm
- * @param string $cmd
* @param string[]|string|null $documentName (optional) an array of document names, the document name, or none
*/
- public function __construct(DocumentManager $dm, $cmd, $documentName = null)
+ public function __construct(DocumentManager $dm, $documentName = null)
{
$this->dm = $dm;
- $this->expr = new Expr($dm, $cmd);
- $this->cmd = $cmd;
+ $this->expr = new Expr($dm);
if ($documentName !== null) {
$this->setDocumentName($documentName);
}
@@ -289,7 +287,6 @@ public function getQuery(array $options = array())
$this->collection,
$query,
$options,
- $this->cmd,
$this->hydrate,
$this->refresh,
$this->primers,
@@ -304,7 +301,7 @@ public function getQuery(array $options = array())
*/
public function expr()
{
- $expr = new Expr($this->dm, $this->cmd);
+ $expr = new Expr($this->dm);
$expr->setClassMetadata($this->class);
return $expr;
View
11 lib/Doctrine/ODM/MongoDB/Query/Expr.php
@@ -44,10 +44,9 @@ class Expr extends \Doctrine\MongoDB\Query\Expr
*/
private $class;
- public function __construct(DocumentManager $dm, $cmd)
+ public function __construct(DocumentManager $dm)
{
$this->dm = $dm;
- $this->cmd = $cmd;
}
public function setClassMetadata(ClassMetadata $class)
@@ -74,7 +73,7 @@ public function references($document)
}
foreach ($keys as $key => $value) {
- $this->query[$this->currentField . '.' . $this->cmd . $key] = $dbRef[$this->cmd . $key];
+ $this->query[$this->currentField . '.$' . $key] = $dbRef['$' . $key];
}
}
} else {
@@ -95,7 +94,7 @@ public function includesReferenceTo($document)
$dbRef = $this->dm->createDBRef($document, $mapping);
if (isset($mapping['simple']) && $mapping['simple']) {
- $this->query[$mapping['name']][$this->cmd . 'elemMatch'] = $dbRef;
+ $this->query[$mapping['name']]['$elemMatch'] = $dbRef;
} else {
$keys = array('ref' => true, 'id' => true, 'db' => true);
@@ -104,12 +103,12 @@ public function includesReferenceTo($document)
}
foreach ($keys as $key => $value) {
- $this->query[$this->currentField][$this->cmd . 'elemMatch'][$this->cmd . $key] = $dbRef[$this->cmd . $key];
+ $this->query[$this->currentField]['$elemMatch']['$' . $key] = $dbRef['$' . $key];
}
}
} else {
$dbRef = $this->dm->createDBRef($document);
- $this->query[$this->cmd . 'elemMatch'] = $dbRef;
+ $this->query['$elemMatch'] = $dbRef;
}
return $this;
View
12 lib/Doctrine/ODM/MongoDB/Query/FieldExtractor.php
@@ -29,22 +29,20 @@ class FieldExtractor
{
private $query;
private $sort;
- private $cmd;
- public function __construct(array $query, array $sort = array(), $cmd = '$')
+ public function __construct(array $query, array $sort = array())
{
$this->query = $query;
$this->sort = $sort;
- $this->cmd = $cmd;
}
public function getFields()
{
$fields = array();
foreach ($this->query as $k => $v) {
- if (is_array($v) && isset($v[$this->cmd.'elemMatch'])) {
- $elemMatchFields = $this->getFieldsFromElemMatch($v[$this->cmd.'elemMatch']);
+ if (is_array($v) && isset($v['$elemMatch'])) {
+ $elemMatchFields = $this->getFieldsFromElemMatch($v['$elemMatch']);
foreach ($elemMatchFields as $field) {
$fields[] = $k.'.'.$field;
}
@@ -53,7 +51,7 @@ public function getFields()
$test = new self($q);
$fields = array_merge($fields, $test->getFields());
}
- } elseif ($k[0] !== $this->cmd) {
+ } elseif ($k[0] !== '$') {
$fields[] = $k;
}
}
@@ -87,7 +85,7 @@ private function isOperator($fieldName, $operator)
$operator = array($operator);
}
foreach ($operator as $op) {
- if ($fieldName === $this->cmd.$op) {
+ if ($fieldName === '$' . $op) {
return true;
}
}
View
5 lib/Doctrine/ODM/MongoDB/Query/Query.php
@@ -92,15 +92,14 @@ class Query extends \Doctrine\MongoDB\Query\Query
* @param Collection $collection
* @param array $query
* @param array $options
- * @param string $cmd
* @param bool $hydrate
* @param bool $refresh
* @param array $primers
* @param null $requireIndexes
*/
- public function __construct(DocumentManager $dm, ClassMetadata $class, Database $database, Collection $collection, array $query = array(), array $options = array(), $cmd = '$', $hydrate = true, $refresh = false, array $primers = array(), $requireIndexes = null)
+ public function __construct(DocumentManager $dm, ClassMetadata $class, Database $database, Collection $collection, array $query = array(), array $options = array(), $hydrate = true, $refresh = false, array $primers = array(), $requireIndexes = null)
{
- parent::__construct($database, $collection, $query, $options, $cmd);
+ parent::__construct($database, $collection, $query, $options);
$this->dm = $dm;
$this->class = $class;
$this->hydrate = $hydrate;
View
21 lib/Doctrine/ODM/MongoDB/UnitOfWork.php
@@ -251,26 +251,17 @@ class UnitOfWork implements PropertyChangedListener
private $parentAssociations = array();
/**
- * Mongo command character
- *
- * @var string
- */
- private $cmd;
-
- /**
* Initializes a new UnitOfWork instance, bound to the given DocumentManager.
*
* @param DocumentManager $dm
* @param EventManager $evm
* @param HydratorFactory $hydratorFactory
- * @param string $cmd
*/
- public function __construct(DocumentManager $dm, EventManager $evm, HydratorFactory $hydratorFactory, $cmd)
+ public function __construct(DocumentManager $dm, EventManager $evm, HydratorFactory $hydratorFactory)
{
$this->dm = $dm;
$this->evm = $evm;
$this->hydratorFactory = $hydratorFactory;
- $this->cmd = $cmd;
}
/**
@@ -282,7 +273,7 @@ public function __construct(DocumentManager $dm, EventManager $evm, HydratorFact
public function getPersistenceBuilder()
{
if ( ! $this->persistenceBuilder) {
- $this->persistenceBuilder = new PersistenceBuilder($this->dm, $this, $this->cmd);
+ $this->persistenceBuilder = new PersistenceBuilder($this->dm, $this);
}
return $this->persistenceBuilder;
}
@@ -331,7 +322,7 @@ public function getDocumentPersister($documentName)
if ( ! isset($this->persisters[$documentName])) {
$class = $this->dm->getClassMetadata($documentName);
$pb = $this->getPersistenceBuilder();
- $this->persisters[$documentName] = new Persisters\DocumentPersister($pb, $this->dm, $this->evm, $this, $this->hydratorFactory, $class, $this->cmd);
+ $this->persisters[$documentName] = new Persisters\DocumentPersister($pb, $this->dm, $this->evm, $this, $this->hydratorFactory, $class);
}
return $this->persisters[$documentName];
}
@@ -345,7 +336,7 @@ public function getCollectionPersister()
{
if ( ! isset($this->collectionPersister)) {
$pb = $this->getPersistenceBuilder();
- $this->collectionPersister = new Persisters\CollectionPersister($this->dm, $pb, $this, $this->cmd);
+ $this->collectionPersister = new Persisters\CollectionPersister($this->dm, $pb, $this);
}
return $this->collectionPersister;
}
@@ -597,7 +588,7 @@ public function getDocumentActualData($document)
}
// Inject PersistentCollection
- $coll = new PersistentCollection($value, $this->dm, $this, $this->cmd);
+ $coll = new PersistentCollection($value, $this->dm, $this);
$coll->setOwner($document, $mapping);
$coll->setDirty( ! $value->isEmpty());
$class->reflFields[$name]->setValue($document, $coll);
@@ -2056,7 +2047,7 @@ private function doMerge($document, array &$visited)
if ( ! $mergeCol instanceof Collection) {
$mergeCol = new ArrayCollection($mergeCol);
}
- $mergeCol = new PersistentCollection($mergeCol, $this->dm, $this, $this->cmd);
+ $mergeCol = new PersistentCollection($mergeCol, $this->dm, $this);
$mergeCol->setInitialized(true);
} else {
$mergeCol->setDocumentManager($this->dm);
View
4 tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php
@@ -150,8 +150,8 @@ private function getTestUser($username)
private function getCollectionPersister()
{
$uow = $this->dm->getUnitOfWork();
- $pb = new PersistenceBuilder($this->dm, $uow, '$');
- return new CollectionPersister($this->dm, $pb, $uow, '$');
+ $pb = new PersistenceBuilder($this->dm, $uow);
+ return new CollectionPersister($this->dm, $pb, $uow);
}
public function testNestedEmbedManySetStrategy()
View
2 tests/Doctrine/ODM/MongoDB/Tests/PersistentCollectionTest.php
@@ -19,7 +19,7 @@ public function testSlice()
->will($this->returnValue(true));
$dm = $this->getMockDocumentManager();
$uow = $this->getMockUnitOfWork();
- $pCollection = new PersistentCollection($collection, $dm, $uow, '$');
+ $pCollection = new PersistentCollection($collection, $dm, $uow);
$pCollection->slice($start, $limit);
}
View
4 tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php
@@ -216,7 +216,7 @@ public function testReferencesUsesMinimalKeys()
->method('getFieldMapping')
->will($this->returnValue(array('targetDocument' => 'Foo')));
- $expr = new Expr($dm, '$');
+ $expr = new Expr($dm);
$expr->setClassMetadata($class);
$expr->field('foo')->references(new \stdClass());
@@ -257,7 +257,7 @@ public function testReferencesUsesAllKeys()
->method('getFieldMapping')
->will($this->returnValue(array()));
- $expr = new Expr($dm, '$');
+ $expr = new Expr($dm);
$expr->setClassMetadata($class);
$expr->field('foo')->references(new \stdClass());
View
4 tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php
@@ -383,7 +383,7 @@ protected function getDocumentManager()
protected function getUnitOfWork(DocumentManager $dm)
{
- return new UnitOfWork($dm, $this->getMockEventManager(), $this->getMockHydratorFactory(), '$');
+ return new UnitOfWork($dm, $this->getMockEventManager(), $this->getMockHydratorFactory());
}
/**
@@ -422,7 +422,7 @@ private function getMockPersistenceBuilder()
private function getMockDocumentPersister(PersistenceBuilder $pb, ClassMetadata $class)
{
- return new DocumentPersisterMock($pb, $this->dm, $this->dm->getEventManager(), $this->uow, $this->dm->getHydratorFactory(), $class, '$');
+ return new DocumentPersisterMock($pb, $this->dm, $this->dm->getEventManager(), $this->uow, $this->dm->getHydratorFactory(), $class);
}
protected function getClassMetadata($class, $flag)

0 comments on commit 338cf06

Please sign in to comment.