repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 39
1.84M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.executeInserts | public function executeInserts(array $options = []) : void
{
if (! $this->queuedInserts) {
return;
}
$inserts = [];
$options = $this->getWriteOptions($options);
foreach ($this->queuedInserts as $oid => $document) {
$data = $this->pb->prepareInsertData($document);
// Set the initial version for each insert
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$nextVersion = null;
if ($versionMapping['type'] === 'int') {
$nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersionDateTime = new DateTime();
$nextVersion = Type::convertPHPToDatabaseValue($nextVersionDateTime);
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
}
$data[$versionMapping['name']] = $nextVersion;
}
$inserts[] = $data;
}
if ($inserts) {
try {
assert($this->collection instanceof Collection);
$this->collection->insertMany($inserts, $options);
} catch (DriverException $e) {
$this->queuedInserts = [];
throw $e;
}
}
/* All collections except for ones using addToSet have already been
* saved. We have left these to be handled separately to avoid checking
* collection for uniqueness on PHP side.
*/
foreach ($this->queuedInserts as $document) {
$this->handleCollections($document, $options);
}
$this->queuedInserts = [];
} | php | public function executeInserts(array $options = []) : void
{
if (! $this->queuedInserts) {
return;
}
$inserts = [];
$options = $this->getWriteOptions($options);
foreach ($this->queuedInserts as $oid => $document) {
$data = $this->pb->prepareInsertData($document);
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$nextVersion = null;
if ($versionMapping['type'] === 'int') {
$nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersionDateTime = new DateTime();
$nextVersion = Type::convertPHPToDatabaseValue($nextVersionDateTime);
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
}
$data[$versionMapping['name']] = $nextVersion;
}
$inserts[] = $data;
}
if ($inserts) {
try {
assert($this->collection instanceof Collection);
$this->collection->insertMany($inserts, $options);
} catch (DriverException $e) {
$this->queuedInserts = [];
throw $e;
}
}
foreach ($this->queuedInserts as $document) {
$this->handleCollections($document, $options);
}
$this->queuedInserts = [];
} | [
"public",
"function",
"executeInserts",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"queuedInserts",
")",
"{",
"return",
";",
"}",
"$",
"inserts",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"queuedInserts",
"as",
"$",
"oid",
"=>",
"$",
"document",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"pb",
"->",
"prepareInsertData",
"(",
"$",
"document",
")",
";",
"// Set the initial version for each insert",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
")",
"{",
"$",
"versionMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
";",
"$",
"nextVersion",
"=",
"null",
";",
"if",
"(",
"$",
"versionMapping",
"[",
"'type'",
"]",
"===",
"'int'",
")",
"{",
"$",
"nextVersion",
"=",
"max",
"(",
"1",
",",
"(",
"int",
")",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
")",
";",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"nextVersion",
")",
";",
"}",
"elseif",
"(",
"$",
"versionMapping",
"[",
"'type'",
"]",
"===",
"'date'",
")",
"{",
"$",
"nextVersionDateTime",
"=",
"new",
"DateTime",
"(",
")",
";",
"$",
"nextVersion",
"=",
"Type",
"::",
"convertPHPToDatabaseValue",
"(",
"$",
"nextVersionDateTime",
")",
";",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"nextVersionDateTime",
")",
";",
"}",
"$",
"data",
"[",
"$",
"versionMapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"nextVersion",
";",
"}",
"$",
"inserts",
"[",
"]",
"=",
"$",
"data",
";",
"}",
"if",
"(",
"$",
"inserts",
")",
"{",
"try",
"{",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"this",
"->",
"collection",
"->",
"insertMany",
"(",
"$",
"inserts",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"DriverException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"queuedInserts",
"=",
"[",
"]",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"/* All collections except for ones using addToSet have already been\n * saved. We have left these to be handled separately to avoid checking\n * collection for uniqueness on PHP side.\n */",
"foreach",
"(",
"$",
"this",
"->",
"queuedInserts",
"as",
"$",
"document",
")",
"{",
"$",
"this",
"->",
"handleCollections",
"(",
"$",
"document",
",",
"$",
"options",
")",
";",
"}",
"$",
"this",
"->",
"queuedInserts",
"=",
"[",
"]",
";",
"}"
] | Executes all queued document insertions.
Queued documents without an ID will inserted in a batch and queued
documents with an ID will be upserted individually.
If no inserts are queued, invoking this method is a NOOP.
@throws DriverException | [
"Executes",
"all",
"queued",
"document",
"insertions",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L197-L245 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.executeUpserts | public function executeUpserts(array $options = []) : void
{
if (! $this->queuedUpserts) {
return;
}
$options = $this->getWriteOptions($options);
foreach ($this->queuedUpserts as $oid => $document) {
try {
$this->executeUpsert($document, $options);
$this->handleCollections($document, $options);
unset($this->queuedUpserts[$oid]);
} catch (WriteException $e) {
unset($this->queuedUpserts[$oid]);
throw $e;
}
}
} | php | public function executeUpserts(array $options = []) : void
{
if (! $this->queuedUpserts) {
return;
}
$options = $this->getWriteOptions($options);
foreach ($this->queuedUpserts as $oid => $document) {
try {
$this->executeUpsert($document, $options);
$this->handleCollections($document, $options);
unset($this->queuedUpserts[$oid]);
} catch (WriteException $e) {
unset($this->queuedUpserts[$oid]);
throw $e;
}
}
} | [
"public",
"function",
"executeUpserts",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"queuedUpserts",
")",
"{",
"return",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"queuedUpserts",
"as",
"$",
"oid",
"=>",
"$",
"document",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"executeUpsert",
"(",
"$",
"document",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"handleCollections",
"(",
"$",
"document",
",",
"$",
"options",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"queuedUpserts",
"[",
"$",
"oid",
"]",
")",
";",
"}",
"catch",
"(",
"WriteException",
"$",
"e",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"queuedUpserts",
"[",
"$",
"oid",
"]",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"}"
] | Executes all queued document upserts.
Queued documents with an ID are upserted individually.
If no upserts are queued, invoking this method is a NOOP. | [
"Executes",
"all",
"queued",
"document",
"upserts",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L254-L271 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.executeUpsert | private function executeUpsert(object $document, array $options) : void
{
$options['upsert'] = true;
$criteria = $this->getQueryForDocument($document);
$data = $this->pb->prepareUpsertData($document);
// Set the initial version for each upsert
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$nextVersion = null;
if ($versionMapping['type'] === 'int') {
$nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersionDateTime = new DateTime();
$nextVersion = Type::convertPHPToDatabaseValue($nextVersionDateTime);
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
}
$data['$set'][$versionMapping['name']] = $nextVersion;
}
foreach (array_keys($criteria) as $field) {
unset($data['$set'][$field]);
unset($data['$inc'][$field]);
unset($data['$setOnInsert'][$field]);
}
// Do not send empty update operators
foreach (['$set', '$inc', '$setOnInsert'] as $operator) {
if (! empty($data[$operator])) {
continue;
}
unset($data[$operator]);
}
/* If there are no modifiers remaining, we're upserting a document with
* an identifier as its only field. Since a document with the identifier
* may already exist, the desired behavior is "insert if not exists" and
* NOOP otherwise. MongoDB 2.6+ does not allow empty modifiers, so $set
* the identifier to the same value in our criteria.
*
* This will fail for versions before MongoDB 2.6, which require an
* empty $set modifier. The best we can do (without attempting to check
* server versions in advance) is attempt the 2.6+ behavior and retry
* after the relevant exception.
*
* See: https://jira.mongodb.org/browse/SERVER-12266
*/
if (empty($data)) {
$retry = true;
$data = ['$set' => ['_id' => $criteria['_id']]];
}
try {
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, $data, $options);
return;
} catch (WriteException $e) {
if (empty($retry) || strpos($e->getMessage(), 'Mod on _id not allowed') === false) {
throw $e;
}
}
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, ['$set' => new stdClass()], $options);
} | php | private function executeUpsert(object $document, array $options) : void
{
$options['upsert'] = true;
$criteria = $this->getQueryForDocument($document);
$data = $this->pb->prepareUpsertData($document);
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$nextVersion = null;
if ($versionMapping['type'] === 'int') {
$nextVersion = max(1, (int) $this->class->reflFields[$this->class->versionField]->getValue($document));
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
} elseif ($versionMapping['type'] === 'date') {
$nextVersionDateTime = new DateTime();
$nextVersion = Type::convertPHPToDatabaseValue($nextVersionDateTime);
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersionDateTime);
}
$data['$set'][$versionMapping['name']] = $nextVersion;
}
foreach (array_keys($criteria) as $field) {
unset($data['$set'][$field]);
unset($data['$inc'][$field]);
unset($data['$setOnInsert'][$field]);
}
foreach (['$set', '$inc', '$setOnInsert'] as $operator) {
if (! empty($data[$operator])) {
continue;
}
unset($data[$operator]);
}
if (empty($data)) {
$retry = true;
$data = ['$set' => ['_id' => $criteria['_id']]];
}
try {
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, $data, $options);
return;
} catch (WriteException $e) {
if (empty($retry) || strpos($e->getMessage(), 'Mod on _id not allowed') === false) {
throw $e;
}
}
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, ['$set' => new stdClass()], $options);
} | [
"private",
"function",
"executeUpsert",
"(",
"object",
"$",
"document",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"options",
"[",
"'upsert'",
"]",
"=",
"true",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"getQueryForDocument",
"(",
"$",
"document",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"pb",
"->",
"prepareUpsertData",
"(",
"$",
"document",
")",
";",
"// Set the initial version for each upsert",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
")",
"{",
"$",
"versionMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
";",
"$",
"nextVersion",
"=",
"null",
";",
"if",
"(",
"$",
"versionMapping",
"[",
"'type'",
"]",
"===",
"'int'",
")",
"{",
"$",
"nextVersion",
"=",
"max",
"(",
"1",
",",
"(",
"int",
")",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
")",
";",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"nextVersion",
")",
";",
"}",
"elseif",
"(",
"$",
"versionMapping",
"[",
"'type'",
"]",
"===",
"'date'",
")",
"{",
"$",
"nextVersionDateTime",
"=",
"new",
"DateTime",
"(",
")",
";",
"$",
"nextVersion",
"=",
"Type",
"::",
"convertPHPToDatabaseValue",
"(",
"$",
"nextVersionDateTime",
")",
";",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"nextVersionDateTime",
")",
";",
"}",
"$",
"data",
"[",
"'$set'",
"]",
"[",
"$",
"versionMapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"nextVersion",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"criteria",
")",
"as",
"$",
"field",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"'$set'",
"]",
"[",
"$",
"field",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'$inc'",
"]",
"[",
"$",
"field",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'$setOnInsert'",
"]",
"[",
"$",
"field",
"]",
")",
";",
"}",
"// Do not send empty update operators",
"foreach",
"(",
"[",
"'$set'",
",",
"'$inc'",
",",
"'$setOnInsert'",
"]",
"as",
"$",
"operator",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"$",
"operator",
"]",
")",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"$",
"operator",
"]",
")",
";",
"}",
"/* If there are no modifiers remaining, we're upserting a document with\n * an identifier as its only field. Since a document with the identifier\n * may already exist, the desired behavior is \"insert if not exists\" and\n * NOOP otherwise. MongoDB 2.6+ does not allow empty modifiers, so $set\n * the identifier to the same value in our criteria.\n *\n * This will fail for versions before MongoDB 2.6, which require an\n * empty $set modifier. The best we can do (without attempting to check\n * server versions in advance) is attempt the 2.6+ behavior and retry\n * after the relevant exception.\n *\n * See: https://jira.mongodb.org/browse/SERVER-12266\n */",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"retry",
"=",
"true",
";",
"$",
"data",
"=",
"[",
"'$set'",
"=>",
"[",
"'_id'",
"=>",
"$",
"criteria",
"[",
"'_id'",
"]",
"]",
"]",
";",
"}",
"try",
"{",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"this",
"->",
"collection",
"->",
"updateOne",
"(",
"$",
"criteria",
",",
"$",
"data",
",",
"$",
"options",
")",
";",
"return",
";",
"}",
"catch",
"(",
"WriteException",
"$",
"e",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"retry",
")",
"||",
"strpos",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'Mod on _id not allowed'",
")",
"===",
"false",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"this",
"->",
"collection",
"->",
"updateOne",
"(",
"$",
"criteria",
",",
"[",
"'$set'",
"=>",
"new",
"stdClass",
"(",
")",
"]",
",",
"$",
"options",
")",
";",
"}"
] | Executes a single upsert in {@link executeUpserts} | [
"Executes",
"a",
"single",
"upsert",
"in",
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L276-L343 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.update | public function update(object $document, array $options = []) : void
{
$update = $this->pb->prepareUpdateData($document);
$query = $this->getQueryForDocument($document);
foreach (array_keys($query) as $field) {
unset($update['$set'][$field]);
}
if (empty($update['$set'])) {
unset($update['$set']);
}
// Include versioning logic to set the new version value in the database
// and to ensure the version has not changed since this document object instance
// was fetched from the database
$nextVersion = null;
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
if ($versionMapping['type'] === 'int') {
$nextVersion = $currentVersion + 1;
$update['$inc'][$versionMapping['name']] = 1;
$query[$versionMapping['name']] = $currentVersion;
} elseif ($versionMapping['type'] === 'date') {
$nextVersion = new DateTime();
$update['$set'][$versionMapping['name']] = Type::convertPHPToDatabaseValue($nextVersion);
$query[$versionMapping['name']] = Type::convertPHPToDatabaseValue($currentVersion);
}
}
if (! empty($update)) {
// Include locking logic so that if the document object in memory is currently
// locked then it will remove it, otherwise it ensures the document is not locked.
if ($this->class->isLockable) {
$isLocked = $this->class->reflFields[$this->class->lockField]->getValue($document);
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
if ($isLocked) {
$update['$unset'] = [$lockMapping['name'] => true];
} else {
$query[$lockMapping['name']] = ['$exists' => false];
}
}
$options = $this->getWriteOptions($options);
assert($this->collection instanceof Collection);
$result = $this->collection->updateOne($query, $update, $options);
if (($this->class->isVersioned || $this->class->isLockable) && $result->getModifiedCount() !== 1) {
throw LockException::lockFailed($document);
} elseif ($this->class->isVersioned) {
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
}
}
$this->handleCollections($document, $options);
} | php | public function update(object $document, array $options = []) : void
{
$update = $this->pb->prepareUpdateData($document);
$query = $this->getQueryForDocument($document);
foreach (array_keys($query) as $field) {
unset($update['$set'][$field]);
}
if (empty($update['$set'])) {
unset($update['$set']);
}
$nextVersion = null;
if ($this->class->isVersioned) {
$versionMapping = $this->class->fieldMappings[$this->class->versionField];
$currentVersion = $this->class->reflFields[$this->class->versionField]->getValue($document);
if ($versionMapping['type'] === 'int') {
$nextVersion = $currentVersion + 1;
$update['$inc'][$versionMapping['name']] = 1;
$query[$versionMapping['name']] = $currentVersion;
} elseif ($versionMapping['type'] === 'date') {
$nextVersion = new DateTime();
$update['$set'][$versionMapping['name']] = Type::convertPHPToDatabaseValue($nextVersion);
$query[$versionMapping['name']] = Type::convertPHPToDatabaseValue($currentVersion);
}
}
if (! empty($update)) {
if ($this->class->isLockable) {
$isLocked = $this->class->reflFields[$this->class->lockField]->getValue($document);
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
if ($isLocked) {
$update['$unset'] = [$lockMapping['name'] => true];
} else {
$query[$lockMapping['name']] = ['$exists' => false];
}
}
$options = $this->getWriteOptions($options);
assert($this->collection instanceof Collection);
$result = $this->collection->updateOne($query, $update, $options);
if (($this->class->isVersioned || $this->class->isLockable) && $result->getModifiedCount() !== 1) {
throw LockException::lockFailed($document);
} elseif ($this->class->isVersioned) {
$this->class->reflFields[$this->class->versionField]->setValue($document, $nextVersion);
}
}
$this->handleCollections($document, $options);
} | [
"public",
"function",
"update",
"(",
"object",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"update",
"=",
"$",
"this",
"->",
"pb",
"->",
"prepareUpdateData",
"(",
"$",
"document",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getQueryForDocument",
"(",
"$",
"document",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"query",
")",
"as",
"$",
"field",
")",
"{",
"unset",
"(",
"$",
"update",
"[",
"'$set'",
"]",
"[",
"$",
"field",
"]",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"update",
"[",
"'$set'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"update",
"[",
"'$set'",
"]",
")",
";",
"}",
"// Include versioning logic to set the new version value in the database",
"// and to ensure the version has not changed since this document object instance",
"// was fetched from the database",
"$",
"nextVersion",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
")",
"{",
"$",
"versionMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
";",
"$",
"currentVersion",
"=",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"versionMapping",
"[",
"'type'",
"]",
"===",
"'int'",
")",
"{",
"$",
"nextVersion",
"=",
"$",
"currentVersion",
"+",
"1",
";",
"$",
"update",
"[",
"'$inc'",
"]",
"[",
"$",
"versionMapping",
"[",
"'name'",
"]",
"]",
"=",
"1",
";",
"$",
"query",
"[",
"$",
"versionMapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"currentVersion",
";",
"}",
"elseif",
"(",
"$",
"versionMapping",
"[",
"'type'",
"]",
"===",
"'date'",
")",
"{",
"$",
"nextVersion",
"=",
"new",
"DateTime",
"(",
")",
";",
"$",
"update",
"[",
"'$set'",
"]",
"[",
"$",
"versionMapping",
"[",
"'name'",
"]",
"]",
"=",
"Type",
"::",
"convertPHPToDatabaseValue",
"(",
"$",
"nextVersion",
")",
";",
"$",
"query",
"[",
"$",
"versionMapping",
"[",
"'name'",
"]",
"]",
"=",
"Type",
"::",
"convertPHPToDatabaseValue",
"(",
"$",
"currentVersion",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"update",
")",
")",
"{",
"// Include locking logic so that if the document object in memory is currently",
"// locked then it will remove it, otherwise it ensures the document is not locked.",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"{",
"$",
"isLocked",
"=",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"$",
"lockMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
";",
"if",
"(",
"$",
"isLocked",
")",
"{",
"$",
"update",
"[",
"'$unset'",
"]",
"=",
"[",
"$",
"lockMapping",
"[",
"'name'",
"]",
"=>",
"true",
"]",
";",
"}",
"else",
"{",
"$",
"query",
"[",
"$",
"lockMapping",
"[",
"'name'",
"]",
"]",
"=",
"[",
"'$exists'",
"=>",
"false",
"]",
";",
"}",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"options",
")",
";",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"collection",
"->",
"updateOne",
"(",
"$",
"query",
",",
"$",
"update",
",",
"$",
"options",
")",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
"||",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"&&",
"$",
"result",
"->",
"getModifiedCount",
"(",
")",
"!==",
"1",
")",
"{",
"throw",
"LockException",
"::",
"lockFailed",
"(",
"$",
"document",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
")",
"{",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"versionField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"nextVersion",
")",
";",
"}",
"}",
"$",
"this",
"->",
"handleCollections",
"(",
"$",
"document",
",",
"$",
"options",
")",
";",
"}"
] | Updates the already persisted document if it has any new changesets.
@throws LockException | [
"Updates",
"the",
"already",
"persisted",
"document",
"if",
"it",
"has",
"any",
"new",
"changesets",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L350-L408 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.delete | public function delete(object $document, array $options = []) : void
{
if ($this->bucket instanceof Bucket) {
$documentIdentifier = $this->uow->getDocumentIdentifier($document);
$databaseIdentifier = $this->class->getDatabaseIdentifierValue($documentIdentifier);
$this->bucket->delete($databaseIdentifier);
return;
}
$query = $this->getQueryForDocument($document);
if ($this->class->isLockable) {
$query[$this->class->lockField] = ['$exists' => false];
}
$options = $this->getWriteOptions($options);
assert($this->collection instanceof Collection);
$result = $this->collection->deleteOne($query, $options);
if (($this->class->isVersioned || $this->class->isLockable) && ! $result->getDeletedCount()) {
throw LockException::lockFailed($document);
}
} | php | public function delete(object $document, array $options = []) : void
{
if ($this->bucket instanceof Bucket) {
$documentIdentifier = $this->uow->getDocumentIdentifier($document);
$databaseIdentifier = $this->class->getDatabaseIdentifierValue($documentIdentifier);
$this->bucket->delete($databaseIdentifier);
return;
}
$query = $this->getQueryForDocument($document);
if ($this->class->isLockable) {
$query[$this->class->lockField] = ['$exists' => false];
}
$options = $this->getWriteOptions($options);
assert($this->collection instanceof Collection);
$result = $this->collection->deleteOne($query, $options);
if (($this->class->isVersioned || $this->class->isLockable) && ! $result->getDeletedCount()) {
throw LockException::lockFailed($document);
}
} | [
"public",
"function",
"delete",
"(",
"object",
"$",
"document",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"bucket",
"instanceof",
"Bucket",
")",
"{",
"$",
"documentIdentifier",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"databaseIdentifier",
"=",
"$",
"this",
"->",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"documentIdentifier",
")",
";",
"$",
"this",
"->",
"bucket",
"->",
"delete",
"(",
"$",
"databaseIdentifier",
")",
";",
"return",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"getQueryForDocument",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"{",
"$",
"query",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
"=",
"[",
"'$exists'",
"=>",
"false",
"]",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"options",
")",
";",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"collection",
"->",
"deleteOne",
"(",
"$",
"query",
",",
"$",
"options",
")",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"class",
"->",
"isVersioned",
"||",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"&&",
"!",
"$",
"result",
"->",
"getDeletedCount",
"(",
")",
")",
"{",
"throw",
"LockException",
"::",
"lockFailed",
"(",
"$",
"document",
")",
";",
"}",
"}"
] | Removes document from mongo
@throws LockException | [
"Removes",
"document",
"from",
"mongo"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L415-L440 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.refresh | public function refresh(object $document) : void
{
assert($this->collection instanceof Collection);
$query = $this->getQueryForDocument($document);
$data = $this->collection->findOne($query);
if ($data === null) {
throw MongoDBException::cannotRefreshDocument();
}
$data = $this->hydratorFactory->hydrate($document, (array) $data);
$this->uow->setOriginalDocumentData($document, $data);
} | php | public function refresh(object $document) : void
{
assert($this->collection instanceof Collection);
$query = $this->getQueryForDocument($document);
$data = $this->collection->findOne($query);
if ($data === null) {
throw MongoDBException::cannotRefreshDocument();
}
$data = $this->hydratorFactory->hydrate($document, (array) $data);
$this->uow->setOriginalDocumentData($document, $data);
} | [
"public",
"function",
"refresh",
"(",
"object",
"$",
"document",
")",
":",
"void",
"{",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"getQueryForDocument",
"(",
"$",
"document",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"collection",
"->",
"findOne",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"throw",
"MongoDBException",
"::",
"cannotRefreshDocument",
"(",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"hydratorFactory",
"->",
"hydrate",
"(",
"$",
"document",
",",
"(",
"array",
")",
"$",
"data",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"setOriginalDocumentData",
"(",
"$",
"document",
",",
"$",
"data",
")",
";",
"}"
] | Refreshes a managed document. | [
"Refreshes",
"a",
"managed",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L445-L455 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.load | public function load($criteria, ?object $document = null, array $hints = [], int $lockMode = 0, ?array $sort = null) : ?object
{
// TODO: remove this
if ($criteria === null || is_scalar($criteria) || $criteria instanceof ObjectId) {
$criteria = ['_id' => $criteria];
}
$criteria = $this->prepareQueryOrNewObj($criteria);
$criteria = $this->addDiscriminatorToPreparedQuery($criteria);
$criteria = $this->addFilterToPreparedQuery($criteria);
$options = [];
if ($sort !== null) {
$options['sort'] = $this->prepareSort($sort);
}
assert($this->collection instanceof Collection);
$result = $this->collection->findOne($criteria, $options);
$result = $result !== null ? (array) $result : null;
if ($this->class->isLockable) {
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
if (isset($result[$lockMapping['name']]) && $result[$lockMapping['name']] === LockMode::PESSIMISTIC_WRITE) {
throw LockException::lockFailed($document);
}
}
if ($result === null) {
return null;
}
return $this->createDocument($result, $document, $hints);
} | php | public function load($criteria, ?object $document = null, array $hints = [], int $lockMode = 0, ?array $sort = null) : ?object
{
if ($criteria === null || is_scalar($criteria) || $criteria instanceof ObjectId) {
$criteria = ['_id' => $criteria];
}
$criteria = $this->prepareQueryOrNewObj($criteria);
$criteria = $this->addDiscriminatorToPreparedQuery($criteria);
$criteria = $this->addFilterToPreparedQuery($criteria);
$options = [];
if ($sort !== null) {
$options['sort'] = $this->prepareSort($sort);
}
assert($this->collection instanceof Collection);
$result = $this->collection->findOne($criteria, $options);
$result = $result !== null ? (array) $result : null;
if ($this->class->isLockable) {
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
if (isset($result[$lockMapping['name']]) && $result[$lockMapping['name']] === LockMode::PESSIMISTIC_WRITE) {
throw LockException::lockFailed($document);
}
}
if ($result === null) {
return null;
}
return $this->createDocument($result, $document, $hints);
} | [
"public",
"function",
"load",
"(",
"$",
"criteria",
",",
"?",
"object",
"$",
"document",
"=",
"null",
",",
"array",
"$",
"hints",
"=",
"[",
"]",
",",
"int",
"$",
"lockMode",
"=",
"0",
",",
"?",
"array",
"$",
"sort",
"=",
"null",
")",
":",
"?",
"object",
"{",
"// TODO: remove this",
"if",
"(",
"$",
"criteria",
"===",
"null",
"||",
"is_scalar",
"(",
"$",
"criteria",
")",
"||",
"$",
"criteria",
"instanceof",
"ObjectId",
")",
"{",
"$",
"criteria",
"=",
"[",
"'_id'",
"=>",
"$",
"criteria",
"]",
";",
"}",
"$",
"criteria",
"=",
"$",
"this",
"->",
"prepareQueryOrNewObj",
"(",
"$",
"criteria",
")",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"addDiscriminatorToPreparedQuery",
"(",
"$",
"criteria",
")",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"addFilterToPreparedQuery",
"(",
"$",
"criteria",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"sort",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'sort'",
"]",
"=",
"$",
"this",
"->",
"prepareSort",
"(",
"$",
"sort",
")",
";",
"}",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"collection",
"->",
"findOne",
"(",
"$",
"criteria",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"$",
"result",
"!==",
"null",
"?",
"(",
"array",
")",
"$",
"result",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"isLockable",
")",
"{",
"$",
"lockMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"$",
"lockMapping",
"[",
"'name'",
"]",
"]",
")",
"&&",
"$",
"result",
"[",
"$",
"lockMapping",
"[",
"'name'",
"]",
"]",
"===",
"LockMode",
"::",
"PESSIMISTIC_WRITE",
")",
"{",
"throw",
"LockException",
"::",
"lockFailed",
"(",
"$",
"document",
")",
";",
"}",
"}",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"createDocument",
"(",
"$",
"result",
",",
"$",
"document",
",",
"$",
"hints",
")",
";",
"}"
] | Finds a document by a set of criteria.
If a scalar or MongoDB\BSON\ObjectId is provided for $criteria, it will
be used to match an _id value.
@param mixed $criteria Query criteria
@throws LockException
@todo Check identity map? loadById method? Try to guess whether
$criteria is the id? | [
"Finds",
"a",
"document",
"by",
"a",
"set",
"of",
"criteria",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L470-L501 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.loadAll | public function loadAll(array $criteria = [], ?array $sort = null, ?int $limit = null, ?int $skip = null) : Iterator
{
$criteria = $this->prepareQueryOrNewObj($criteria);
$criteria = $this->addDiscriminatorToPreparedQuery($criteria);
$criteria = $this->addFilterToPreparedQuery($criteria);
$options = [];
if ($sort !== null) {
$options['sort'] = $this->prepareSort($sort);
}
if ($limit !== null) {
$options['limit'] = $limit;
}
if ($skip !== null) {
$options['skip'] = $skip;
}
assert($this->collection instanceof Collection);
$baseCursor = $this->collection->find($criteria, $options);
return $this->wrapCursor($baseCursor);
} | php | public function loadAll(array $criteria = [], ?array $sort = null, ?int $limit = null, ?int $skip = null) : Iterator
{
$criteria = $this->prepareQueryOrNewObj($criteria);
$criteria = $this->addDiscriminatorToPreparedQuery($criteria);
$criteria = $this->addFilterToPreparedQuery($criteria);
$options = [];
if ($sort !== null) {
$options['sort'] = $this->prepareSort($sort);
}
if ($limit !== null) {
$options['limit'] = $limit;
}
if ($skip !== null) {
$options['skip'] = $skip;
}
assert($this->collection instanceof Collection);
$baseCursor = $this->collection->find($criteria, $options);
return $this->wrapCursor($baseCursor);
} | [
"public",
"function",
"loadAll",
"(",
"array",
"$",
"criteria",
"=",
"[",
"]",
",",
"?",
"array",
"$",
"sort",
"=",
"null",
",",
"?",
"int",
"$",
"limit",
"=",
"null",
",",
"?",
"int",
"$",
"skip",
"=",
"null",
")",
":",
"Iterator",
"{",
"$",
"criteria",
"=",
"$",
"this",
"->",
"prepareQueryOrNewObj",
"(",
"$",
"criteria",
")",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"addDiscriminatorToPreparedQuery",
"(",
"$",
"criteria",
")",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"addFilterToPreparedQuery",
"(",
"$",
"criteria",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"sort",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'sort'",
"]",
"=",
"$",
"this",
"->",
"prepareSort",
"(",
"$",
"sort",
")",
";",
"}",
"if",
"(",
"$",
"limit",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'limit'",
"]",
"=",
"$",
"limit",
";",
"}",
"if",
"(",
"$",
"skip",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'skip'",
"]",
"=",
"$",
"skip",
";",
"}",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"baseCursor",
"=",
"$",
"this",
"->",
"collection",
"->",
"find",
"(",
"$",
"criteria",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"wrapCursor",
"(",
"$",
"baseCursor",
")",
";",
"}"
] | Finds documents by a set of criteria. | [
"Finds",
"documents",
"by",
"a",
"set",
"of",
"criteria",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L506-L528 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.wrapCursor | private function wrapCursor(Cursor $baseCursor) : Iterator
{
return new CachingIterator(new HydratingIterator($baseCursor, $this->dm->getUnitOfWork(), $this->class));
} | php | private function wrapCursor(Cursor $baseCursor) : Iterator
{
return new CachingIterator(new HydratingIterator($baseCursor, $this->dm->getUnitOfWork(), $this->class));
} | [
"private",
"function",
"wrapCursor",
"(",
"Cursor",
"$",
"baseCursor",
")",
":",
"Iterator",
"{",
"return",
"new",
"CachingIterator",
"(",
"new",
"HydratingIterator",
"(",
"$",
"baseCursor",
",",
"$",
"this",
"->",
"dm",
"->",
"getUnitOfWork",
"(",
")",
",",
"$",
"this",
"->",
"class",
")",
")",
";",
"}"
] | Wraps the supplied base cursor in the corresponding ODM class. | [
"Wraps",
"the",
"supplied",
"base",
"cursor",
"in",
"the",
"corresponding",
"ODM",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L571-L574 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.exists | public function exists(object $document) : bool
{
$id = $this->class->getIdentifierObject($document);
assert($this->collection instanceof Collection);
return (bool) $this->collection->findOne(['_id' => $id], ['_id']);
} | php | public function exists(object $document) : bool
{
$id = $this->class->getIdentifierObject($document);
assert($this->collection instanceof Collection);
return (bool) $this->collection->findOne(['_id' => $id], ['_id']);
} | [
"public",
"function",
"exists",
"(",
"object",
"$",
"document",
")",
":",
"bool",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"class",
"->",
"getIdentifierObject",
"(",
"$",
"document",
")",
";",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"collection",
"->",
"findOne",
"(",
"[",
"'_id'",
"=>",
"$",
"id",
"]",
",",
"[",
"'_id'",
"]",
")",
";",
"}"
] | Checks whether the given managed document exists in the database. | [
"Checks",
"whether",
"the",
"given",
"managed",
"document",
"exists",
"in",
"the",
"database",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L579-L584 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.lock | public function lock(object $document, int $lockMode) : void
{
$id = $this->uow->getDocumentIdentifier($document);
$criteria = ['_id' => $this->class->getDatabaseIdentifierValue($id)];
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, ['$set' => [$lockMapping['name'] => $lockMode]]);
$this->class->reflFields[$this->class->lockField]->setValue($document, $lockMode);
} | php | public function lock(object $document, int $lockMode) : void
{
$id = $this->uow->getDocumentIdentifier($document);
$criteria = ['_id' => $this->class->getDatabaseIdentifierValue($id)];
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, ['$set' => [$lockMapping['name'] => $lockMode]]);
$this->class->reflFields[$this->class->lockField]->setValue($document, $lockMode);
} | [
"public",
"function",
"lock",
"(",
"object",
"$",
"document",
",",
"int",
"$",
"lockMode",
")",
":",
"void",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"criteria",
"=",
"[",
"'_id'",
"=>",
"$",
"this",
"->",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
"]",
";",
"$",
"lockMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
";",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"this",
"->",
"collection",
"->",
"updateOne",
"(",
"$",
"criteria",
",",
"[",
"'$set'",
"=>",
"[",
"$",
"lockMapping",
"[",
"'name'",
"]",
"=>",
"$",
"lockMode",
"]",
"]",
")",
";",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"lockMode",
")",
";",
"}"
] | Locks document by storing the lock mode on the mapped lock field. | [
"Locks",
"document",
"by",
"storing",
"the",
"lock",
"mode",
"on",
"the",
"mapped",
"lock",
"field",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L589-L597 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.unlock | public function unlock(object $document) : void
{
$id = $this->uow->getDocumentIdentifier($document);
$criteria = ['_id' => $this->class->getDatabaseIdentifierValue($id)];
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, ['$unset' => [$lockMapping['name'] => true]]);
$this->class->reflFields[$this->class->lockField]->setValue($document, null);
} | php | public function unlock(object $document) : void
{
$id = $this->uow->getDocumentIdentifier($document);
$criteria = ['_id' => $this->class->getDatabaseIdentifierValue($id)];
$lockMapping = $this->class->fieldMappings[$this->class->lockField];
assert($this->collection instanceof Collection);
$this->collection->updateOne($criteria, ['$unset' => [$lockMapping['name'] => true]]);
$this->class->reflFields[$this->class->lockField]->setValue($document, null);
} | [
"public",
"function",
"unlock",
"(",
"object",
"$",
"document",
")",
":",
"void",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"criteria",
"=",
"[",
"'_id'",
"=>",
"$",
"this",
"->",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
"]",
";",
"$",
"lockMapping",
"=",
"$",
"this",
"->",
"class",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
";",
"assert",
"(",
"$",
"this",
"->",
"collection",
"instanceof",
"Collection",
")",
";",
"$",
"this",
"->",
"collection",
"->",
"updateOne",
"(",
"$",
"criteria",
",",
"[",
"'$unset'",
"=>",
"[",
"$",
"lockMapping",
"[",
"'name'",
"]",
"=>",
"true",
"]",
"]",
")",
";",
"$",
"this",
"->",
"class",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"class",
"->",
"lockField",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"null",
")",
";",
"}"
] | Releases any lock that exists on this document. | [
"Releases",
"any",
"lock",
"that",
"exists",
"on",
"this",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L602-L610 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.createDocument | private function createDocument(array $result, ?object $document = null, array $hints = []) : ?object
{
if ($document !== null) {
$hints[Query::HINT_REFRESH] = true;
$id = $this->class->getPHPIdentifierValue($result['_id']);
$this->uow->registerManaged($document, $id, $result);
}
return $this->uow->getOrCreateDocument($this->class->name, $result, $hints, $document);
} | php | private function createDocument(array $result, ?object $document = null, array $hints = []) : ?object
{
if ($document !== null) {
$hints[Query::HINT_REFRESH] = true;
$id = $this->class->getPHPIdentifierValue($result['_id']);
$this->uow->registerManaged($document, $id, $result);
}
return $this->uow->getOrCreateDocument($this->class->name, $result, $hints, $document);
} | [
"private",
"function",
"createDocument",
"(",
"array",
"$",
"result",
",",
"?",
"object",
"$",
"document",
"=",
"null",
",",
"array",
"$",
"hints",
"=",
"[",
"]",
")",
":",
"?",
"object",
"{",
"if",
"(",
"$",
"document",
"!==",
"null",
")",
"{",
"$",
"hints",
"[",
"Query",
"::",
"HINT_REFRESH",
"]",
"=",
"true",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"class",
"->",
"getPHPIdentifierValue",
"(",
"$",
"result",
"[",
"'_id'",
"]",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"registerManaged",
"(",
"$",
"document",
",",
"$",
"id",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"this",
"->",
"uow",
"->",
"getOrCreateDocument",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
",",
"$",
"result",
",",
"$",
"hints",
",",
"$",
"document",
")",
";",
"}"
] | Creates or fills a single document object from an query result.
@param array $result The query result.
@param object $document The document object to fill, if any.
@param array $hints Hints for document creation.
@return object|null The filled and managed document object or NULL, if the query result is empty. | [
"Creates",
"or",
"fills",
"a",
"single",
"document",
"object",
"from",
"an",
"query",
"result",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L621-L630 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.loadCollection | public function loadCollection(PersistentCollectionInterface $collection) : void
{
$mapping = $collection->getMapping();
switch ($mapping['association']) {
case ClassMetadata::EMBED_MANY:
$this->loadEmbedManyCollection($collection);
break;
case ClassMetadata::REFERENCE_MANY:
if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) {
$this->loadReferenceManyWithRepositoryMethod($collection);
} else {
if ($mapping['isOwningSide']) {
$this->loadReferenceManyCollectionOwningSide($collection);
} else {
$this->loadReferenceManyCollectionInverseSide($collection);
}
}
break;
}
} | php | public function loadCollection(PersistentCollectionInterface $collection) : void
{
$mapping = $collection->getMapping();
switch ($mapping['association']) {
case ClassMetadata::EMBED_MANY:
$this->loadEmbedManyCollection($collection);
break;
case ClassMetadata::REFERENCE_MANY:
if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) {
$this->loadReferenceManyWithRepositoryMethod($collection);
} else {
if ($mapping['isOwningSide']) {
$this->loadReferenceManyCollectionOwningSide($collection);
} else {
$this->loadReferenceManyCollectionInverseSide($collection);
}
}
break;
}
} | [
"public",
"function",
"loadCollection",
"(",
"PersistentCollectionInterface",
"$",
"collection",
")",
":",
"void",
"{",
"$",
"mapping",
"=",
"$",
"collection",
"->",
"getMapping",
"(",
")",
";",
"switch",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"{",
"case",
"ClassMetadata",
"::",
"EMBED_MANY",
":",
"$",
"this",
"->",
"loadEmbedManyCollection",
"(",
"$",
"collection",
")",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"REFERENCE_MANY",
":",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'repositoryMethod'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'repositoryMethod'",
"]",
")",
"{",
"$",
"this",
"->",
"loadReferenceManyWithRepositoryMethod",
"(",
"$",
"collection",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
")",
"{",
"$",
"this",
"->",
"loadReferenceManyCollectionOwningSide",
"(",
"$",
"collection",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"loadReferenceManyCollectionInverseSide",
"(",
"$",
"collection",
")",
";",
"}",
"}",
"break",
";",
"}",
"}"
] | Loads a PersistentCollection data. Used in the initialize() method. | [
"Loads",
"a",
"PersistentCollection",
"data",
".",
"Used",
"in",
"the",
"initialize",
"()",
"method",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L635-L655 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.prepareProjection | public function prepareProjection(array $fields) : array
{
$preparedFields = [];
foreach ($fields as $key => $value) {
$preparedFields[$this->prepareFieldName($key)] = $value;
}
return $preparedFields;
} | php | public function prepareProjection(array $fields) : array
{
$preparedFields = [];
foreach ($fields as $key => $value) {
$preparedFields[$this->prepareFieldName($key)] = $value;
}
return $preparedFields;
} | [
"public",
"function",
"prepareProjection",
"(",
"array",
"$",
"fields",
")",
":",
"array",
"{",
"$",
"preparedFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"preparedFields",
"[",
"$",
"this",
"->",
"prepareFieldName",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"preparedFields",
";",
"}"
] | Prepare a projection array by converting keys, which are PHP property
names, to MongoDB field names. | [
"Prepare",
"a",
"projection",
"array",
"by",
"converting",
"keys",
"which",
"are",
"PHP",
"property",
"names",
"to",
"MongoDB",
"field",
"names",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L859-L868 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.prepareSort | public function prepareSort(array $fields) : array
{
$sortFields = [];
foreach ($fields as $key => $value) {
if (is_array($value)) {
$sortFields[$this->prepareFieldName($key)] = $value;
} else {
$sortFields[$this->prepareFieldName($key)] = $this->getSortDirection($value);
}
}
return $sortFields;
} | php | public function prepareSort(array $fields) : array
{
$sortFields = [];
foreach ($fields as $key => $value) {
if (is_array($value)) {
$sortFields[$this->prepareFieldName($key)] = $value;
} else {
$sortFields[$this->prepareFieldName($key)] = $this->getSortDirection($value);
}
}
return $sortFields;
} | [
"public",
"function",
"prepareSort",
"(",
"array",
"$",
"fields",
")",
":",
"array",
"{",
"$",
"sortFields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"sortFields",
"[",
"$",
"this",
"->",
"prepareFieldName",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"sortFields",
"[",
"$",
"this",
"->",
"prepareFieldName",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"this",
"->",
"getSortDirection",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"sortFields",
";",
"}"
] | Prepare a sort specification array by converting keys to MongoDB field
names and changing direction strings to int. | [
"Prepare",
"a",
"sort",
"specification",
"array",
"by",
"converting",
"keys",
"to",
"MongoDB",
"field",
"names",
"and",
"changing",
"direction",
"strings",
"to",
"int",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L892-L905 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.prepareFieldName | public function prepareFieldName(string $fieldName) : string
{
$fieldNames = $this->prepareQueryElement($fieldName, null, null, false);
return $fieldNames[0][0];
} | php | public function prepareFieldName(string $fieldName) : string
{
$fieldNames = $this->prepareQueryElement($fieldName, null, null, false);
return $fieldNames[0][0];
} | [
"public",
"function",
"prepareFieldName",
"(",
"string",
"$",
"fieldName",
")",
":",
"string",
"{",
"$",
"fieldNames",
"=",
"$",
"this",
"->",
"prepareQueryElement",
"(",
"$",
"fieldName",
",",
"null",
",",
"null",
",",
"false",
")",
";",
"return",
"$",
"fieldNames",
"[",
"0",
"]",
"[",
"0",
"]",
";",
"}"
] | Prepare a mongodb field name and convert the PHP property names to
MongoDB field names. | [
"Prepare",
"a",
"mongodb",
"field",
"name",
"and",
"convert",
"the",
"PHP",
"property",
"names",
"to",
"MongoDB",
"field",
"names",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L911-L916 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.addDiscriminatorToPreparedQuery | public function addDiscriminatorToPreparedQuery(array $preparedQuery) : array
{
if (isset($preparedQuery[$this->class->discriminatorField]) || $this->class->discriminatorField === null) {
return $preparedQuery;
}
$discriminatorValues = $this->getClassDiscriminatorValues($this->class);
if ($discriminatorValues === []) {
return $preparedQuery;
}
if (count($discriminatorValues) === 1) {
$preparedQuery[$this->class->discriminatorField] = $discriminatorValues[0];
} else {
$preparedQuery[$this->class->discriminatorField] = ['$in' => $discriminatorValues];
}
return $preparedQuery;
} | php | public function addDiscriminatorToPreparedQuery(array $preparedQuery) : array
{
if (isset($preparedQuery[$this->class->discriminatorField]) || $this->class->discriminatorField === null) {
return $preparedQuery;
}
$discriminatorValues = $this->getClassDiscriminatorValues($this->class);
if ($discriminatorValues === []) {
return $preparedQuery;
}
if (count($discriminatorValues) === 1) {
$preparedQuery[$this->class->discriminatorField] = $discriminatorValues[0];
} else {
$preparedQuery[$this->class->discriminatorField] = ['$in' => $discriminatorValues];
}
return $preparedQuery;
} | [
"public",
"function",
"addDiscriminatorToPreparedQuery",
"(",
"array",
"$",
"preparedQuery",
")",
":",
"array",
"{",
"if",
"(",
"isset",
"(",
"$",
"preparedQuery",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
")",
"||",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"===",
"null",
")",
"{",
"return",
"$",
"preparedQuery",
";",
"}",
"$",
"discriminatorValues",
"=",
"$",
"this",
"->",
"getClassDiscriminatorValues",
"(",
"$",
"this",
"->",
"class",
")",
";",
"if",
"(",
"$",
"discriminatorValues",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"preparedQuery",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"discriminatorValues",
")",
"===",
"1",
")",
"{",
"$",
"preparedQuery",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
"=",
"$",
"discriminatorValues",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"preparedQuery",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
"=",
"[",
"'$in'",
"=>",
"$",
"discriminatorValues",
"]",
";",
"}",
"return",
"$",
"preparedQuery",
";",
"}"
] | Adds discriminator criteria to an already-prepared query.
If the class we're querying has a discriminator field set, we add all
possible discriminator values to the query. The list of possible
discriminator values is based on the discriminatorValue of the class
itself as well as those of all its subclasses.
This method should be used once for query criteria and not be used for
nested expressions. It should be called before
{@link DocumentPerister::addFilterToPreparedQuery()}. | [
"Adds",
"discriminator",
"criteria",
"to",
"an",
"already",
"-",
"prepared",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L930-L949 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.prepareQueryOrNewObj | public function prepareQueryOrNewObj(array $query, bool $isNewObj = false) : array
{
$preparedQuery = [];
foreach ($query as $key => $value) {
// Recursively prepare logical query clauses
if (in_array($key, ['$and', '$or', '$nor'], true) && is_array($value)) {
foreach ($value as $k2 => $v2) {
$preparedQuery[$key][$k2] = $this->prepareQueryOrNewObj($v2, $isNewObj);
}
continue;
}
if (isset($key[0]) && $key[0] === '$' && is_array($value)) {
$preparedQuery[$key] = $this->prepareQueryOrNewObj($value, $isNewObj);
continue;
}
$preparedQueryElements = $this->prepareQueryElement((string) $key, $value, null, true, $isNewObj);
foreach ($preparedQueryElements as [$preparedKey, $preparedValue]) {
$preparedQuery[$preparedKey] = is_array($preparedValue)
? array_map('\Doctrine\ODM\MongoDB\Types\Type::convertPHPToDatabaseValue', $preparedValue)
: Type::convertPHPToDatabaseValue($preparedValue);
}
}
return $preparedQuery;
} | php | public function prepareQueryOrNewObj(array $query, bool $isNewObj = false) : array
{
$preparedQuery = [];
foreach ($query as $key => $value) {
if (in_array($key, ['$and', '$or', '$nor'], true) && is_array($value)) {
foreach ($value as $k2 => $v2) {
$preparedQuery[$key][$k2] = $this->prepareQueryOrNewObj($v2, $isNewObj);
}
continue;
}
if (isset($key[0]) && $key[0] === '$' && is_array($value)) {
$preparedQuery[$key] = $this->prepareQueryOrNewObj($value, $isNewObj);
continue;
}
$preparedQueryElements = $this->prepareQueryElement((string) $key, $value, null, true, $isNewObj);
foreach ($preparedQueryElements as [$preparedKey, $preparedValue]) {
$preparedQuery[$preparedKey] = is_array($preparedValue)
? array_map('\Doctrine\ODM\MongoDB\Types\Type::convertPHPToDatabaseValue', $preparedValue)
: Type::convertPHPToDatabaseValue($preparedValue);
}
}
return $preparedQuery;
} | [
"public",
"function",
"prepareQueryOrNewObj",
"(",
"array",
"$",
"query",
",",
"bool",
"$",
"isNewObj",
"=",
"false",
")",
":",
"array",
"{",
"$",
"preparedQuery",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Recursively prepare logical query clauses",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"[",
"'$and'",
",",
"'$or'",
",",
"'$nor'",
"]",
",",
"true",
")",
"&&",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k2",
"=>",
"$",
"v2",
")",
"{",
"$",
"preparedQuery",
"[",
"$",
"key",
"]",
"[",
"$",
"k2",
"]",
"=",
"$",
"this",
"->",
"prepareQueryOrNewObj",
"(",
"$",
"v2",
",",
"$",
"isNewObj",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"key",
"[",
"0",
"]",
")",
"&&",
"$",
"key",
"[",
"0",
"]",
"===",
"'$'",
"&&",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"preparedQuery",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"prepareQueryOrNewObj",
"(",
"$",
"value",
",",
"$",
"isNewObj",
")",
";",
"continue",
";",
"}",
"$",
"preparedQueryElements",
"=",
"$",
"this",
"->",
"prepareQueryElement",
"(",
"(",
"string",
")",
"$",
"key",
",",
"$",
"value",
",",
"null",
",",
"true",
",",
"$",
"isNewObj",
")",
";",
"foreach",
"(",
"$",
"preparedQueryElements",
"as",
"[",
"$",
"preparedKey",
",",
"$",
"preparedValue",
"]",
")",
"{",
"$",
"preparedQuery",
"[",
"$",
"preparedKey",
"]",
"=",
"is_array",
"(",
"$",
"preparedValue",
")",
"?",
"array_map",
"(",
"'\\Doctrine\\ODM\\MongoDB\\Types\\Type::convertPHPToDatabaseValue'",
",",
"$",
"preparedValue",
")",
":",
"Type",
"::",
"convertPHPToDatabaseValue",
"(",
"$",
"preparedValue",
")",
";",
"}",
"}",
"return",
"$",
"preparedQuery",
";",
"}"
] | Prepares the query criteria or new document object.
PHP field names and types will be converted to those used by MongoDB. | [
"Prepares",
"the",
"query",
"criteria",
"or",
"new",
"document",
"object",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L979-L1006 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.prepareQueryElement | private function prepareQueryElement(string $fieldName, $value = null, ?ClassMetadata $class = null, bool $prepareValue = true, bool $inNewObj = false) : array
{
$class = $class ?? $this->class;
// @todo Consider inlining calls to ClassMetadata methods
// Process all non-identifier fields by translating field names
if ($class->hasField($fieldName) && ! $class->isIdentifier($fieldName)) {
$mapping = $class->fieldMappings[$fieldName];
$fieldName = $mapping['name'];
if (! $prepareValue) {
return [[$fieldName, $value]];
}
// Prepare mapped, embedded objects
if (! empty($mapping['embedded']) && is_object($value) &&
! $this->dm->getMetadataFactory()->isTransient(get_class($value))) {
return [[$fieldName, $this->pb->prepareEmbeddedDocumentValue($mapping, $value)]];
}
if (! empty($mapping['reference']) && is_object($value) && ! ($value instanceof ObjectId)) {
try {
return $this->prepareReference($fieldName, $value, $mapping, $inNewObj);
} catch (MappingException $e) {
// do nothing in case passed object is not mapped document
}
}
// No further preparation unless we're dealing with a simple reference
if (empty($mapping['reference']) || $mapping['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID || empty((array) $value)) {
return [[$fieldName, $value]];
}
// Additional preparation for one or more simple reference values
$targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
if (! is_array($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
// Objects without operators or with DBRef fields can be converted immediately
if (! $this->hasQueryOperators($value) || $this->hasDBRefFields($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
return [[$fieldName, $this->prepareQueryExpression($value, $targetClass)]];
}
// Process identifier fields
if (($class->hasField($fieldName) && $class->isIdentifier($fieldName)) || $fieldName === '_id') {
$fieldName = '_id';
if (! $prepareValue) {
return [[$fieldName, $value]];
}
if (! is_array($value)) {
return [[$fieldName, $class->getDatabaseIdentifierValue($value)]];
}
// Objects without operators or with DBRef fields can be converted immediately
if (! $this->hasQueryOperators($value) || $this->hasDBRefFields($value)) {
return [[$fieldName, $class->getDatabaseIdentifierValue($value)]];
}
return [[$fieldName, $this->prepareQueryExpression($value, $class)]];
}
// No processing for unmapped, non-identifier, non-dotted field names
if (strpos($fieldName, '.') === false) {
return [[$fieldName, $value]];
}
/* Process "fieldName.objectProperty" queries (on arrays or objects).
*
* We can limit parsing here, since at most three segments are
* significant: "fieldName.objectProperty" with an optional index or key
* for collections stored as either BSON arrays or objects.
*/
$e = explode('.', $fieldName, 4);
// No further processing for unmapped fields
if (! isset($class->fieldMappings[$e[0]])) {
return [[$fieldName, $value]];
}
$mapping = $class->fieldMappings[$e[0]];
$e[0] = $mapping['name'];
// Hash and raw fields will not be prepared beyond the field name
if ($mapping['type'] === Type::HASH || $mapping['type'] === Type::RAW) {
$fieldName = implode('.', $e);
return [[$fieldName, $value]];
}
if ($mapping['type'] === 'many' && CollectionHelper::isHash($mapping['strategy'])
&& isset($e[2])) {
$objectProperty = $e[2];
$objectPropertyPrefix = $e[1] . '.';
$nextObjectProperty = implode('.', array_slice($e, 3));
} elseif ($e[1] !== '$') {
$fieldName = $e[0] . '.' . $e[1];
$objectProperty = $e[1];
$objectPropertyPrefix = '';
$nextObjectProperty = implode('.', array_slice($e, 2));
} elseif (isset($e[2])) {
$fieldName = $e[0] . '.' . $e[1] . '.' . $e[2];
$objectProperty = $e[2];
$objectPropertyPrefix = $e[1] . '.';
$nextObjectProperty = implode('.', array_slice($e, 3));
} else {
$fieldName = $e[0] . '.' . $e[1];
return [[$fieldName, $value]];
}
// No further processing for fields without a targetDocument mapping
if (! isset($mapping['targetDocument'])) {
if ($nextObjectProperty) {
$fieldName .= '.' . $nextObjectProperty;
}
return [[$fieldName, $value]];
}
$targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
// No further processing for unmapped targetDocument fields
if (! $targetClass->hasField($objectProperty)) {
if ($nextObjectProperty) {
$fieldName .= '.' . $nextObjectProperty;
}
return [[$fieldName, $value]];
}
$targetMapping = $targetClass->getFieldMapping($objectProperty);
$objectPropertyIsId = $targetClass->isIdentifier($objectProperty);
// Prepare DBRef identifiers or the mapped field's property path
$fieldName = $objectPropertyIsId && ! empty($mapping['reference']) && $mapping['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID
? ClassMetadata::getReferenceFieldName($mapping['storeAs'], $e[0])
: $e[0] . '.' . $objectPropertyPrefix . $targetMapping['name'];
// Process targetDocument identifier fields
if ($objectPropertyIsId) {
if (! $prepareValue) {
return [[$fieldName, $value]];
}
if (! is_array($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
// Objects without operators or with DBRef fields can be converted immediately
if (! $this->hasQueryOperators($value) || $this->hasDBRefFields($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
return [[$fieldName, $this->prepareQueryExpression($value, $targetClass)]];
}
/* The property path may include a third field segment, excluding the
* collection item pointer. If present, this next object property must
* be processed recursively.
*/
if ($nextObjectProperty) {
// Respect the targetDocument's class metadata when recursing
$nextTargetClass = isset($targetMapping['targetDocument'])
? $this->dm->getClassMetadata($targetMapping['targetDocument'])
: null;
if (empty($targetMapping['reference'])) {
$fieldNames = $this->prepareQueryElement($nextObjectProperty, $value, $nextTargetClass, $prepareValue);
} else {
// No recursive processing for references as most probably somebody is querying DBRef or alike
if ($nextObjectProperty[0] !== '$' && in_array($targetMapping['storeAs'], [ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB, ClassMetadata::REFERENCE_STORE_AS_DB_REF])) {
$nextObjectProperty = '$' . $nextObjectProperty;
}
$fieldNames = [[$nextObjectProperty, $value]];
}
return array_map(static function ($preparedTuple) use ($fieldName) {
[$key, $value] = $preparedTuple;
return [$fieldName . '.' . $key, $value];
}, $fieldNames);
}
return [[$fieldName, $value]];
} | php | private function prepareQueryElement(string $fieldName, $value = null, ?ClassMetadata $class = null, bool $prepareValue = true, bool $inNewObj = false) : array
{
$class = $class ?? $this->class;
if ($class->hasField($fieldName) && ! $class->isIdentifier($fieldName)) {
$mapping = $class->fieldMappings[$fieldName];
$fieldName = $mapping['name'];
if (! $prepareValue) {
return [[$fieldName, $value]];
}
if (! empty($mapping['embedded']) && is_object($value) &&
! $this->dm->getMetadataFactory()->isTransient(get_class($value))) {
return [[$fieldName, $this->pb->prepareEmbeddedDocumentValue($mapping, $value)]];
}
if (! empty($mapping['reference']) && is_object($value) && ! ($value instanceof ObjectId)) {
try {
return $this->prepareReference($fieldName, $value, $mapping, $inNewObj);
} catch (MappingException $e) {
}
}
if (empty($mapping['reference']) || $mapping['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID || empty((array) $value)) {
return [[$fieldName, $value]];
}
$targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
if (! is_array($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
if (! $this->hasQueryOperators($value) || $this->hasDBRefFields($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
return [[$fieldName, $this->prepareQueryExpression($value, $targetClass)]];
}
if (($class->hasField($fieldName) && $class->isIdentifier($fieldName)) || $fieldName === '_id') {
$fieldName = '_id';
if (! $prepareValue) {
return [[$fieldName, $value]];
}
if (! is_array($value)) {
return [[$fieldName, $class->getDatabaseIdentifierValue($value)]];
}
if (! $this->hasQueryOperators($value) || $this->hasDBRefFields($value)) {
return [[$fieldName, $class->getDatabaseIdentifierValue($value)]];
}
return [[$fieldName, $this->prepareQueryExpression($value, $class)]];
}
if (strpos($fieldName, '.') === false) {
return [[$fieldName, $value]];
}
$e = explode('.', $fieldName, 4);
if (! isset($class->fieldMappings[$e[0]])) {
return [[$fieldName, $value]];
}
$mapping = $class->fieldMappings[$e[0]];
$e[0] = $mapping['name'];
if ($mapping['type'] === Type::HASH || $mapping['type'] === Type::RAW) {
$fieldName = implode('.', $e);
return [[$fieldName, $value]];
}
if ($mapping['type'] === 'many' && CollectionHelper::isHash($mapping['strategy'])
&& isset($e[2])) {
$objectProperty = $e[2];
$objectPropertyPrefix = $e[1] . '.';
$nextObjectProperty = implode('.', array_slice($e, 3));
} elseif ($e[1] !== '$') {
$fieldName = $e[0] . '.' . $e[1];
$objectProperty = $e[1];
$objectPropertyPrefix = '';
$nextObjectProperty = implode('.', array_slice($e, 2));
} elseif (isset($e[2])) {
$fieldName = $e[0] . '.' . $e[1] . '.' . $e[2];
$objectProperty = $e[2];
$objectPropertyPrefix = $e[1] . '.';
$nextObjectProperty = implode('.', array_slice($e, 3));
} else {
$fieldName = $e[0] . '.' . $e[1];
return [[$fieldName, $value]];
}
if (! isset($mapping['targetDocument'])) {
if ($nextObjectProperty) {
$fieldName .= '.' . $nextObjectProperty;
}
return [[$fieldName, $value]];
}
$targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
if (! $targetClass->hasField($objectProperty)) {
if ($nextObjectProperty) {
$fieldName .= '.' . $nextObjectProperty;
}
return [[$fieldName, $value]];
}
$targetMapping = $targetClass->getFieldMapping($objectProperty);
$objectPropertyIsId = $targetClass->isIdentifier($objectProperty);
$fieldName = $objectPropertyIsId && ! empty($mapping['reference']) && $mapping['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID
? ClassMetadata::getReferenceFieldName($mapping['storeAs'], $e[0])
: $e[0] . '.' . $objectPropertyPrefix . $targetMapping['name'];
if ($objectPropertyIsId) {
if (! $prepareValue) {
return [[$fieldName, $value]];
}
if (! is_array($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
if (! $this->hasQueryOperators($value) || $this->hasDBRefFields($value)) {
return [[$fieldName, $targetClass->getDatabaseIdentifierValue($value)]];
}
return [[$fieldName, $this->prepareQueryExpression($value, $targetClass)]];
}
if ($nextObjectProperty) {
$nextTargetClass = isset($targetMapping['targetDocument'])
? $this->dm->getClassMetadata($targetMapping['targetDocument'])
: null;
if (empty($targetMapping['reference'])) {
$fieldNames = $this->prepareQueryElement($nextObjectProperty, $value, $nextTargetClass, $prepareValue);
} else {
if ($nextObjectProperty[0] !== '$' && in_array($targetMapping['storeAs'], [ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB, ClassMetadata::REFERENCE_STORE_AS_DB_REF])) {
$nextObjectProperty = '$' . $nextObjectProperty;
}
$fieldNames = [[$nextObjectProperty, $value]];
}
return array_map(static function ($preparedTuple) use ($fieldName) {
[$key, $value] = $preparedTuple;
return [$fieldName . '.' . $key, $value];
}, $fieldNames);
}
return [[$fieldName, $value]];
} | [
"private",
"function",
"prepareQueryElement",
"(",
"string",
"$",
"fieldName",
",",
"$",
"value",
"=",
"null",
",",
"?",
"ClassMetadata",
"$",
"class",
"=",
"null",
",",
"bool",
"$",
"prepareValue",
"=",
"true",
",",
"bool",
"$",
"inNewObj",
"=",
"false",
")",
":",
"array",
"{",
"$",
"class",
"=",
"$",
"class",
"??",
"$",
"this",
"->",
"class",
";",
"// @todo Consider inlining calls to ClassMetadata methods",
"// Process all non-identifier fields by translating field names",
"if",
"(",
"$",
"class",
"->",
"hasField",
"(",
"$",
"fieldName",
")",
"&&",
"!",
"$",
"class",
"->",
"isIdentifier",
"(",
"$",
"fieldName",
")",
")",
"{",
"$",
"mapping",
"=",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
";",
"$",
"fieldName",
"=",
"$",
"mapping",
"[",
"'name'",
"]",
";",
"if",
"(",
"!",
"$",
"prepareValue",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"// Prepare mapped, embedded objects",
"if",
"(",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
"&&",
"is_object",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"this",
"->",
"dm",
"->",
"getMetadataFactory",
"(",
")",
"->",
"isTransient",
"(",
"get_class",
"(",
"$",
"value",
")",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"this",
"->",
"pb",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"value",
")",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"is_object",
"(",
"$",
"value",
")",
"&&",
"!",
"(",
"$",
"value",
"instanceof",
"ObjectId",
")",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"prepareReference",
"(",
"$",
"fieldName",
",",
"$",
"value",
",",
"$",
"mapping",
",",
"$",
"inNewObj",
")",
";",
"}",
"catch",
"(",
"MappingException",
"$",
"e",
")",
"{",
"// do nothing in case passed object is not mapped document",
"}",
"}",
"// No further preparation unless we're dealing with a simple reference",
"if",
"(",
"empty",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"||",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"!==",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
"||",
"empty",
"(",
"(",
"array",
")",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"// Additional preparation for one or more simple reference values",
"$",
"targetClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"targetClass",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"// Objects without operators or with DBRef fields can be converted immediately",
"if",
"(",
"!",
"$",
"this",
"->",
"hasQueryOperators",
"(",
"$",
"value",
")",
"||",
"$",
"this",
"->",
"hasDBRefFields",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"targetClass",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"this",
"->",
"prepareQueryExpression",
"(",
"$",
"value",
",",
"$",
"targetClass",
")",
"]",
"]",
";",
"}",
"// Process identifier fields",
"if",
"(",
"(",
"$",
"class",
"->",
"hasField",
"(",
"$",
"fieldName",
")",
"&&",
"$",
"class",
"->",
"isIdentifier",
"(",
"$",
"fieldName",
")",
")",
"||",
"$",
"fieldName",
"===",
"'_id'",
")",
"{",
"$",
"fieldName",
"=",
"'_id'",
";",
"if",
"(",
"!",
"$",
"prepareValue",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"// Objects without operators or with DBRef fields can be converted immediately",
"if",
"(",
"!",
"$",
"this",
"->",
"hasQueryOperators",
"(",
"$",
"value",
")",
"||",
"$",
"this",
"->",
"hasDBRefFields",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"this",
"->",
"prepareQueryExpression",
"(",
"$",
"value",
",",
"$",
"class",
")",
"]",
"]",
";",
"}",
"// No processing for unmapped, non-identifier, non-dotted field names",
"if",
"(",
"strpos",
"(",
"$",
"fieldName",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"/* Process \"fieldName.objectProperty\" queries (on arrays or objects).\n *\n * We can limit parsing here, since at most three segments are\n * significant: \"fieldName.objectProperty\" with an optional index or key\n * for collections stored as either BSON arrays or objects.\n */",
"$",
"e",
"=",
"explode",
"(",
"'.'",
",",
"$",
"fieldName",
",",
"4",
")",
";",
"// No further processing for unmapped fields",
"if",
"(",
"!",
"isset",
"(",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"e",
"[",
"0",
"]",
"]",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"$",
"mapping",
"=",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"e",
"[",
"0",
"]",
"]",
";",
"$",
"e",
"[",
"0",
"]",
"=",
"$",
"mapping",
"[",
"'name'",
"]",
";",
"// Hash and raw fields will not be prepared beyond the field name",
"if",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"Type",
"::",
"HASH",
"||",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"Type",
"::",
"RAW",
")",
"{",
"$",
"fieldName",
"=",
"implode",
"(",
"'.'",
",",
"$",
"e",
")",
";",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"if",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
"&&",
"CollectionHelper",
"::",
"isHash",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"isset",
"(",
"$",
"e",
"[",
"2",
"]",
")",
")",
"{",
"$",
"objectProperty",
"=",
"$",
"e",
"[",
"2",
"]",
";",
"$",
"objectPropertyPrefix",
"=",
"$",
"e",
"[",
"1",
"]",
".",
"'.'",
";",
"$",
"nextObjectProperty",
"=",
"implode",
"(",
"'.'",
",",
"array_slice",
"(",
"$",
"e",
",",
"3",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"e",
"[",
"1",
"]",
"!==",
"'$'",
")",
"{",
"$",
"fieldName",
"=",
"$",
"e",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"e",
"[",
"1",
"]",
";",
"$",
"objectProperty",
"=",
"$",
"e",
"[",
"1",
"]",
";",
"$",
"objectPropertyPrefix",
"=",
"''",
";",
"$",
"nextObjectProperty",
"=",
"implode",
"(",
"'.'",
",",
"array_slice",
"(",
"$",
"e",
",",
"2",
")",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"e",
"[",
"2",
"]",
")",
")",
"{",
"$",
"fieldName",
"=",
"$",
"e",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"e",
"[",
"1",
"]",
".",
"'.'",
".",
"$",
"e",
"[",
"2",
"]",
";",
"$",
"objectProperty",
"=",
"$",
"e",
"[",
"2",
"]",
";",
"$",
"objectPropertyPrefix",
"=",
"$",
"e",
"[",
"1",
"]",
".",
"'.'",
";",
"$",
"nextObjectProperty",
"=",
"implode",
"(",
"'.'",
",",
"array_slice",
"(",
"$",
"e",
",",
"3",
")",
")",
";",
"}",
"else",
"{",
"$",
"fieldName",
"=",
"$",
"e",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"e",
"[",
"1",
"]",
";",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"// No further processing for fields without a targetDocument mapping",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"nextObjectProperty",
")",
"{",
"$",
"fieldName",
".=",
"'.'",
".",
"$",
"nextObjectProperty",
";",
"}",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"$",
"targetClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
";",
"// No further processing for unmapped targetDocument fields",
"if",
"(",
"!",
"$",
"targetClass",
"->",
"hasField",
"(",
"$",
"objectProperty",
")",
")",
"{",
"if",
"(",
"$",
"nextObjectProperty",
")",
"{",
"$",
"fieldName",
".=",
"'.'",
".",
"$",
"nextObjectProperty",
";",
"}",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"$",
"targetMapping",
"=",
"$",
"targetClass",
"->",
"getFieldMapping",
"(",
"$",
"objectProperty",
")",
";",
"$",
"objectPropertyIsId",
"=",
"$",
"targetClass",
"->",
"isIdentifier",
"(",
"$",
"objectProperty",
")",
";",
"// Prepare DBRef identifiers or the mapped field's property path",
"$",
"fieldName",
"=",
"$",
"objectPropertyIsId",
"&&",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"!==",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
"?",
"ClassMetadata",
"::",
"getReferenceFieldName",
"(",
"$",
"mapping",
"[",
"'storeAs'",
"]",
",",
"$",
"e",
"[",
"0",
"]",
")",
":",
"$",
"e",
"[",
"0",
"]",
".",
"'.'",
".",
"$",
"objectPropertyPrefix",
".",
"$",
"targetMapping",
"[",
"'name'",
"]",
";",
"// Process targetDocument identifier fields",
"if",
"(",
"$",
"objectPropertyIsId",
")",
"{",
"if",
"(",
"!",
"$",
"prepareValue",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"targetClass",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"// Objects without operators or with DBRef fields can be converted immediately",
"if",
"(",
"!",
"$",
"this",
"->",
"hasQueryOperators",
"(",
"$",
"value",
")",
"||",
"$",
"this",
"->",
"hasDBRefFields",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"targetClass",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"value",
")",
"]",
"]",
";",
"}",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"this",
"->",
"prepareQueryExpression",
"(",
"$",
"value",
",",
"$",
"targetClass",
")",
"]",
"]",
";",
"}",
"/* The property path may include a third field segment, excluding the\n * collection item pointer. If present, this next object property must\n * be processed recursively.\n */",
"if",
"(",
"$",
"nextObjectProperty",
")",
"{",
"// Respect the targetDocument's class metadata when recursing",
"$",
"nextTargetClass",
"=",
"isset",
"(",
"$",
"targetMapping",
"[",
"'targetDocument'",
"]",
")",
"?",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"targetMapping",
"[",
"'targetDocument'",
"]",
")",
":",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"targetMapping",
"[",
"'reference'",
"]",
")",
")",
"{",
"$",
"fieldNames",
"=",
"$",
"this",
"->",
"prepareQueryElement",
"(",
"$",
"nextObjectProperty",
",",
"$",
"value",
",",
"$",
"nextTargetClass",
",",
"$",
"prepareValue",
")",
";",
"}",
"else",
"{",
"// No recursive processing for references as most probably somebody is querying DBRef or alike",
"if",
"(",
"$",
"nextObjectProperty",
"[",
"0",
"]",
"!==",
"'$'",
"&&",
"in_array",
"(",
"$",
"targetMapping",
"[",
"'storeAs'",
"]",
",",
"[",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF_WITH_DB",
",",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF",
"]",
")",
")",
"{",
"$",
"nextObjectProperty",
"=",
"'$'",
".",
"$",
"nextObjectProperty",
";",
"}",
"$",
"fieldNames",
"=",
"[",
"[",
"$",
"nextObjectProperty",
",",
"$",
"value",
"]",
"]",
";",
"}",
"return",
"array_map",
"(",
"static",
"function",
"(",
"$",
"preparedTuple",
")",
"use",
"(",
"$",
"fieldName",
")",
"{",
"[",
"$",
"key",
",",
"$",
"value",
"]",
"=",
"$",
"preparedTuple",
";",
"return",
"[",
"$",
"fieldName",
".",
"'.'",
".",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}",
",",
"$",
"fieldNames",
")",
";",
"}",
"return",
"[",
"[",
"$",
"fieldName",
",",
"$",
"value",
"]",
"]",
";",
"}"
] | Prepares a query value and converts the PHP value to the database value
if it is an identifier.
It also handles converting $fieldName to the database name if they are
different.
@param mixed $value | [
"Prepares",
"a",
"query",
"value",
"and",
"converts",
"the",
"PHP",
"value",
"to",
"the",
"database",
"value",
"if",
"it",
"is",
"an",
"identifier",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L1017-L1209 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.hasDBRefFields | private function hasDBRefFields($value) : bool
{
if (! is_array($value) && ! is_object($value)) {
return false;
}
if (is_object($value)) {
$value = get_object_vars($value);
}
foreach ($value as $key => $_) {
if ($key === '$ref' || $key === '$id' || $key === '$db') {
return true;
}
}
return false;
} | php | private function hasDBRefFields($value) : bool
{
if (! is_array($value) && ! is_object($value)) {
return false;
}
if (is_object($value)) {
$value = get_object_vars($value);
}
foreach ($value as $key => $_) {
if ($key === '$ref' || $key === '$id' || $key === '$db') {
return true;
}
}
return false;
} | [
"private",
"function",
"hasDBRefFields",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"get_object_vars",
"(",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"_",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'$ref'",
"||",
"$",
"key",
"===",
"'$id'",
"||",
"$",
"key",
"===",
"'$db'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether the value has DBRef fields.
This method doesn't check if the the value is a complete DBRef object,
although it should return true for a DBRef. Rather, we're checking that
the value has one or more fields for a DBref. In practice, this could be
$elemMatch criteria for matching a DBRef.
@param mixed $value | [
"Checks",
"whether",
"the",
"value",
"has",
"DBRef",
"fields",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L1249-L1266 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.hasQueryOperators | private function hasQueryOperators($value) : bool
{
if (! is_array($value) && ! is_object($value)) {
return false;
}
if (is_object($value)) {
$value = get_object_vars($value);
}
foreach ($value as $key => $_) {
if (isset($key[0]) && $key[0] === '$') {
return true;
}
}
return false;
} | php | private function hasQueryOperators($value) : bool
{
if (! is_array($value) && ! is_object($value)) {
return false;
}
if (is_object($value)) {
$value = get_object_vars($value);
}
foreach ($value as $key => $_) {
if (isset($key[0]) && $key[0] === '$') {
return true;
}
}
return false;
} | [
"private",
"function",
"hasQueryOperators",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"get_object_vars",
"(",
"$",
"value",
")",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"key",
"=>",
"$",
"_",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"key",
"[",
"0",
"]",
")",
"&&",
"$",
"key",
"[",
"0",
"]",
"===",
"'$'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether the value has query operators.
@param mixed $value | [
"Checks",
"whether",
"the",
"value",
"has",
"query",
"operators",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L1273-L1290 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.getClassDiscriminatorValues | private function getClassDiscriminatorValues(ClassMetadata $metadata) : array
{
$discriminatorValues = [];
if ($metadata->discriminatorValue !== null) {
$discriminatorValues[] = $metadata->discriminatorValue;
}
foreach ($metadata->subClasses as $className) {
$key = array_search($className, $metadata->discriminatorMap);
if (! $key) {
continue;
}
$discriminatorValues[] = $key;
}
// If a defaultDiscriminatorValue is set and it is among the discriminators being queries, add NULL to the list
if ($metadata->defaultDiscriminatorValue && in_array($metadata->defaultDiscriminatorValue, $discriminatorValues)) {
$discriminatorValues[] = null;
}
return $discriminatorValues;
} | php | private function getClassDiscriminatorValues(ClassMetadata $metadata) : array
{
$discriminatorValues = [];
if ($metadata->discriminatorValue !== null) {
$discriminatorValues[] = $metadata->discriminatorValue;
}
foreach ($metadata->subClasses as $className) {
$key = array_search($className, $metadata->discriminatorMap);
if (! $key) {
continue;
}
$discriminatorValues[] = $key;
}
if ($metadata->defaultDiscriminatorValue && in_array($metadata->defaultDiscriminatorValue, $discriminatorValues)) {
$discriminatorValues[] = null;
}
return $discriminatorValues;
} | [
"private",
"function",
"getClassDiscriminatorValues",
"(",
"ClassMetadata",
"$",
"metadata",
")",
":",
"array",
"{",
"$",
"discriminatorValues",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"metadata",
"->",
"discriminatorValue",
"!==",
"null",
")",
"{",
"$",
"discriminatorValues",
"[",
"]",
"=",
"$",
"metadata",
"->",
"discriminatorValue",
";",
"}",
"foreach",
"(",
"$",
"metadata",
"->",
"subClasses",
"as",
"$",
"className",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"className",
",",
"$",
"metadata",
"->",
"discriminatorMap",
")",
";",
"if",
"(",
"!",
"$",
"key",
")",
"{",
"continue",
";",
"}",
"$",
"discriminatorValues",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"// If a defaultDiscriminatorValue is set and it is among the discriminators being queries, add NULL to the list",
"if",
"(",
"$",
"metadata",
"->",
"defaultDiscriminatorValue",
"&&",
"in_array",
"(",
"$",
"metadata",
"->",
"defaultDiscriminatorValue",
",",
"$",
"discriminatorValues",
")",
")",
"{",
"$",
"discriminatorValues",
"[",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"discriminatorValues",
";",
"}"
] | Returns the list of discriminator values for the given ClassMetadata | [
"Returns",
"the",
"list",
"of",
"discriminator",
"values",
"for",
"the",
"given",
"ClassMetadata"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L1295-L1318 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php | DocumentPersister.getQueryForDocument | private function getQueryForDocument(object $document) : array
{
$id = $this->uow->getDocumentIdentifier($document);
$id = $this->class->getDatabaseIdentifierValue($id);
$shardKeyQueryPart = $this->getShardKeyQuery($document);
return array_merge(['_id' => $id], $shardKeyQueryPart);
} | php | private function getQueryForDocument(object $document) : array
{
$id = $this->uow->getDocumentIdentifier($document);
$id = $this->class->getDatabaseIdentifierValue($id);
$shardKeyQueryPart = $this->getShardKeyQuery($document);
return array_merge(['_id' => $id], $shardKeyQueryPart);
} | [
"private",
"function",
"getQueryForDocument",
"(",
"object",
"$",
"document",
")",
":",
"array",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
";",
"$",
"shardKeyQueryPart",
"=",
"$",
"this",
"->",
"getShardKeyQuery",
"(",
"$",
"document",
")",
";",
"return",
"array_merge",
"(",
"[",
"'_id'",
"=>",
"$",
"id",
"]",
",",
"$",
"shardKeyQueryPart",
")",
";",
"}"
] | Get shard key aware query for single document. | [
"Get",
"shard",
"key",
"aware",
"query",
"for",
"single",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php#L1379-L1386 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Filter/BsonFilter.php | BsonFilter.setParameter | final public function setParameter(string $name, $value) : self
{
$this->parameters[$name] = $value;
return $this;
} | php | final public function setParameter(string $name, $value) : self
{
$this->parameters[$name] = $value;
return $this;
} | [
"final",
"public",
"function",
"setParameter",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a parameter that can be used by the filter.
@param mixed $value Value of the parameter. | [
"Sets",
"a",
"parameter",
"that",
"can",
"be",
"used",
"by",
"the",
"filter",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Filter/BsonFilter.php#L39-L43 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Filter/BsonFilter.php | BsonFilter.getParameter | final public function getParameter(string $name)
{
if (! array_key_exists($name, $this->parameters)) {
throw new InvalidArgumentException("Filter parameter '" . $name . "' is not set.");
}
return $this->parameters[$name];
} | php | final public function getParameter(string $name)
{
if (! array_key_exists($name, $this->parameters)) {
throw new InvalidArgumentException("Filter parameter '" . $name . "' is not set.");
}
return $this->parameters[$name];
} | [
"final",
"public",
"function",
"getParameter",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"parameters",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Filter parameter '\"",
".",
"$",
"name",
".",
"\"' is not set.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
";",
"}"
] | Gets a parameter to use in a query.
These are not like SQL parameters. These parameters can hold anything,
even objects. They are not automatically injected into a query, they
are to be used in the addFilterCriteria method.
@return mixed The parameter. | [
"Gets",
"a",
"parameter",
"to",
"use",
"in",
"a",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Filter/BsonFilter.php#L54-L60 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php | PersistenceBuilder.prepareInsertData | public function prepareInsertData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$insertData = [];
foreach ($class->fieldMappings as $mapping) {
$new = $changeset[$mapping['fieldName']][1] ?? null;
if ($new === null && $mapping['nullable']) {
$insertData[$mapping['name']] = null;
}
/* Nothing more to do for null values, since we're either storing
* them (if nullable was true) or not.
*/
if ($new === null) {
continue;
}
// @Field, @String, @Date, etc.
if (! isset($mapping['association'])) {
$insertData[$mapping['name']] = Type::getType($mapping['type'])->convertToDatabaseValue($new);
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
$insertData[$mapping['name']] = $this->prepareReferencedDocumentValue($mapping, $new);
// @EmbedOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
$insertData[$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
// @ReferenceMany, @EmbedMany
// We're excluding collections using addToSet since there is a risk
// of duplicated entries stored in the collection
} elseif ($mapping['type'] === ClassMetadata::MANY && ! $mapping['isInverseSide']
&& $mapping['strategy'] !== ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET && ! $new->isEmpty()) {
$insertData[$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
}
}
// add discriminator if the class has one
if (isset($class->discriminatorField)) {
$discriminatorValue = $class->discriminatorValue;
if ($discriminatorValue === null) {
if (! empty($class->discriminatorMap)) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
$discriminatorValue = $class->name;
}
$insertData[$class->discriminatorField] = $discriminatorValue;
}
return $insertData;
} | php | public function prepareInsertData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$insertData = [];
foreach ($class->fieldMappings as $mapping) {
$new = $changeset[$mapping['fieldName']][1] ?? null;
if ($new === null && $mapping['nullable']) {
$insertData[$mapping['name']] = null;
}
if ($new === null) {
continue;
}
if (! isset($mapping['association'])) {
$insertData[$mapping['name']] = Type::getType($mapping['type'])->convertToDatabaseValue($new);
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
$insertData[$mapping['name']] = $this->prepareReferencedDocumentValue($mapping, $new);
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
$insertData[$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
} elseif ($mapping['type'] === ClassMetadata::MANY && ! $mapping['isInverseSide']
&& $mapping['strategy'] !== ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET && ! $new->isEmpty()) {
$insertData[$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
}
}
if (isset($class->discriminatorField)) {
$discriminatorValue = $class->discriminatorValue;
if ($discriminatorValue === null) {
if (! empty($class->discriminatorMap)) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
$discriminatorValue = $class->name;
}
$insertData[$class->discriminatorField] = $discriminatorValue;
}
return $insertData;
} | [
"public",
"function",
"prepareInsertData",
"(",
"$",
"document",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"document",
")",
")",
";",
"$",
"changeset",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"document",
")",
";",
"$",
"insertData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"class",
"->",
"fieldMappings",
"as",
"$",
"mapping",
")",
"{",
"$",
"new",
"=",
"$",
"changeset",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"[",
"1",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"new",
"===",
"null",
"&&",
"$",
"mapping",
"[",
"'nullable'",
"]",
")",
"{",
"$",
"insertData",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"null",
";",
"}",
"/* Nothing more to do for null values, since we're either storing\n * them (if nullable was true) or not.\n */",
"if",
"(",
"$",
"new",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"// @Field, @String, @Date, etc.",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
")",
"{",
"$",
"insertData",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"Type",
"::",
"getType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"new",
")",
";",
"// @ReferenceOne",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'association'",
"]",
"===",
"ClassMetadata",
"::",
"REFERENCE_ONE",
")",
"{",
"$",
"insertData",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareReferencedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"new",
")",
";",
"// @EmbedOne",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'association'",
"]",
"===",
"ClassMetadata",
"::",
"EMBED_ONE",
")",
"{",
"$",
"insertData",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"new",
")",
";",
"// @ReferenceMany, @EmbedMany",
"// We're excluding collections using addToSet since there is a risk",
"// of duplicated entries stored in the collection",
"}",
"elseif",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"ClassMetadata",
"::",
"MANY",
"&&",
"!",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
"&&",
"$",
"mapping",
"[",
"'strategy'",
"]",
"!==",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_ADD_TO_SET",
"&&",
"!",
"$",
"new",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"insertData",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareAssociatedCollectionValue",
"(",
"$",
"new",
",",
"true",
")",
";",
"}",
"}",
"// add discriminator if the class has one",
"if",
"(",
"isset",
"(",
"$",
"class",
"->",
"discriminatorField",
")",
")",
"{",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"discriminatorValue",
";",
"if",
"(",
"$",
"discriminatorValue",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
"->",
"discriminatorMap",
")",
")",
"{",
"throw",
"MappingException",
"::",
"unlistedClassInDiscriminatorMap",
"(",
"$",
"class",
"->",
"name",
")",
";",
"}",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"name",
";",
"}",
"$",
"insertData",
"[",
"$",
"class",
"->",
"discriminatorField",
"]",
"=",
"$",
"discriminatorValue",
";",
"}",
"return",
"$",
"insertData",
";",
"}"
] | Prepares the array that is ready to be inserted to mongodb for a given object document.
@param object $document
@return array $insertData | [
"Prepares",
"the",
"array",
"that",
"is",
"ready",
"to",
"be",
"inserted",
"to",
"mongodb",
"for",
"a",
"given",
"object",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php#L59-L116 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php | PersistenceBuilder.prepareUpdateData | public function prepareUpdateData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$updateData = [];
foreach ($changeset as $fieldName => $change) {
$mapping = $class->fieldMappings[$fieldName];
// skip non embedded document identifiers
if (! $class->isEmbeddedDocument && ! empty($mapping['id'])) {
continue;
}
[$old, $new] = $change;
// Scalar fields
if (! isset($mapping['association'])) {
if ($new === null && $mapping['nullable'] !== true) {
$updateData['$unset'][$mapping['name']] = true;
} else {
if ($new !== null && isset($mapping['strategy']) && $mapping['strategy'] === ClassMetadata::STORAGE_STRATEGY_INCREMENT) {
$operator = '$inc';
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new - $old);
} else {
$operator = '$set';
$value = $new === null ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new);
}
$updateData[$operator][$mapping['name']] = $value;
}
// @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['$set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
// If we don't have a new value then lets unset the embedded document
} elseif (! $new) {
$updateData['$unset'][$mapping['name']] = true;
// Update existing embedded document
} else {
$update = $this->prepareUpdateData($new);
foreach ($update as $cmd => $values) {
foreach ($values as $key => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key] = $value;
}
}
}
// @ReferenceMany, @EmbedMany
} elseif (isset($mapping['association']) && $mapping['type'] === 'many' && $new) {
if (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForUpdate($new)) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
} elseif (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForDeletion($new)) {
$updateData['$unset'][$mapping['name']] = true;
$this->uow->unscheduleCollectionDeletion($new);
} elseif (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForDeletion($old)) {
$updateData['$unset'][$mapping['name']] = true;
$this->uow->unscheduleCollectionDeletion($old);
} elseif ($mapping['association'] === ClassMetadata::EMBED_MANY) {
foreach ($new as $key => $embeddedDoc) {
if ($this->uow->isScheduledForInsert($embeddedDoc)) {
continue;
}
$update = $this->prepareUpdateData($embeddedDoc);
foreach ($update as $cmd => $values) {
foreach ($values as $name => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key . '.' . $name] = $value;
}
}
}
}
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if (isset($new) || $mapping['nullable'] === true) {
$updateData['$set'][$mapping['name']] = $new === null ? null : $this->prepareReferencedDocumentValue($mapping, $new);
} else {
$updateData['$unset'][$mapping['name']] = true;
}
}
}
// collections that aren't dirty but could be subject to update are
// excluded from change set, let's go through them now
foreach ($this->uow->getScheduledCollections($document) as $coll) {
$mapping = $coll->getMapping();
if (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForUpdate($coll)) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($coll, true);
} elseif (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForDeletion($coll)) {
$updateData['$unset'][$mapping['name']] = true;
$this->uow->unscheduleCollectionDeletion($coll);
}
// @ReferenceMany is handled by CollectionPersister
}
return $updateData;
} | php | public function prepareUpdateData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$updateData = [];
foreach ($changeset as $fieldName => $change) {
$mapping = $class->fieldMappings[$fieldName];
if (! $class->isEmbeddedDocument && ! empty($mapping['id'])) {
continue;
}
[$old, $new] = $change;
if (! isset($mapping['association'])) {
if ($new === null && $mapping['nullable'] !== true) {
$updateData['$unset'][$mapping['name']] = true;
} else {
if ($new !== null && isset($mapping['strategy']) && $mapping['strategy'] === ClassMetadata::STORAGE_STRATEGY_INCREMENT) {
$operator = '$inc';
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new - $old);
} else {
$operator = '$set';
$value = $new === null ? null : Type::getType($mapping['type'])->convertToDatabaseValue($new);
}
$updateData[$operator][$mapping['name']] = $value;
}
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
if ($new && $this->uow->isScheduledForInsert($new)) {
$updateData['$set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
} elseif (! $new) {
$updateData['$unset'][$mapping['name']] = true;
} else {
$update = $this->prepareUpdateData($new);
foreach ($update as $cmd => $values) {
foreach ($values as $key => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key] = $value;
}
}
}
} elseif (isset($mapping['association']) && $mapping['type'] === 'many' && $new) {
if (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForUpdate($new)) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
} elseif (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForDeletion($new)) {
$updateData['$unset'][$mapping['name']] = true;
$this->uow->unscheduleCollectionDeletion($new);
} elseif (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForDeletion($old)) {
$updateData['$unset'][$mapping['name']] = true;
$this->uow->unscheduleCollectionDeletion($old);
} elseif ($mapping['association'] === ClassMetadata::EMBED_MANY) {
foreach ($new as $key => $embeddedDoc) {
if ($this->uow->isScheduledForInsert($embeddedDoc)) {
continue;
}
$update = $this->prepareUpdateData($embeddedDoc);
foreach ($update as $cmd => $values) {
foreach ($values as $name => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key . '.' . $name] = $value;
}
}
}
}
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if (isset($new) || $mapping['nullable'] === true) {
$updateData['$set'][$mapping['name']] = $new === null ? null : $this->prepareReferencedDocumentValue($mapping, $new);
} else {
$updateData['$unset'][$mapping['name']] = true;
}
}
}
foreach ($this->uow->getScheduledCollections($document) as $coll) {
$mapping = $coll->getMapping();
if (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForUpdate($coll)) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($coll, true);
} elseif (CollectionHelper::isAtomic($mapping['strategy']) && $this->uow->isCollectionScheduledForDeletion($coll)) {
$updateData['$unset'][$mapping['name']] = true;
$this->uow->unscheduleCollectionDeletion($coll);
}
}
return $updateData;
} | [
"public",
"function",
"prepareUpdateData",
"(",
"$",
"document",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"document",
")",
")",
";",
"$",
"changeset",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"document",
")",
";",
"$",
"updateData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"changeset",
"as",
"$",
"fieldName",
"=>",
"$",
"change",
")",
"{",
"$",
"mapping",
"=",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
";",
"// skip non embedded document identifiers",
"if",
"(",
"!",
"$",
"class",
"->",
"isEmbeddedDocument",
"&&",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'id'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"[",
"$",
"old",
",",
"$",
"new",
"]",
"=",
"$",
"change",
";",
"// Scalar fields",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"new",
"===",
"null",
"&&",
"$",
"mapping",
"[",
"'nullable'",
"]",
"!==",
"true",
")",
"{",
"$",
"updateData",
"[",
"'$unset'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"new",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'strategy'",
"]",
"===",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_INCREMENT",
")",
"{",
"$",
"operator",
"=",
"'$inc'",
";",
"$",
"value",
"=",
"Type",
"::",
"getType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"new",
"-",
"$",
"old",
")",
";",
"}",
"else",
"{",
"$",
"operator",
"=",
"'$set'",
";",
"$",
"value",
"=",
"$",
"new",
"===",
"null",
"?",
"null",
":",
"Type",
"::",
"getType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"new",
")",
";",
"}",
"$",
"updateData",
"[",
"$",
"operator",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"// @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",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"new",
")",
";",
"// If we don't have a new value then lets unset the embedded document",
"}",
"elseif",
"(",
"!",
"$",
"new",
")",
"{",
"$",
"updateData",
"[",
"'$unset'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"true",
";",
"// Update existing embedded document",
"}",
"else",
"{",
"$",
"update",
"=",
"$",
"this",
"->",
"prepareUpdateData",
"(",
"$",
"new",
")",
";",
"foreach",
"(",
"$",
"update",
"as",
"$",
"cmd",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"updateData",
"[",
"$",
"cmd",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
".",
"'.'",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"// @ReferenceMany, @EmbedMany",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
"&&",
"$",
"new",
")",
"{",
"if",
"(",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForUpdate",
"(",
"$",
"new",
")",
")",
"{",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareAssociatedCollectionValue",
"(",
"$",
"new",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForDeletion",
"(",
"$",
"new",
")",
")",
"{",
"$",
"updateData",
"[",
"'$unset'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionDeletion",
"(",
"$",
"new",
")",
";",
"}",
"elseif",
"(",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForDeletion",
"(",
"$",
"old",
")",
")",
"{",
"$",
"updateData",
"[",
"'$unset'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionDeletion",
"(",
"$",
"old",
")",
";",
"}",
"elseif",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
"===",
"ClassMetadata",
"::",
"EMBED_MANY",
")",
"{",
"foreach",
"(",
"$",
"new",
"as",
"$",
"key",
"=>",
"$",
"embeddedDoc",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"uow",
"->",
"isScheduledForInsert",
"(",
"$",
"embeddedDoc",
")",
")",
"{",
"continue",
";",
"}",
"$",
"update",
"=",
"$",
"this",
"->",
"prepareUpdateData",
"(",
"$",
"embeddedDoc",
")",
";",
"foreach",
"(",
"$",
"update",
"as",
"$",
"cmd",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"updateData",
"[",
"$",
"cmd",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
".",
"'.'",
".",
"$",
"key",
".",
"'.'",
".",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}",
"// @ReferenceOne",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'association'",
"]",
"===",
"ClassMetadata",
"::",
"REFERENCE_ONE",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
"||",
"$",
"mapping",
"[",
"'nullable'",
"]",
"===",
"true",
")",
"{",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"new",
"===",
"null",
"?",
"null",
":",
"$",
"this",
"->",
"prepareReferencedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"new",
")",
";",
"}",
"else",
"{",
"$",
"updateData",
"[",
"'$unset'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"// collections that aren't dirty but could be subject to update are",
"// excluded from change set, let's go through them now",
"foreach",
"(",
"$",
"this",
"->",
"uow",
"->",
"getScheduledCollections",
"(",
"$",
"document",
")",
"as",
"$",
"coll",
")",
"{",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"if",
"(",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForUpdate",
"(",
"$",
"coll",
")",
")",
"{",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareAssociatedCollectionValue",
"(",
"$",
"coll",
",",
"true",
")",
";",
"}",
"elseif",
"(",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForDeletion",
"(",
"$",
"coll",
")",
")",
"{",
"$",
"updateData",
"[",
"'$unset'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionDeletion",
"(",
"$",
"coll",
")",
";",
"}",
"// @ReferenceMany is handled by CollectionPersister",
"}",
"return",
"$",
"updateData",
";",
"}"
] | Prepares the update query to update a given document object in mongodb.
@param object $document
@return array $updateData | [
"Prepares",
"the",
"update",
"query",
"to",
"update",
"a",
"given",
"document",
"object",
"in",
"mongodb",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php#L125-L224 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php | PersistenceBuilder.prepareUpsertData | public function prepareUpsertData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$updateData = [];
foreach ($changeset as $fieldName => $change) {
$mapping = $class->fieldMappings[$fieldName];
[$old, $new] = $change;
// Scalar fields
if (! isset($mapping['association'])) {
if ($new !== null) {
if (empty($mapping['id']) && isset($mapping['strategy']) && $mapping['strategy'] === ClassMetadata::STORAGE_STRATEGY_INCREMENT) {
$operator = '$inc';
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new - $old);
} else {
$operator = '$set';
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new);
}
$updateData[$operator][$mapping['name']] = $value;
} elseif ($mapping['nullable'] === true) {
$updateData['$setOnInsert'][$mapping['name']] = null;
}
// @EmbedOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
// If we don't have a new value then do nothing on upsert
// If we have a new embedded document then lets set the whole thing
if ($new && $this->uow->isScheduledForInsert($new)) {
$updateData['$set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
} elseif ($new) {
// Update existing embedded document
$update = $this->prepareUpsertData($new);
foreach ($update as $cmd => $values) {
foreach ($values as $key => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key] = $value;
}
}
}
// @ReferenceOne
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if (isset($new) || $mapping['nullable'] === true) {
$updateData['$set'][$mapping['name']] = $new === null ? null : $this->prepareReferencedDocumentValue($mapping, $new);
}
// @ReferenceMany, @EmbedMany
} elseif ($mapping['type'] === ClassMetadata::MANY && ! $mapping['isInverseSide']
&& $new instanceof PersistentCollectionInterface && $new->isDirty()
&& CollectionHelper::isAtomic($mapping['strategy'])) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
}
// @EmbedMany and @ReferenceMany are handled by CollectionPersister
}
// add discriminator if the class has one
if (isset($class->discriminatorField)) {
$discriminatorValue = $class->discriminatorValue;
if ($discriminatorValue === null) {
if (! empty($class->discriminatorMap)) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
$discriminatorValue = $class->name;
}
$updateData['$set'][$class->discriminatorField] = $discriminatorValue;
}
return $updateData;
} | php | public function prepareUpsertData($document)
{
$class = $this->dm->getClassMetadata(get_class($document));
$changeset = $this->uow->getDocumentChangeSet($document);
$updateData = [];
foreach ($changeset as $fieldName => $change) {
$mapping = $class->fieldMappings[$fieldName];
[$old, $new] = $change;
if (! isset($mapping['association'])) {
if ($new !== null) {
if (empty($mapping['id']) && isset($mapping['strategy']) && $mapping['strategy'] === ClassMetadata::STORAGE_STRATEGY_INCREMENT) {
$operator = '$inc';
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new - $old);
} else {
$operator = '$set';
$value = Type::getType($mapping['type'])->convertToDatabaseValue($new);
}
$updateData[$operator][$mapping['name']] = $value;
} elseif ($mapping['nullable'] === true) {
$updateData['$setOnInsert'][$mapping['name']] = null;
}
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::EMBED_ONE) {
if ($new && $this->uow->isScheduledForInsert($new)) {
$updateData['$set'][$mapping['name']] = $this->prepareEmbeddedDocumentValue($mapping, $new);
} elseif ($new) {
$update = $this->prepareUpsertData($new);
foreach ($update as $cmd => $values) {
foreach ($values as $key => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key] = $value;
}
}
}
} elseif (isset($mapping['association']) && $mapping['association'] === ClassMetadata::REFERENCE_ONE) {
if (isset($new) || $mapping['nullable'] === true) {
$updateData['$set'][$mapping['name']] = $new === null ? null : $this->prepareReferencedDocumentValue($mapping, $new);
}
} elseif ($mapping['type'] === ClassMetadata::MANY && ! $mapping['isInverseSide']
&& $new instanceof PersistentCollectionInterface && $new->isDirty()
&& CollectionHelper::isAtomic($mapping['strategy'])) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
}
}
if (isset($class->discriminatorField)) {
$discriminatorValue = $class->discriminatorValue;
if ($discriminatorValue === null) {
if (! empty($class->discriminatorMap)) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
$discriminatorValue = $class->name;
}
$updateData['$set'][$class->discriminatorField] = $discriminatorValue;
}
return $updateData;
} | [
"public",
"function",
"prepareUpsertData",
"(",
"$",
"document",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"document",
")",
")",
";",
"$",
"changeset",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"document",
")",
";",
"$",
"updateData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"changeset",
"as",
"$",
"fieldName",
"=>",
"$",
"change",
")",
"{",
"$",
"mapping",
"=",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
";",
"[",
"$",
"old",
",",
"$",
"new",
"]",
"=",
"$",
"change",
";",
"// Scalar fields",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"new",
"!==",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"mapping",
"[",
"'id'",
"]",
")",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'strategy'",
"]",
"===",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_INCREMENT",
")",
"{",
"$",
"operator",
"=",
"'$inc'",
";",
"$",
"value",
"=",
"Type",
"::",
"getType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"new",
"-",
"$",
"old",
")",
";",
"}",
"else",
"{",
"$",
"operator",
"=",
"'$set'",
";",
"$",
"value",
"=",
"Type",
"::",
"getType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"new",
")",
";",
"}",
"$",
"updateData",
"[",
"$",
"operator",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"elseif",
"(",
"$",
"mapping",
"[",
"'nullable'",
"]",
"===",
"true",
")",
"{",
"$",
"updateData",
"[",
"'$setOnInsert'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"null",
";",
"}",
"// @EmbedOne",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'association'",
"]",
"===",
"ClassMetadata",
"::",
"EMBED_ONE",
")",
"{",
"// If we don't have a new value then do nothing on upsert",
"// If we have a new embedded document then lets set the whole thing",
"if",
"(",
"$",
"new",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isScheduledForInsert",
"(",
"$",
"new",
")",
")",
"{",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"new",
")",
";",
"}",
"elseif",
"(",
"$",
"new",
")",
"{",
"// Update existing embedded document",
"$",
"update",
"=",
"$",
"this",
"->",
"prepareUpsertData",
"(",
"$",
"new",
")",
";",
"foreach",
"(",
"$",
"update",
"as",
"$",
"cmd",
"=>",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"updateData",
"[",
"$",
"cmd",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
".",
"'.'",
".",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"// @ReferenceOne",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'association'",
"]",
"===",
"ClassMetadata",
"::",
"REFERENCE_ONE",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"new",
")",
"||",
"$",
"mapping",
"[",
"'nullable'",
"]",
"===",
"true",
")",
"{",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"new",
"===",
"null",
"?",
"null",
":",
"$",
"this",
"->",
"prepareReferencedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"new",
")",
";",
"}",
"// @ReferenceMany, @EmbedMany",
"}",
"elseif",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"ClassMetadata",
"::",
"MANY",
"&&",
"!",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
"&&",
"$",
"new",
"instanceof",
"PersistentCollectionInterface",
"&&",
"$",
"new",
"->",
"isDirty",
"(",
")",
"&&",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"prepareAssociatedCollectionValue",
"(",
"$",
"new",
",",
"true",
")",
";",
"}",
"// @EmbedMany and @ReferenceMany are handled by CollectionPersister",
"}",
"// add discriminator if the class has one",
"if",
"(",
"isset",
"(",
"$",
"class",
"->",
"discriminatorField",
")",
")",
"{",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"discriminatorValue",
";",
"if",
"(",
"$",
"discriminatorValue",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
"->",
"discriminatorMap",
")",
")",
"{",
"throw",
"MappingException",
"::",
"unlistedClassInDiscriminatorMap",
"(",
"$",
"class",
"->",
"name",
")",
";",
"}",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"name",
";",
"}",
"$",
"updateData",
"[",
"'$set'",
"]",
"[",
"$",
"class",
"->",
"discriminatorField",
"]",
"=",
"$",
"discriminatorValue",
";",
"}",
"return",
"$",
"updateData",
";",
"}"
] | Prepares the update query to upsert a given document object in mongodb.
@param object $document
@return array $updateData | [
"Prepares",
"the",
"update",
"query",
"to",
"upsert",
"a",
"given",
"document",
"object",
"in",
"mongodb",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php#L233-L307 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php | PersistenceBuilder.prepareEmbeddedDocumentValue | public function prepareEmbeddedDocumentValue(array $embeddedMapping, $embeddedDocument, $includeNestedCollections = false)
{
$embeddedDocumentValue = [];
$class = $this->dm->getClassMetadata(get_class($embeddedDocument));
foreach ($class->fieldMappings as $mapping) {
// Skip notSaved fields
if (! empty($mapping['notSaved'])) {
continue;
}
// Inline ClassMetadata::getFieldValue()
$rawValue = $class->reflFields[$mapping['fieldName']]->getValue($embeddedDocument);
$value = null;
if ($rawValue !== null) {
switch ($mapping['association'] ?? null) {
// @Field, @String, @Date, etc.
case null:
$value = Type::getType($mapping['type'])->convertToDatabaseValue($rawValue);
break;
case ClassMetadata::EMBED_ONE:
case ClassMetadata::REFERENCE_ONE:
// Nested collections should only be included for embedded relationships
$value = $this->prepareAssociatedDocumentValue($mapping, $rawValue, $includeNestedCollections && isset($mapping['embedded']));
break;
case ClassMetadata::EMBED_MANY:
case ClassMetadata::REFERENCE_MANY:
// Skip PersistentCollections already scheduled for deletion
if (! $includeNestedCollections && $rawValue instanceof PersistentCollectionInterface
&& $this->uow->isCollectionScheduledForDeletion($rawValue)) {
break;
}
$value = $this->prepareAssociatedCollectionValue($rawValue, $includeNestedCollections);
break;
default:
throw new UnexpectedValueException('Unsupported mapping association: ' . $mapping['association']);
}
}
// Omit non-nullable fields that would have a null value
if ($value === null && $mapping['nullable'] === false) {
continue;
}
$embeddedDocumentValue[$mapping['name']] = $value;
}
/* Add a discriminator value if the embedded document is not mapped
* explicitly to a targetDocument class.
*/
if (! isset($embeddedMapping['targetDocument'])) {
$discriminatorField = $embeddedMapping['discriminatorField'];
if (! empty($embeddedMapping['discriminatorMap'])) {
$discriminatorValue = array_search($class->name, $embeddedMapping['discriminatorMap']);
if ($discriminatorValue === false) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
} else {
$discriminatorValue = $class->name;
}
$embeddedDocumentValue[$discriminatorField] = $discriminatorValue;
}
/* If the class has a discriminator (field and value), use it. A child
* class that is not defined in the discriminator map may only have a
* discriminator field and no value, so default to the full class name.
*/
if (isset($class->discriminatorField)) {
$discriminatorValue = $class->discriminatorValue;
if ($discriminatorValue === null) {
if (! empty($class->discriminatorMap)) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
$discriminatorValue = $class->name;
}
$embeddedDocumentValue[$class->discriminatorField] = $discriminatorValue;
}
// Ensure empty embedded documents are stored as BSON objects
if (empty($embeddedDocumentValue)) {
return (object) $embeddedDocumentValue;
}
/* @todo Consider always casting the return value to an object, or
* building $embeddedDocumentValue as an object instead of an array, to
* handle the edge case where all database field names are sequential,
* numeric keys.
*/
return $embeddedDocumentValue;
} | php | public function prepareEmbeddedDocumentValue(array $embeddedMapping, $embeddedDocument, $includeNestedCollections = false)
{
$embeddedDocumentValue = [];
$class = $this->dm->getClassMetadata(get_class($embeddedDocument));
foreach ($class->fieldMappings as $mapping) {
if (! empty($mapping['notSaved'])) {
continue;
}
$rawValue = $class->reflFields[$mapping['fieldName']]->getValue($embeddedDocument);
$value = null;
if ($rawValue !== null) {
switch ($mapping['association'] ?? null) {
case null:
$value = Type::getType($mapping['type'])->convertToDatabaseValue($rawValue);
break;
case ClassMetadata::EMBED_ONE:
case ClassMetadata::REFERENCE_ONE:
$value = $this->prepareAssociatedDocumentValue($mapping, $rawValue, $includeNestedCollections && isset($mapping['embedded']));
break;
case ClassMetadata::EMBED_MANY:
case ClassMetadata::REFERENCE_MANY:
if (! $includeNestedCollections && $rawValue instanceof PersistentCollectionInterface
&& $this->uow->isCollectionScheduledForDeletion($rawValue)) {
break;
}
$value = $this->prepareAssociatedCollectionValue($rawValue, $includeNestedCollections);
break;
default:
throw new UnexpectedValueException('Unsupported mapping association: ' . $mapping['association']);
}
}
if ($value === null && $mapping['nullable'] === false) {
continue;
}
$embeddedDocumentValue[$mapping['name']] = $value;
}
if (! isset($embeddedMapping['targetDocument'])) {
$discriminatorField = $embeddedMapping['discriminatorField'];
if (! empty($embeddedMapping['discriminatorMap'])) {
$discriminatorValue = array_search($class->name, $embeddedMapping['discriminatorMap']);
if ($discriminatorValue === false) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
} else {
$discriminatorValue = $class->name;
}
$embeddedDocumentValue[$discriminatorField] = $discriminatorValue;
}
if (isset($class->discriminatorField)) {
$discriminatorValue = $class->discriminatorValue;
if ($discriminatorValue === null) {
if (! empty($class->discriminatorMap)) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
$discriminatorValue = $class->name;
}
$embeddedDocumentValue[$class->discriminatorField] = $discriminatorValue;
}
if (empty($embeddedDocumentValue)) {
return (object) $embeddedDocumentValue;
}
return $embeddedDocumentValue;
} | [
"public",
"function",
"prepareEmbeddedDocumentValue",
"(",
"array",
"$",
"embeddedMapping",
",",
"$",
"embeddedDocument",
",",
"$",
"includeNestedCollections",
"=",
"false",
")",
"{",
"$",
"embeddedDocumentValue",
"=",
"[",
"]",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"embeddedDocument",
")",
")",
";",
"foreach",
"(",
"$",
"class",
"->",
"fieldMappings",
"as",
"$",
"mapping",
")",
"{",
"// Skip notSaved fields",
"if",
"(",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'notSaved'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"// Inline ClassMetadata::getFieldValue()",
"$",
"rawValue",
"=",
"$",
"class",
"->",
"reflFields",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"->",
"getValue",
"(",
"$",
"embeddedDocument",
")",
";",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"$",
"rawValue",
"!==",
"null",
")",
"{",
"switch",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
"??",
"null",
")",
"{",
"// @Field, @String, @Date, etc.",
"case",
"null",
":",
"$",
"value",
"=",
"Type",
"::",
"getType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"rawValue",
")",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"EMBED_ONE",
":",
"case",
"ClassMetadata",
"::",
"REFERENCE_ONE",
":",
"// Nested collections should only be included for embedded relationships",
"$",
"value",
"=",
"$",
"this",
"->",
"prepareAssociatedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"rawValue",
",",
"$",
"includeNestedCollections",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"EMBED_MANY",
":",
"case",
"ClassMetadata",
"::",
"REFERENCE_MANY",
":",
"// Skip PersistentCollections already scheduled for deletion",
"if",
"(",
"!",
"$",
"includeNestedCollections",
"&&",
"$",
"rawValue",
"instanceof",
"PersistentCollectionInterface",
"&&",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForDeletion",
"(",
"$",
"rawValue",
")",
")",
"{",
"break",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"prepareAssociatedCollectionValue",
"(",
"$",
"rawValue",
",",
"$",
"includeNestedCollections",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Unsupported mapping association: '",
".",
"$",
"mapping",
"[",
"'association'",
"]",
")",
";",
"}",
"}",
"// Omit non-nullable fields that would have a null value",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"$",
"mapping",
"[",
"'nullable'",
"]",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"embeddedDocumentValue",
"[",
"$",
"mapping",
"[",
"'name'",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"/* Add a discriminator value if the embedded document is not mapped\n * explicitly to a targetDocument class.\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"embeddedMapping",
"[",
"'targetDocument'",
"]",
")",
")",
"{",
"$",
"discriminatorField",
"=",
"$",
"embeddedMapping",
"[",
"'discriminatorField'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"embeddedMapping",
"[",
"'discriminatorMap'",
"]",
")",
")",
"{",
"$",
"discriminatorValue",
"=",
"array_search",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"embeddedMapping",
"[",
"'discriminatorMap'",
"]",
")",
";",
"if",
"(",
"$",
"discriminatorValue",
"===",
"false",
")",
"{",
"throw",
"MappingException",
"::",
"unlistedClassInDiscriminatorMap",
"(",
"$",
"class",
"->",
"name",
")",
";",
"}",
"}",
"else",
"{",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"name",
";",
"}",
"$",
"embeddedDocumentValue",
"[",
"$",
"discriminatorField",
"]",
"=",
"$",
"discriminatorValue",
";",
"}",
"/* If the class has a discriminator (field and value), use it. A child\n * class that is not defined in the discriminator map may only have a\n * discriminator field and no value, so default to the full class name.\n */",
"if",
"(",
"isset",
"(",
"$",
"class",
"->",
"discriminatorField",
")",
")",
"{",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"discriminatorValue",
";",
"if",
"(",
"$",
"discriminatorValue",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
"->",
"discriminatorMap",
")",
")",
"{",
"throw",
"MappingException",
"::",
"unlistedClassInDiscriminatorMap",
"(",
"$",
"class",
"->",
"name",
")",
";",
"}",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"name",
";",
"}",
"$",
"embeddedDocumentValue",
"[",
"$",
"class",
"->",
"discriminatorField",
"]",
"=",
"$",
"discriminatorValue",
";",
"}",
"// Ensure empty embedded documents are stored as BSON objects",
"if",
"(",
"empty",
"(",
"$",
"embeddedDocumentValue",
")",
")",
"{",
"return",
"(",
"object",
")",
"$",
"embeddedDocumentValue",
";",
"}",
"/* @todo Consider always casting the return value to an object, or\n * building $embeddedDocumentValue as an object instead of an array, to\n * handle the edge case where all database field names are sequential,\n * numeric keys.\n */",
"return",
"$",
"embeddedDocumentValue",
";",
"}"
] | Returns the embedded document to be stored in MongoDB.
The return value will usually be an associative array with string keys
corresponding to field names on the embedded document. An object may be
returned if the document is empty, to ensure that a BSON object will be
stored in lieu of an array.
If $includeNestedCollections is true, nested collections will be included
in this prepared value and the option will cascade to all embedded
associations. If any nested PersistentCollections (embed or reference)
within this value were previously scheduled for deletion or update, they
will also be unscheduled.
@param array $embeddedMapping
@param object $embeddedDocument
@param bool $includeNestedCollections
@return array|object
@throws UnexpectedValueException If an unsupported associating mapping is found. | [
"Returns",
"the",
"embedded",
"document",
"to",
"be",
"stored",
"in",
"MongoDB",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php#L347-L447 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php | PersistenceBuilder.prepareAssociatedDocumentValue | public function prepareAssociatedDocumentValue(array $mapping, $document, $includeNestedCollections = false)
{
if (isset($mapping['embedded'])) {
return $this->prepareEmbeddedDocumentValue($mapping, $document, $includeNestedCollections);
}
if (isset($mapping['reference'])) {
return $this->prepareReferencedDocumentValue($mapping, $document);
}
throw new InvalidArgumentException('Mapping is neither embedded nor reference.');
} | php | public function prepareAssociatedDocumentValue(array $mapping, $document, $includeNestedCollections = false)
{
if (isset($mapping['embedded'])) {
return $this->prepareEmbeddedDocumentValue($mapping, $document, $includeNestedCollections);
}
if (isset($mapping['reference'])) {
return $this->prepareReferencedDocumentValue($mapping, $document);
}
throw new InvalidArgumentException('Mapping is neither embedded nor reference.');
} | [
"public",
"function",
"prepareAssociatedDocumentValue",
"(",
"array",
"$",
"mapping",
",",
"$",
"document",
",",
"$",
"includeNestedCollections",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"document",
",",
"$",
"includeNestedCollections",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"prepareReferencedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"document",
")",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Mapping is neither embedded nor reference.'",
")",
";",
"}"
] | Returns the embedded document or reference representation to be stored.
@param array $mapping
@param object $document
@param bool $includeNestedCollections
@return array|object|null
@throws InvalidArgumentException If the mapping is neither embedded nor reference. | [
"Returns",
"the",
"embedded",
"document",
"or",
"reference",
"representation",
"to",
"be",
"stored",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php#L460-L471 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php | PersistenceBuilder.prepareAssociatedCollectionValue | public function prepareAssociatedCollectionValue(PersistentCollectionInterface $coll, $includeNestedCollections = false)
{
$mapping = $coll->getMapping();
$pb = $this;
$callback = isset($mapping['embedded'])
? static function ($v) use ($pb, $mapping, $includeNestedCollections) {
return $pb->prepareEmbeddedDocumentValue($mapping, $v, $includeNestedCollections);
}
: static function ($v) use ($pb, $mapping) {
return $pb->prepareReferencedDocumentValue($mapping, $v);
};
$setData = $coll->map($callback)->toArray();
if (CollectionHelper::isList($mapping['strategy'])) {
$setData = array_values($setData);
}
$this->uow->unscheduleCollectionDeletion($coll);
$this->uow->unscheduleCollectionUpdate($coll);
return $setData;
} | php | public function prepareAssociatedCollectionValue(PersistentCollectionInterface $coll, $includeNestedCollections = false)
{
$mapping = $coll->getMapping();
$pb = $this;
$callback = isset($mapping['embedded'])
? static function ($v) use ($pb, $mapping, $includeNestedCollections) {
return $pb->prepareEmbeddedDocumentValue($mapping, $v, $includeNestedCollections);
}
: static function ($v) use ($pb, $mapping) {
return $pb->prepareReferencedDocumentValue($mapping, $v);
};
$setData = $coll->map($callback)->toArray();
if (CollectionHelper::isList($mapping['strategy'])) {
$setData = array_values($setData);
}
$this->uow->unscheduleCollectionDeletion($coll);
$this->uow->unscheduleCollectionUpdate($coll);
return $setData;
} | [
"public",
"function",
"prepareAssociatedCollectionValue",
"(",
"PersistentCollectionInterface",
"$",
"coll",
",",
"$",
"includeNestedCollections",
"=",
"false",
")",
"{",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"$",
"pb",
"=",
"$",
"this",
";",
"$",
"callback",
"=",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
"?",
"static",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"$",
"pb",
",",
"$",
"mapping",
",",
"$",
"includeNestedCollections",
")",
"{",
"return",
"$",
"pb",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"v",
",",
"$",
"includeNestedCollections",
")",
";",
"}",
":",
"static",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"$",
"pb",
",",
"$",
"mapping",
")",
"{",
"return",
"$",
"pb",
"->",
"prepareReferencedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"v",
")",
";",
"}",
";",
"$",
"setData",
"=",
"$",
"coll",
"->",
"map",
"(",
"$",
"callback",
")",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"CollectionHelper",
"::",
"isList",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"$",
"setData",
"=",
"array_values",
"(",
"$",
"setData",
")",
";",
"}",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionDeletion",
"(",
"$",
"coll",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"unscheduleCollectionUpdate",
"(",
"$",
"coll",
")",
";",
"return",
"$",
"setData",
";",
"}"
] | Returns the collection representation to be stored and unschedules it afterwards.
@param bool $includeNestedCollections
@return array | [
"Returns",
"the",
"collection",
"representation",
"to",
"be",
"stored",
"and",
"unschedules",
"it",
"afterwards",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php#L480-L501 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.initialize | protected function initialize() : void
{
$driver = $this->config->getMetadataDriverImpl();
if ($driver === null) {
throw ConfigurationException::noMetadataDriverConfigured();
}
$this->driver = $driver;
$this->evm = $this->dm->getEventManager();
$this->initialized = true;
} | php | protected function initialize() : void
{
$driver = $this->config->getMetadataDriverImpl();
if ($driver === null) {
throw ConfigurationException::noMetadataDriverConfigured();
}
$this->driver = $driver;
$this->evm = $this->dm->getEventManager();
$this->initialized = true;
} | [
"protected",
"function",
"initialize",
"(",
")",
":",
"void",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"config",
"->",
"getMetadataDriverImpl",
"(",
")",
";",
"if",
"(",
"$",
"driver",
"===",
"null",
")",
"{",
"throw",
"ConfigurationException",
"::",
"noMetadataDriverConfigured",
"(",
")",
";",
"}",
"$",
"this",
"->",
"driver",
"=",
"$",
"driver",
";",
"$",
"this",
"->",
"evm",
"=",
"$",
"this",
"->",
"dm",
"->",
"getEventManager",
"(",
")",
";",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"}"
] | Lazy initialization of this stuff, especially the metadata driver,
since these are not needed at all when a metadata cache is active. | [
"Lazy",
"initialization",
"of",
"this",
"stuff",
"especially",
"the",
"metadata",
"driver",
"since",
"these",
"are",
"not",
"needed",
"at",
"all",
"when",
"a",
"metadata",
"cache",
"is",
"active",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L73-L83 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.onNotFoundMetadata | protected function onNotFoundMetadata($className)
{
if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
return null;
}
$eventArgs = new OnClassMetadataNotFoundEventArgs($className, $this->dm);
$this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs);
return $eventArgs->getFoundMetadata();
} | php | protected function onNotFoundMetadata($className)
{
if (! $this->evm->hasListeners(Events::onClassMetadataNotFound)) {
return null;
}
$eventArgs = new OnClassMetadataNotFoundEventArgs($className, $this->dm);
$this->evm->dispatchEvent(Events::onClassMetadataNotFound, $eventArgs);
return $eventArgs->getFoundMetadata();
} | [
"protected",
"function",
"onNotFoundMetadata",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"evm",
"->",
"hasListeners",
"(",
"Events",
"::",
"onClassMetadataNotFound",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"eventArgs",
"=",
"new",
"OnClassMetadataNotFoundEventArgs",
"(",
"$",
"className",
",",
"$",
"this",
"->",
"dm",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"onClassMetadataNotFound",
",",
"$",
"eventArgs",
")",
";",
"return",
"$",
"eventArgs",
"->",
"getFoundMetadata",
"(",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L88-L99 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.doLoadMetadata | protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents = []) : void
{
assert($class instanceof ClassMetadata);
if ($parent instanceof ClassMetadata) {
$class->setInheritanceType($parent->inheritanceType);
$class->setDiscriminatorField($parent->discriminatorField);
$class->setDiscriminatorMap($parent->discriminatorMap);
$class->setDefaultDiscriminatorValue($parent->defaultDiscriminatorValue);
$class->setIdGeneratorType($parent->generatorType);
$this->addInheritedFields($class, $parent);
$this->addInheritedRelations($class, $parent);
$this->addInheritedIndexes($class, $parent);
$this->setInheritedShardKey($class, $parent);
$class->setIdentifier($parent->identifier);
$class->setVersioned($parent->isVersioned);
$class->setVersionField($parent->versionField);
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
$class->setAlsoLoadMethods($parent->alsoLoadMethods);
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
$class->setReadPreference($parent->readPreference, $parent->readPreferenceTags);
$class->setWriteConcern($parent->writeConcern);
if ($parent->isMappedSuperclass) {
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
}
if ($parent->isFile) {
$class->isFile = true;
$class->setBucketName($parent->bucketName);
if ($parent->chunkSizeBytes !== null) {
$class->setChunkSizeBytes($parent->chunkSizeBytes);
}
}
}
// Invoke driver
try {
$this->driver->loadMetadataForClass($class->getName(), $class);
} catch (ReflectionException $e) {
throw MappingException::reflectionFailure($class->getName(), $e);
}
$this->validateIdentifier($class);
if ($parent instanceof ClassMetadata && $rootEntityFound && $parent->generatorType === $class->generatorType) {
if ($parent->generatorType) {
$class->setIdGeneratorType($parent->generatorType);
}
if ($parent->generatorOptions) {
$class->setIdGeneratorOptions($parent->generatorOptions);
}
if ($parent->idGenerator) {
$class->setIdGenerator($parent->idGenerator);
}
} else {
$this->completeIdGeneratorMapping($class);
}
if ($parent instanceof ClassMetadata && $parent->isInheritanceTypeSingleCollection()) {
$class->setDatabase($parent->getDatabase());
$class->setCollection($parent->getCollection());
}
$class->setParentClasses($nonSuperclassParents);
if (! $this->evm->hasListeners(Events::loadClassMetadata)) {
return;
}
$eventArgs = new LoadClassMetadataEventArgs($class, $this->dm);
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
} | php | protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents = []) : void
{
assert($class instanceof ClassMetadata);
if ($parent instanceof ClassMetadata) {
$class->setInheritanceType($parent->inheritanceType);
$class->setDiscriminatorField($parent->discriminatorField);
$class->setDiscriminatorMap($parent->discriminatorMap);
$class->setDefaultDiscriminatorValue($parent->defaultDiscriminatorValue);
$class->setIdGeneratorType($parent->generatorType);
$this->addInheritedFields($class, $parent);
$this->addInheritedRelations($class, $parent);
$this->addInheritedIndexes($class, $parent);
$this->setInheritedShardKey($class, $parent);
$class->setIdentifier($parent->identifier);
$class->setVersioned($parent->isVersioned);
$class->setVersionField($parent->versionField);
$class->setLifecycleCallbacks($parent->lifecycleCallbacks);
$class->setAlsoLoadMethods($parent->alsoLoadMethods);
$class->setChangeTrackingPolicy($parent->changeTrackingPolicy);
$class->setReadPreference($parent->readPreference, $parent->readPreferenceTags);
$class->setWriteConcern($parent->writeConcern);
if ($parent->isMappedSuperclass) {
$class->setCustomRepositoryClass($parent->customRepositoryClassName);
}
if ($parent->isFile) {
$class->isFile = true;
$class->setBucketName($parent->bucketName);
if ($parent->chunkSizeBytes !== null) {
$class->setChunkSizeBytes($parent->chunkSizeBytes);
}
}
}
try {
$this->driver->loadMetadataForClass($class->getName(), $class);
} catch (ReflectionException $e) {
throw MappingException::reflectionFailure($class->getName(), $e);
}
$this->validateIdentifier($class);
if ($parent instanceof ClassMetadata && $rootEntityFound && $parent->generatorType === $class->generatorType) {
if ($parent->generatorType) {
$class->setIdGeneratorType($parent->generatorType);
}
if ($parent->generatorOptions) {
$class->setIdGeneratorOptions($parent->generatorOptions);
}
if ($parent->idGenerator) {
$class->setIdGenerator($parent->idGenerator);
}
} else {
$this->completeIdGeneratorMapping($class);
}
if ($parent instanceof ClassMetadata && $parent->isInheritanceTypeSingleCollection()) {
$class->setDatabase($parent->getDatabase());
$class->setCollection($parent->getCollection());
}
$class->setParentClasses($nonSuperclassParents);
if (! $this->evm->hasListeners(Events::loadClassMetadata)) {
return;
}
$eventArgs = new LoadClassMetadataEventArgs($class, $this->dm);
$this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
} | [
"protected",
"function",
"doLoadMetadata",
"(",
"$",
"class",
",",
"$",
"parent",
",",
"$",
"rootEntityFound",
",",
"array",
"$",
"nonSuperclassParents",
"=",
"[",
"]",
")",
":",
"void",
"{",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"if",
"(",
"$",
"parent",
"instanceof",
"ClassMetadata",
")",
"{",
"$",
"class",
"->",
"setInheritanceType",
"(",
"$",
"parent",
"->",
"inheritanceType",
")",
";",
"$",
"class",
"->",
"setDiscriminatorField",
"(",
"$",
"parent",
"->",
"discriminatorField",
")",
";",
"$",
"class",
"->",
"setDiscriminatorMap",
"(",
"$",
"parent",
"->",
"discriminatorMap",
")",
";",
"$",
"class",
"->",
"setDefaultDiscriminatorValue",
"(",
"$",
"parent",
"->",
"defaultDiscriminatorValue",
")",
";",
"$",
"class",
"->",
"setIdGeneratorType",
"(",
"$",
"parent",
"->",
"generatorType",
")",
";",
"$",
"this",
"->",
"addInheritedFields",
"(",
"$",
"class",
",",
"$",
"parent",
")",
";",
"$",
"this",
"->",
"addInheritedRelations",
"(",
"$",
"class",
",",
"$",
"parent",
")",
";",
"$",
"this",
"->",
"addInheritedIndexes",
"(",
"$",
"class",
",",
"$",
"parent",
")",
";",
"$",
"this",
"->",
"setInheritedShardKey",
"(",
"$",
"class",
",",
"$",
"parent",
")",
";",
"$",
"class",
"->",
"setIdentifier",
"(",
"$",
"parent",
"->",
"identifier",
")",
";",
"$",
"class",
"->",
"setVersioned",
"(",
"$",
"parent",
"->",
"isVersioned",
")",
";",
"$",
"class",
"->",
"setVersionField",
"(",
"$",
"parent",
"->",
"versionField",
")",
";",
"$",
"class",
"->",
"setLifecycleCallbacks",
"(",
"$",
"parent",
"->",
"lifecycleCallbacks",
")",
";",
"$",
"class",
"->",
"setAlsoLoadMethods",
"(",
"$",
"parent",
"->",
"alsoLoadMethods",
")",
";",
"$",
"class",
"->",
"setChangeTrackingPolicy",
"(",
"$",
"parent",
"->",
"changeTrackingPolicy",
")",
";",
"$",
"class",
"->",
"setReadPreference",
"(",
"$",
"parent",
"->",
"readPreference",
",",
"$",
"parent",
"->",
"readPreferenceTags",
")",
";",
"$",
"class",
"->",
"setWriteConcern",
"(",
"$",
"parent",
"->",
"writeConcern",
")",
";",
"if",
"(",
"$",
"parent",
"->",
"isMappedSuperclass",
")",
"{",
"$",
"class",
"->",
"setCustomRepositoryClass",
"(",
"$",
"parent",
"->",
"customRepositoryClassName",
")",
";",
"}",
"if",
"(",
"$",
"parent",
"->",
"isFile",
")",
"{",
"$",
"class",
"->",
"isFile",
"=",
"true",
";",
"$",
"class",
"->",
"setBucketName",
"(",
"$",
"parent",
"->",
"bucketName",
")",
";",
"if",
"(",
"$",
"parent",
"->",
"chunkSizeBytes",
"!==",
"null",
")",
"{",
"$",
"class",
"->",
"setChunkSizeBytes",
"(",
"$",
"parent",
"->",
"chunkSizeBytes",
")",
";",
"}",
"}",
"}",
"// Invoke driver",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"loadMetadataForClass",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
",",
"$",
"class",
")",
";",
"}",
"catch",
"(",
"ReflectionException",
"$",
"e",
")",
"{",
"throw",
"MappingException",
"::",
"reflectionFailure",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"$",
"this",
"->",
"validateIdentifier",
"(",
"$",
"class",
")",
";",
"if",
"(",
"$",
"parent",
"instanceof",
"ClassMetadata",
"&&",
"$",
"rootEntityFound",
"&&",
"$",
"parent",
"->",
"generatorType",
"===",
"$",
"class",
"->",
"generatorType",
")",
"{",
"if",
"(",
"$",
"parent",
"->",
"generatorType",
")",
"{",
"$",
"class",
"->",
"setIdGeneratorType",
"(",
"$",
"parent",
"->",
"generatorType",
")",
";",
"}",
"if",
"(",
"$",
"parent",
"->",
"generatorOptions",
")",
"{",
"$",
"class",
"->",
"setIdGeneratorOptions",
"(",
"$",
"parent",
"->",
"generatorOptions",
")",
";",
"}",
"if",
"(",
"$",
"parent",
"->",
"idGenerator",
")",
"{",
"$",
"class",
"->",
"setIdGenerator",
"(",
"$",
"parent",
"->",
"idGenerator",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"completeIdGeneratorMapping",
"(",
"$",
"class",
")",
";",
"}",
"if",
"(",
"$",
"parent",
"instanceof",
"ClassMetadata",
"&&",
"$",
"parent",
"->",
"isInheritanceTypeSingleCollection",
"(",
")",
")",
"{",
"$",
"class",
"->",
"setDatabase",
"(",
"$",
"parent",
"->",
"getDatabase",
"(",
")",
")",
";",
"$",
"class",
"->",
"setCollection",
"(",
"$",
"parent",
"->",
"getCollection",
"(",
")",
")",
";",
"}",
"$",
"class",
"->",
"setParentClasses",
"(",
"$",
"nonSuperclassParents",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"evm",
"->",
"hasListeners",
"(",
"Events",
"::",
"loadClassMetadata",
")",
")",
"{",
"return",
";",
"}",
"$",
"eventArgs",
"=",
"new",
"LoadClassMetadataEventArgs",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"dm",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"loadClassMetadata",
",",
"$",
"eventArgs",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L143-L215 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.validateIdentifier | protected function validateIdentifier(ClassMetadata $class) : void
{
if (! $class->identifier && ! $class->isMappedSuperclass && ! $class->isEmbeddedDocument && ! $class->isQueryResultDocument) {
throw MappingException::identifierRequired($class->name);
}
} | php | protected function validateIdentifier(ClassMetadata $class) : void
{
if (! $class->identifier && ! $class->isMappedSuperclass && ! $class->isEmbeddedDocument && ! $class->isQueryResultDocument) {
throw MappingException::identifierRequired($class->name);
}
} | [
"protected",
"function",
"validateIdentifier",
"(",
"ClassMetadata",
"$",
"class",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"class",
"->",
"identifier",
"&&",
"!",
"$",
"class",
"->",
"isMappedSuperclass",
"&&",
"!",
"$",
"class",
"->",
"isEmbeddedDocument",
"&&",
"!",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"MappingException",
"::",
"identifierRequired",
"(",
"$",
"class",
"->",
"name",
")",
";",
"}",
"}"
] | Validates the identifier mapping.
@throws MappingException | [
"Validates",
"the",
"identifier",
"mapping",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L222-L227 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.addInheritedFields | private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
$mapping['inherited'] = $parentClass->name;
}
if (! isset($mapping['declared'])) {
$mapping['declared'] = $parentClass->name;
}
$subClass->addInheritedFieldMapping($mapping);
}
foreach ($parentClass->reflFields as $name => $field) {
$subClass->reflFields[$name] = $field;
}
} | php | private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
$mapping['inherited'] = $parentClass->name;
}
if (! isset($mapping['declared'])) {
$mapping['declared'] = $parentClass->name;
}
$subClass->addInheritedFieldMapping($mapping);
}
foreach ($parentClass->reflFields as $name => $field) {
$subClass->reflFields[$name] = $field;
}
} | [
"private",
"function",
"addInheritedFields",
"(",
"ClassMetadata",
"$",
"subClass",
",",
"ClassMetadata",
"$",
"parentClass",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"parentClass",
"->",
"fieldMappings",
"as",
"$",
"fieldName",
"=>",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'inherited'",
"]",
")",
"&&",
"!",
"$",
"parentClass",
"->",
"isMappedSuperclass",
")",
"{",
"$",
"mapping",
"[",
"'inherited'",
"]",
"=",
"$",
"parentClass",
"->",
"name",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'declared'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'declared'",
"]",
"=",
"$",
"parentClass",
"->",
"name",
";",
"}",
"$",
"subClass",
"->",
"addInheritedFieldMapping",
"(",
"$",
"mapping",
")",
";",
"}",
"foreach",
"(",
"$",
"parentClass",
"->",
"reflFields",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"$",
"subClass",
"->",
"reflFields",
"[",
"$",
"name",
"]",
"=",
"$",
"field",
";",
"}",
"}"
] | Adds inherited fields to the subclass mapping. | [
"Adds",
"inherited",
"fields",
"to",
"the",
"subclass",
"mapping",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L309-L323 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.addInheritedRelations | private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
foreach ($parentClass->associationMappings as $field => $mapping) {
if ($parentClass->isMappedSuperclass) {
$mapping['sourceDocument'] = $subClass->name;
}
if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
$mapping['inherited'] = $parentClass->name;
}
if (! isset($mapping['declared'])) {
$mapping['declared'] = $parentClass->name;
}
$subClass->addInheritedAssociationMapping($mapping);
}
} | php | private function addInheritedRelations(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
foreach ($parentClass->associationMappings as $field => $mapping) {
if ($parentClass->isMappedSuperclass) {
$mapping['sourceDocument'] = $subClass->name;
}
if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
$mapping['inherited'] = $parentClass->name;
}
if (! isset($mapping['declared'])) {
$mapping['declared'] = $parentClass->name;
}
$subClass->addInheritedAssociationMapping($mapping);
}
} | [
"private",
"function",
"addInheritedRelations",
"(",
"ClassMetadata",
"$",
"subClass",
",",
"ClassMetadata",
"$",
"parentClass",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"parentClass",
"->",
"associationMappings",
"as",
"$",
"field",
"=>",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"parentClass",
"->",
"isMappedSuperclass",
")",
"{",
"$",
"mapping",
"[",
"'sourceDocument'",
"]",
"=",
"$",
"subClass",
"->",
"name",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'inherited'",
"]",
")",
"&&",
"!",
"$",
"parentClass",
"->",
"isMappedSuperclass",
")",
"{",
"$",
"mapping",
"[",
"'inherited'",
"]",
"=",
"$",
"parentClass",
"->",
"name",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'declared'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'declared'",
"]",
"=",
"$",
"parentClass",
"->",
"name",
";",
"}",
"$",
"subClass",
"->",
"addInheritedAssociationMapping",
"(",
"$",
"mapping",
")",
";",
"}",
"}"
] | Adds inherited association mappings to the subclass mapping.
@throws MappingException | [
"Adds",
"inherited",
"association",
"mappings",
"to",
"the",
"subclass",
"mapping",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L331-L346 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.addInheritedIndexes | private function addInheritedIndexes(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
foreach ($parentClass->indexes as $index) {
$subClass->addIndex($index['keys'], $index['options']);
}
} | php | private function addInheritedIndexes(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
foreach ($parentClass->indexes as $index) {
$subClass->addIndex($index['keys'], $index['options']);
}
} | [
"private",
"function",
"addInheritedIndexes",
"(",
"ClassMetadata",
"$",
"subClass",
",",
"ClassMetadata",
"$",
"parentClass",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"parentClass",
"->",
"indexes",
"as",
"$",
"index",
")",
"{",
"$",
"subClass",
"->",
"addIndex",
"(",
"$",
"index",
"[",
"'keys'",
"]",
",",
"$",
"index",
"[",
"'options'",
"]",
")",
";",
"}",
"}"
] | Adds inherited indexes to the subclass mapping. | [
"Adds",
"inherited",
"indexes",
"to",
"the",
"subclass",
"mapping",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L351-L356 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php | ClassMetadataFactory.setInheritedShardKey | private function setInheritedShardKey(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
if (! $parentClass->isSharded()) {
return;
}
$subClass->setShardKey(
$parentClass->shardKey['keys'],
$parentClass->shardKey['options']
);
} | php | private function setInheritedShardKey(ClassMetadata $subClass, ClassMetadata $parentClass) : void
{
if (! $parentClass->isSharded()) {
return;
}
$subClass->setShardKey(
$parentClass->shardKey['keys'],
$parentClass->shardKey['options']
);
} | [
"private",
"function",
"setInheritedShardKey",
"(",
"ClassMetadata",
"$",
"subClass",
",",
"ClassMetadata",
"$",
"parentClass",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"parentClass",
"->",
"isSharded",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"subClass",
"->",
"setShardKey",
"(",
"$",
"parentClass",
"->",
"shardKey",
"[",
"'keys'",
"]",
",",
"$",
"parentClass",
"->",
"shardKey",
"[",
"'options'",
"]",
")",
";",
"}"
] | Adds inherited shard key to the subclass mapping. | [
"Adds",
"inherited",
"shard",
"key",
"to",
"the",
"subclass",
"mapping",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php#L361-L371 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php | XmlDriver.loadMetadataForClass | public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $class)
{
assert($class instanceof ClassMetadata);
$xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() === 'document') {
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() === 'mapped-superclass') {
$class->setCustomRepositoryClass(
isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null
);
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() === 'embedded-document') {
$class->isEmbeddedDocument = true;
} elseif ($xmlRoot->getName() === 'query-result-document') {
$class->isQueryResultDocument = true;
} elseif ($xmlRoot->getName() === 'gridfs-file') {
$class->isFile = true;
if (isset($xmlRoot['chunk-size-bytes'])) {
$class->setChunkSizeBytes((int) $xmlRoot['chunk-size-bytes']);
}
}
if (isset($xmlRoot['db'])) {
$class->setDatabase((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
if (isset($xmlRoot['capped-collection'])) {
$config = ['name' => (string) $xmlRoot['collection']];
$config['capped'] = (bool) $xmlRoot['capped-collection'];
if (isset($xmlRoot['capped-collection-max'])) {
$config['max'] = (int) $xmlRoot['capped-collection-max'];
}
if (isset($xmlRoot['capped-collection-size'])) {
$config['size'] = (int) $xmlRoot['capped-collection-size'];
}
$class->setCollection($config);
} else {
$class->setCollection((string) $xmlRoot['collection']);
}
}
if (isset($xmlRoot['bucket-name'])) {
$class->setBucketName((string) $xmlRoot['bucket-name']);
}
if (isset($xmlRoot['write-concern'])) {
$class->setWriteConcern((string) $xmlRoot['write-concern']);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant(ClassMetadata::class . '::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot['change-tracking-policy'])) {
$class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField((string) $discrField['name']);
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = [];
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->{'default-discriminator-value'})) {
$class->setDefaultDiscriminatorValue((string) $xmlRoot->{'default-discriminator-value'}['value']);
}
if (isset($xmlRoot->{'indexes'})) {
foreach ($xmlRoot->{'indexes'}->{'index'} as $index) {
$this->addIndex($class, $index);
}
}
if (isset($xmlRoot->{'shard-key'})) {
$this->setShardKey($class, $xmlRoot->{'shard-key'}[0]);
}
if (isset($xmlRoot['read-only']) && (string) $xmlRoot['read-only'] === 'true') {
$class->markReadOnly();
}
if (isset($xmlRoot->{'read-preference'})) {
$class->setReadPreference(...$this->transformReadPreference($xmlRoot->{'read-preference'}));
}
if (isset($xmlRoot->id)) {
$field = $xmlRoot->id;
$mapping = [
'id' => true,
'fieldName' => 'id',
];
/** @var SimpleXMLElement $attributes */
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
}
if (isset($mapping['strategy'])) {
$mapping['options'] = [];
if (isset($field->{'generator-option'})) {
foreach ($field->{'generator-option'} as $generatorOptions) {
$attributesGenerator = iterator_to_array($generatorOptions->attributes());
if (! isset($attributesGenerator['name']) || ! isset($attributesGenerator['value'])) {
continue;
}
$mapping['options'][(string) $attributesGenerator['name']] = (string) $attributesGenerator['value'];
}
}
}
$this->addFieldMapping($class, $mapping);
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = [];
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
$booleanAttributes = ['reference', 'embed', 'unique', 'sparse'];
if (! in_array($key, $booleanAttributes)) {
continue;
}
$mapping[$key] = ($mapping[$key] === 'true');
}
if (isset($attributes['not-saved'])) {
$mapping['notSaved'] = ((string) $attributes['not-saved'] === 'true');
}
if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
}
if (isset($attributes['also-load'])) {
$mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
} elseif (isset($attributes['version'])) {
$mapping['version'] = ((string) $attributes['version'] === 'true');
} elseif (isset($attributes['lock'])) {
$mapping['lock'] = ((string) $attributes['lock'] === 'true');
}
$this->addFieldMapping($class, $mapping);
}
}
$this->addGridFSMappings($class, $xmlRoot);
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$this->addEmbedMapping($class, $embed, 'one');
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$this->addEmbedMapping($class, $embed, 'many');
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$this->addReferenceMapping($class, $reference, 'many');
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$this->addReferenceMapping($class, $reference, 'one');
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\ODM\MongoDB\Events::' . (string) $lifecycleCallback['type']));
}
}
if (! isset($xmlRoot->{'also-load-methods'})) {
return;
}
foreach ($xmlRoot->{'also-load-methods'}->{'also-load-method'} as $alsoLoadMethod) {
$class->registerAlsoLoadMethod((string) $alsoLoadMethod['method'], (string) $alsoLoadMethod['field']);
}
} | php | public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $class)
{
assert($class instanceof ClassMetadata);
$xmlRoot = $this->getElement($className);
if ($xmlRoot->getName() === 'document') {
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() === 'mapped-superclass') {
$class->setCustomRepositoryClass(
isset($xmlRoot['repository-class']) ? (string) $xmlRoot['repository-class'] : null
);
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() === 'embedded-document') {
$class->isEmbeddedDocument = true;
} elseif ($xmlRoot->getName() === 'query-result-document') {
$class->isQueryResultDocument = true;
} elseif ($xmlRoot->getName() === 'gridfs-file') {
$class->isFile = true;
if (isset($xmlRoot['chunk-size-bytes'])) {
$class->setChunkSizeBytes((int) $xmlRoot['chunk-size-bytes']);
}
}
if (isset($xmlRoot['db'])) {
$class->setDatabase((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
if (isset($xmlRoot['capped-collection'])) {
$config = ['name' => (string) $xmlRoot['collection']];
$config['capped'] = (bool) $xmlRoot['capped-collection'];
if (isset($xmlRoot['capped-collection-max'])) {
$config['max'] = (int) $xmlRoot['capped-collection-max'];
}
if (isset($xmlRoot['capped-collection-size'])) {
$config['size'] = (int) $xmlRoot['capped-collection-size'];
}
$class->setCollection($config);
} else {
$class->setCollection((string) $xmlRoot['collection']);
}
}
if (isset($xmlRoot['bucket-name'])) {
$class->setBucketName((string) $xmlRoot['bucket-name']);
}
if (isset($xmlRoot['write-concern'])) {
$class->setWriteConcern((string) $xmlRoot['write-concern']);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant(ClassMetadata::class . '::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot['change-tracking-policy'])) {
$class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . strtoupper((string) $xmlRoot['change-tracking-policy'])));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField((string) $discrField['name']);
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = [];
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->{'default-discriminator-value'})) {
$class->setDefaultDiscriminatorValue((string) $xmlRoot->{'default-discriminator-value'}['value']);
}
if (isset($xmlRoot->{'indexes'})) {
foreach ($xmlRoot->{'indexes'}->{'index'} as $index) {
$this->addIndex($class, $index);
}
}
if (isset($xmlRoot->{'shard-key'})) {
$this->setShardKey($class, $xmlRoot->{'shard-key'}[0]);
}
if (isset($xmlRoot['read-only']) && (string) $xmlRoot['read-only'] === 'true') {
$class->markReadOnly();
}
if (isset($xmlRoot->{'read-preference'})) {
$class->setReadPreference(...$this->transformReadPreference($xmlRoot->{'read-preference'}));
}
if (isset($xmlRoot->id)) {
$field = $xmlRoot->id;
$mapping = [
'id' => true,
'fieldName' => 'id',
];
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
}
if (isset($mapping['strategy'])) {
$mapping['options'] = [];
if (isset($field->{'generator-option'})) {
foreach ($field->{'generator-option'} as $generatorOptions) {
$attributesGenerator = iterator_to_array($generatorOptions->attributes());
if (! isset($attributesGenerator['name']) || ! isset($attributesGenerator['value'])) {
continue;
}
$mapping['options'][(string) $attributesGenerator['name']] = (string) $attributesGenerator['value'];
}
}
}
$this->addFieldMapping($class, $mapping);
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = [];
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
$booleanAttributes = ['reference', 'embed', 'unique', 'sparse'];
if (! in_array($key, $booleanAttributes)) {
continue;
}
$mapping[$key] = ($mapping[$key] === 'true');
}
if (isset($attributes['not-saved'])) {
$mapping['notSaved'] = ((string) $attributes['not-saved'] === 'true');
}
if (isset($attributes['field-name'])) {
$mapping['fieldName'] = (string) $attributes['field-name'];
}
if (isset($attributes['also-load'])) {
$mapping['alsoLoadFields'] = explode(',', $attributes['also-load']);
} elseif (isset($attributes['version'])) {
$mapping['version'] = ((string) $attributes['version'] === 'true');
} elseif (isset($attributes['lock'])) {
$mapping['lock'] = ((string) $attributes['lock'] === 'true');
}
$this->addFieldMapping($class, $mapping);
}
}
$this->addGridFSMappings($class, $xmlRoot);
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$this->addEmbedMapping($class, $embed, 'one');
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$this->addEmbedMapping($class, $embed, 'many');
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$this->addReferenceMapping($class, $reference, 'many');
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$this->addReferenceMapping($class, $reference, 'one');
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\ODM\MongoDB\Events::' . (string) $lifecycleCallback['type']));
}
}
if (! isset($xmlRoot->{'also-load-methods'})) {
return;
}
foreach ($xmlRoot->{'also-load-methods'}->{'also-load-method'} as $alsoLoadMethod) {
$class->registerAlsoLoadMethod((string) $alsoLoadMethod['method'], (string) $alsoLoadMethod['field']);
}
} | [
"public",
"function",
"loadMetadataForClass",
"(",
"$",
"className",
",",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Persistence",
"\\",
"Mapping",
"\\",
"ClassMetadata",
"$",
"class",
")",
"{",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"$",
"xmlRoot",
"=",
"$",
"this",
"->",
"getElement",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"xmlRoot",
"->",
"getName",
"(",
")",
"===",
"'document'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'repository-class'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setCustomRepositoryClass",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'repository-class'",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"xmlRoot",
"->",
"getName",
"(",
")",
"===",
"'mapped-superclass'",
")",
"{",
"$",
"class",
"->",
"setCustomRepositoryClass",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'repository-class'",
"]",
")",
"?",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'repository-class'",
"]",
":",
"null",
")",
";",
"$",
"class",
"->",
"isMappedSuperclass",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"xmlRoot",
"->",
"getName",
"(",
")",
"===",
"'embedded-document'",
")",
"{",
"$",
"class",
"->",
"isEmbeddedDocument",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"xmlRoot",
"->",
"getName",
"(",
")",
"===",
"'query-result-document'",
")",
"{",
"$",
"class",
"->",
"isQueryResultDocument",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"xmlRoot",
"->",
"getName",
"(",
")",
"===",
"'gridfs-file'",
")",
"{",
"$",
"class",
"->",
"isFile",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'chunk-size-bytes'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setChunkSizeBytes",
"(",
"(",
"int",
")",
"$",
"xmlRoot",
"[",
"'chunk-size-bytes'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'db'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setDatabase",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'db'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'collection'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'capped-collection'",
"]",
")",
")",
"{",
"$",
"config",
"=",
"[",
"'name'",
"=>",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'collection'",
"]",
"]",
";",
"$",
"config",
"[",
"'capped'",
"]",
"=",
"(",
"bool",
")",
"$",
"xmlRoot",
"[",
"'capped-collection'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'capped-collection-max'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'max'",
"]",
"=",
"(",
"int",
")",
"$",
"xmlRoot",
"[",
"'capped-collection-max'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'capped-collection-size'",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'size'",
"]",
"=",
"(",
"int",
")",
"$",
"xmlRoot",
"[",
"'capped-collection-size'",
"]",
";",
"}",
"$",
"class",
"->",
"setCollection",
"(",
"$",
"config",
")",
";",
"}",
"else",
"{",
"$",
"class",
"->",
"setCollection",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'collection'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'bucket-name'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setBucketName",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'bucket-name'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'write-concern'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setWriteConcern",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'write-concern'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'inheritance-type'",
"]",
")",
")",
"{",
"$",
"inheritanceType",
"=",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'inheritance-type'",
"]",
";",
"$",
"class",
"->",
"setInheritanceType",
"(",
"constant",
"(",
"ClassMetadata",
"::",
"class",
".",
"'::INHERITANCE_TYPE_'",
".",
"$",
"inheritanceType",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'change-tracking-policy'",
"]",
")",
")",
"{",
"$",
"class",
"->",
"setChangeTrackingPolicy",
"(",
"constant",
"(",
"ClassMetadata",
"::",
"class",
".",
"'::CHANGETRACKING_'",
".",
"strtoupper",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'change-tracking-policy'",
"]",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'discriminator-field'",
"}",
")",
")",
"{",
"$",
"discrField",
"=",
"$",
"xmlRoot",
"->",
"{",
"'discriminator-field'",
"}",
";",
"$",
"class",
"->",
"setDiscriminatorField",
"(",
"(",
"string",
")",
"$",
"discrField",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'discriminator-map'",
"}",
")",
")",
"{",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'discriminator-map'",
"}",
"->",
"{",
"'discriminator-mapping'",
"}",
"as",
"$",
"discrMapElement",
")",
"{",
"$",
"map",
"[",
"(",
"string",
")",
"$",
"discrMapElement",
"[",
"'value'",
"]",
"]",
"=",
"(",
"string",
")",
"$",
"discrMapElement",
"[",
"'class'",
"]",
";",
"}",
"$",
"class",
"->",
"setDiscriminatorMap",
"(",
"$",
"map",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'default-discriminator-value'",
"}",
")",
")",
"{",
"$",
"class",
"->",
"setDefaultDiscriminatorValue",
"(",
"(",
"string",
")",
"$",
"xmlRoot",
"->",
"{",
"'default-discriminator-value'",
"}",
"[",
"'value'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'indexes'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'indexes'",
"}",
"->",
"{",
"'index'",
"}",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"addIndex",
"(",
"$",
"class",
",",
"$",
"index",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'shard-key'",
"}",
")",
")",
"{",
"$",
"this",
"->",
"setShardKey",
"(",
"$",
"class",
",",
"$",
"xmlRoot",
"->",
"{",
"'shard-key'",
"}",
"[",
"0",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"[",
"'read-only'",
"]",
")",
"&&",
"(",
"string",
")",
"$",
"xmlRoot",
"[",
"'read-only'",
"]",
"===",
"'true'",
")",
"{",
"$",
"class",
"->",
"markReadOnly",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'read-preference'",
"}",
")",
")",
"{",
"$",
"class",
"->",
"setReadPreference",
"(",
"...",
"$",
"this",
"->",
"transformReadPreference",
"(",
"$",
"xmlRoot",
"->",
"{",
"'read-preference'",
"}",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"id",
")",
")",
"{",
"$",
"field",
"=",
"$",
"xmlRoot",
"->",
"id",
";",
"$",
"mapping",
"=",
"[",
"'id'",
"=>",
"true",
",",
"'fieldName'",
"=>",
"'id'",
",",
"]",
";",
"/** @var SimpleXMLElement $attributes */",
"$",
"attributes",
"=",
"$",
"field",
"->",
"attributes",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"mapping",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'options'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"field",
"->",
"{",
"'generator-option'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"field",
"->",
"{",
"'generator-option'",
"}",
"as",
"$",
"generatorOptions",
")",
"{",
"$",
"attributesGenerator",
"=",
"iterator_to_array",
"(",
"$",
"generatorOptions",
"->",
"attributes",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attributesGenerator",
"[",
"'name'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"attributesGenerator",
"[",
"'value'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"mapping",
"[",
"'options'",
"]",
"[",
"(",
"string",
")",
"$",
"attributesGenerator",
"[",
"'name'",
"]",
"]",
"=",
"(",
"string",
")",
"$",
"attributesGenerator",
"[",
"'value'",
"]",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"addFieldMapping",
"(",
"$",
"class",
",",
"$",
"mapping",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"field",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"field",
"as",
"$",
"field",
")",
"{",
"$",
"mapping",
"=",
"[",
"]",
";",
"$",
"attributes",
"=",
"$",
"field",
"->",
"attributes",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"mapping",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"booleanAttributes",
"=",
"[",
"'reference'",
",",
"'embed'",
",",
"'unique'",
",",
"'sparse'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"booleanAttributes",
")",
")",
"{",
"continue",
";",
"}",
"$",
"mapping",
"[",
"$",
"key",
"]",
"=",
"(",
"$",
"mapping",
"[",
"$",
"key",
"]",
"===",
"'true'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'not-saved'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'notSaved'",
"]",
"=",
"(",
"(",
"string",
")",
"$",
"attributes",
"[",
"'not-saved'",
"]",
"===",
"'true'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'field-name'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"=",
"(",
"string",
")",
"$",
"attributes",
"[",
"'field-name'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'also-load'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'alsoLoadFields'",
"]",
"=",
"explode",
"(",
"','",
",",
"$",
"attributes",
"[",
"'also-load'",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'version'",
"]",
"=",
"(",
"(",
"string",
")",
"$",
"attributes",
"[",
"'version'",
"]",
"===",
"'true'",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'lock'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'lock'",
"]",
"=",
"(",
"(",
"string",
")",
"$",
"attributes",
"[",
"'lock'",
"]",
"===",
"'true'",
")",
";",
"}",
"$",
"this",
"->",
"addFieldMapping",
"(",
"$",
"class",
",",
"$",
"mapping",
")",
";",
"}",
"}",
"$",
"this",
"->",
"addGridFSMappings",
"(",
"$",
"class",
",",
"$",
"xmlRoot",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'embed-one'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'embed-one'",
"}",
"as",
"$",
"embed",
")",
"{",
"$",
"this",
"->",
"addEmbedMapping",
"(",
"$",
"class",
",",
"$",
"embed",
",",
"'one'",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'embed-many'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'embed-many'",
"}",
"as",
"$",
"embed",
")",
"{",
"$",
"this",
"->",
"addEmbedMapping",
"(",
"$",
"class",
",",
"$",
"embed",
",",
"'many'",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'reference-many'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'reference-many'",
"}",
"as",
"$",
"reference",
")",
"{",
"$",
"this",
"->",
"addReferenceMapping",
"(",
"$",
"class",
",",
"$",
"reference",
",",
"'many'",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'reference-one'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'reference-one'",
"}",
"as",
"$",
"reference",
")",
"{",
"$",
"this",
"->",
"addReferenceMapping",
"(",
"$",
"class",
",",
"$",
"reference",
",",
"'one'",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'lifecycle-callbacks'",
"}",
")",
")",
"{",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'lifecycle-callbacks'",
"}",
"->",
"{",
"'lifecycle-callback'",
"}",
"as",
"$",
"lifecycleCallback",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"(",
"string",
")",
"$",
"lifecycleCallback",
"[",
"'method'",
"]",
",",
"constant",
"(",
"'Doctrine\\ODM\\MongoDB\\Events::'",
".",
"(",
"string",
")",
"$",
"lifecycleCallback",
"[",
"'type'",
"]",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"xmlRoot",
"->",
"{",
"'also-load-methods'",
"}",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"xmlRoot",
"->",
"{",
"'also-load-methods'",
"}",
"->",
"{",
"'also-load-method'",
"}",
"as",
"$",
"alsoLoadMethod",
")",
"{",
"$",
"class",
"->",
"registerAlsoLoadMethod",
"(",
"(",
"string",
")",
"$",
"alsoLoadMethod",
"[",
"'method'",
"]",
",",
"(",
"string",
")",
"$",
"alsoLoadMethod",
"[",
"'field'",
"]",
")",
";",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php#L79-L264 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php | XmlDriver.transformReadPreference | private function transformReadPreference(SimpleXMLElement $xmlReadPreference) : array
{
$tags = null;
if (isset($xmlReadPreference->{'tag-set'})) {
$tags = [];
foreach ($xmlReadPreference->{'tag-set'} as $tagSet) {
$set = [];
foreach ($tagSet->tag as $tag) {
$set[(string) $tag['name']] = (string) $tag['value'];
}
$tags[] = $set;
}
}
return [(string) $xmlReadPreference['mode'], $tags];
} | php | private function transformReadPreference(SimpleXMLElement $xmlReadPreference) : array
{
$tags = null;
if (isset($xmlReadPreference->{'tag-set'})) {
$tags = [];
foreach ($xmlReadPreference->{'tag-set'} as $tagSet) {
$set = [];
foreach ($tagSet->tag as $tag) {
$set[(string) $tag['name']] = (string) $tag['value'];
}
$tags[] = $set;
}
}
return [(string) $xmlReadPreference['mode'], $tags];
} | [
"private",
"function",
"transformReadPreference",
"(",
"SimpleXMLElement",
"$",
"xmlReadPreference",
")",
":",
"array",
"{",
"$",
"tags",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"xmlReadPreference",
"->",
"{",
"'tag-set'",
"}",
")",
")",
"{",
"$",
"tags",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"xmlReadPreference",
"->",
"{",
"'tag-set'",
"}",
"as",
"$",
"tagSet",
")",
"{",
"$",
"set",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tagSet",
"->",
"tag",
"as",
"$",
"tag",
")",
"{",
"$",
"set",
"[",
"(",
"string",
")",
"$",
"tag",
"[",
"'name'",
"]",
"]",
"=",
"(",
"string",
")",
"$",
"tag",
"[",
"'value'",
"]",
";",
"}",
"$",
"tags",
"[",
"]",
"=",
"$",
"set",
";",
"}",
"}",
"return",
"[",
"(",
"string",
")",
"$",
"xmlReadPreference",
"[",
"'mode'",
"]",
",",
"$",
"tags",
"]",
";",
"}"
] | Parses <read-preference> to a format suitable for the underlying driver.
list($readPreference, $tags) = $this->transformReadPreference($xml->{read-preference}); | [
"Parses",
"<read",
"-",
"preference",
">",
"to",
"a",
"format",
"suitable",
"for",
"the",
"underlying",
"driver",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php#L551-L565 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php | XmlDriver.loadMappingFile | protected function loadMappingFile($file) : array
{
$result = [];
$this->validateSchema($file);
$xmlElement = simplexml_load_file($file);
foreach (['document', 'embedded-document', 'mapped-superclass', 'query-result-document', 'gridfs-file'] as $type) {
if (! isset($xmlElement->$type)) {
continue;
}
foreach ($xmlElement->$type as $documentElement) {
$documentName = (string) $documentElement['name'];
$result[$documentName] = $documentElement;
}
}
return $result;
} | php | protected function loadMappingFile($file) : array
{
$result = [];
$this->validateSchema($file);
$xmlElement = simplexml_load_file($file);
foreach (['document', 'embedded-document', 'mapped-superclass', 'query-result-document', 'gridfs-file'] as $type) {
if (! isset($xmlElement->$type)) {
continue;
}
foreach ($xmlElement->$type as $documentElement) {
$documentName = (string) $documentElement['name'];
$result[$documentName] = $documentElement;
}
}
return $result;
} | [
"protected",
"function",
"loadMappingFile",
"(",
"$",
"file",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"validateSchema",
"(",
"$",
"file",
")",
";",
"$",
"xmlElement",
"=",
"simplexml_load_file",
"(",
"$",
"file",
")",
";",
"foreach",
"(",
"[",
"'document'",
",",
"'embedded-document'",
",",
"'mapped-superclass'",
",",
"'query-result-document'",
",",
"'gridfs-file'",
"]",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"xmlElement",
"->",
"$",
"type",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"xmlElement",
"->",
"$",
"type",
"as",
"$",
"documentElement",
")",
"{",
"$",
"documentName",
"=",
"(",
"string",
")",
"$",
"documentElement",
"[",
"'name'",
"]",
";",
"$",
"result",
"[",
"$",
"documentName",
"]",
"=",
"$",
"documentElement",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php#L570-L590 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php | ReplaceRoot.getExpression | public function getExpression() : array
{
return [
'$replaceRoot' => $this->expression !== null ? $this->convertExpression($this->expression) : $this->expr->getExpression(),
];
} | php | public function getExpression() : array
{
return [
'$replaceRoot' => $this->expression !== null ? $this->convertExpression($this->expression) : $this->expr->getExpression(),
];
} | [
"public",
"function",
"getExpression",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'$replaceRoot'",
"=>",
"$",
"this",
"->",
"expression",
"!==",
"null",
"?",
"$",
"this",
"->",
"convertExpression",
"(",
"$",
"this",
"->",
"expression",
")",
":",
"$",
"this",
"->",
"expr",
"->",
"getExpression",
"(",
")",
",",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php#L41-L46 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php | BucketAuto.output | public function output() : Bucket\BucketAutoOutput
{
if (! $this->output) {
$this->output = new Bucket\BucketAutoOutput($this->builder, $this);
}
assert($this->output instanceof Bucket\BucketAutoOutput);
return $this->output;
} | php | public function output() : Bucket\BucketAutoOutput
{
if (! $this->output) {
$this->output = new Bucket\BucketAutoOutput($this->builder, $this);
}
assert($this->output instanceof Bucket\BucketAutoOutput);
return $this->output;
} | [
"public",
"function",
"output",
"(",
")",
":",
"Bucket",
"\\",
"BucketAutoOutput",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"output",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"new",
"Bucket",
"\\",
"BucketAutoOutput",
"(",
"$",
"this",
"->",
"builder",
",",
"$",
"this",
")",
";",
"}",
"assert",
"(",
"$",
"this",
"->",
"output",
"instanceof",
"Bucket",
"\\",
"BucketAutoOutput",
")",
";",
"return",
"$",
"this",
"->",
"output",
";",
"}"
] | A document that specifies the fields to include in the output documents
in addition to the _id field. To specify the field to include, you must
use accumulator expressions. | [
"A",
"document",
"that",
"specifies",
"the",
"fields",
"to",
"include",
"in",
"the",
"output",
"documents",
"in",
"addition",
"to",
"the",
"_id",
"field",
".",
"To",
"specify",
"the",
"field",
"to",
"include",
"you",
"must",
"use",
"accumulator",
"expressions",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php#L46-L54 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.delete | public function delete(object $parent, array $collections, array $options) : void
{
$unsetPathsMap = [];
foreach ($collections as $collection) {
$mapping = $collection->getMapping();
if ($mapping['isInverseSide']) {
continue; // ignore inverse side
}
if (CollectionHelper::isAtomic($mapping['strategy'])) {
throw new UnexpectedValueException($mapping['strategy'] . ' delete collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker');
}
[$propertyPath] = $this->getPathAndParent($collection);
$unsetPathsMap[$propertyPath] = true;
}
if (empty($unsetPathsMap)) {
return;
}
/** @var string[] $unsetPaths */
$unsetPaths = array_keys($unsetPathsMap);
$unsetPaths = array_fill_keys($this->excludeSubPaths($unsetPaths), true);
$query = ['$unset' => $unsetPaths];
$this->executeQuery($parent, $query, $options);
} | php | public function delete(object $parent, array $collections, array $options) : void
{
$unsetPathsMap = [];
foreach ($collections as $collection) {
$mapping = $collection->getMapping();
if ($mapping['isInverseSide']) {
continue;
}
if (CollectionHelper::isAtomic($mapping['strategy'])) {
throw new UnexpectedValueException($mapping['strategy'] . ' delete collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker');
}
[$propertyPath] = $this->getPathAndParent($collection);
$unsetPathsMap[$propertyPath] = true;
}
if (empty($unsetPathsMap)) {
return;
}
$unsetPaths = array_keys($unsetPathsMap);
$unsetPaths = array_fill_keys($this->excludeSubPaths($unsetPaths), true);
$query = ['$unset' => $unsetPaths];
$this->executeQuery($parent, $query, $options);
} | [
"public",
"function",
"delete",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collections",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"unsetPathsMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"collection",
")",
"{",
"$",
"mapping",
"=",
"$",
"collection",
"->",
"getMapping",
"(",
")",
";",
"if",
"(",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
")",
"{",
"continue",
";",
"// ignore inverse side",
"}",
"if",
"(",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
".",
"' delete collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker'",
")",
";",
"}",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"this",
"->",
"getPathAndParent",
"(",
"$",
"collection",
")",
";",
"$",
"unsetPathsMap",
"[",
"$",
"propertyPath",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"unsetPathsMap",
")",
")",
"{",
"return",
";",
"}",
"/** @var string[] $unsetPaths */",
"$",
"unsetPaths",
"=",
"array_keys",
"(",
"$",
"unsetPathsMap",
")",
";",
"$",
"unsetPaths",
"=",
"array_fill_keys",
"(",
"$",
"this",
"->",
"excludeSubPaths",
"(",
"$",
"unsetPaths",
")",
",",
"true",
")",
";",
"$",
"query",
"=",
"[",
"'$unset'",
"=>",
"$",
"unsetPaths",
"]",
";",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"$",
"query",
",",
"$",
"options",
")",
";",
"}"
] | Deletes a PersistentCollection instances completely from a document using $unset.
@param PersistentCollectionInterface[] $collections
@param array $options | [
"Deletes",
"a",
"PersistentCollection",
"instances",
"completely",
"from",
"a",
"document",
"using",
"$unset",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L68-L94 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.update | public function update(object $parent, array $collections, array $options) : void
{
$setStrategyColls = [];
$addPushStrategyColls = [];
foreach ($collections as $coll) {
$mapping = $coll->getMapping();
if ($mapping['isInverseSide']) {
continue; // ignore inverse side
}
switch ($mapping['strategy']) {
case ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET:
case ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY:
throw new UnexpectedValueException($mapping['strategy'] . ' update collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker');
case ClassMetadata::STORAGE_STRATEGY_SET:
case ClassMetadata::STORAGE_STRATEGY_SET_ARRAY:
$setStrategyColls[] = $coll;
break;
case ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET:
case ClassMetadata::STORAGE_STRATEGY_PUSH_ALL:
$addPushStrategyColls[] = $coll;
break;
default:
throw new UnexpectedValueException('Unsupported collection strategy: ' . $mapping['strategy']);
}
}
if (! empty($setStrategyColls)) {
$this->setCollections($parent, $setStrategyColls, $options);
}
if (empty($addPushStrategyColls)) {
return;
}
$this->deleteElements($parent, $addPushStrategyColls, $options);
$this->insertElements($parent, $addPushStrategyColls, $options);
} | php | public function update(object $parent, array $collections, array $options) : void
{
$setStrategyColls = [];
$addPushStrategyColls = [];
foreach ($collections as $coll) {
$mapping = $coll->getMapping();
if ($mapping['isInverseSide']) {
continue;
}
switch ($mapping['strategy']) {
case ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET:
case ClassMetadata::STORAGE_STRATEGY_ATOMIC_SET_ARRAY:
throw new UnexpectedValueException($mapping['strategy'] . ' update collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker');
case ClassMetadata::STORAGE_STRATEGY_SET:
case ClassMetadata::STORAGE_STRATEGY_SET_ARRAY:
$setStrategyColls[] = $coll;
break;
case ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET:
case ClassMetadata::STORAGE_STRATEGY_PUSH_ALL:
$addPushStrategyColls[] = $coll;
break;
default:
throw new UnexpectedValueException('Unsupported collection strategy: ' . $mapping['strategy']);
}
}
if (! empty($setStrategyColls)) {
$this->setCollections($parent, $setStrategyColls, $options);
}
if (empty($addPushStrategyColls)) {
return;
}
$this->deleteElements($parent, $addPushStrategyColls, $options);
$this->insertElements($parent, $addPushStrategyColls, $options);
} | [
"public",
"function",
"update",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collections",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"setStrategyColls",
"=",
"[",
"]",
";",
"$",
"addPushStrategyColls",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"coll",
")",
"{",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"if",
"(",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
")",
"{",
"continue",
";",
"// ignore inverse side",
"}",
"switch",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"{",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_ATOMIC_SET",
":",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_ATOMIC_SET_ARRAY",
":",
"throw",
"new",
"UnexpectedValueException",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
".",
"' update collection strategy should have been handled by DocumentPersister. Please report a bug in issue tracker'",
")",
";",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_SET",
":",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_SET_ARRAY",
":",
"$",
"setStrategyColls",
"[",
"]",
"=",
"$",
"coll",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_ADD_TO_SET",
":",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_PUSH_ALL",
":",
"$",
"addPushStrategyColls",
"[",
"]",
"=",
"$",
"coll",
";",
"break",
";",
"default",
":",
"throw",
"new",
"UnexpectedValueException",
"(",
"'Unsupported collection strategy: '",
".",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"setStrategyColls",
")",
")",
"{",
"$",
"this",
"->",
"setCollections",
"(",
"$",
"parent",
",",
"$",
"setStrategyColls",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"addPushStrategyColls",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"deleteElements",
"(",
"$",
"parent",
",",
"$",
"addPushStrategyColls",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"insertElements",
"(",
"$",
"parent",
",",
"$",
"addPushStrategyColls",
",",
"$",
"options",
")",
";",
"}"
] | Updates a list PersistentCollection instances deleting removed rows and inserting new rows.
@param PersistentCollectionInterface[] $collections
@param array $options | [
"Updates",
"a",
"list",
"PersistentCollection",
"instances",
"deleting",
"removed",
"rows",
"and",
"inserting",
"new",
"rows",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L102-L142 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.setCollections | private function setCollections(object $parent, array $collections, array $options) : void
{
$pathCollMap = [];
$paths = [];
foreach ($collections as $coll) {
[$propertyPath ] = $this->getPathAndParent($coll);
$pathCollMap[$propertyPath] = $coll;
$paths[] = $propertyPath;
}
$paths = $this->excludeSubPaths($paths);
/** @var PersistentCollectionInterface[] $setColls */
$setColls = array_intersect_key($pathCollMap, array_flip($paths));
$setPayload = [];
foreach ($setColls as $propertyPath => $coll) {
$coll->initialize();
$mapping = $coll->getMapping();
$setData = $this->pb->prepareAssociatedCollectionValue(
$coll,
CollectionHelper::usesSet($mapping['strategy'])
);
$setPayload[$propertyPath] = $setData;
}
if (empty($setPayload)) {
return;
}
$query = ['$set' => $setPayload];
$this->executeQuery($parent, $query, $options);
} | php | private function setCollections(object $parent, array $collections, array $options) : void
{
$pathCollMap = [];
$paths = [];
foreach ($collections as $coll) {
[$propertyPath ] = $this->getPathAndParent($coll);
$pathCollMap[$propertyPath] = $coll;
$paths[] = $propertyPath;
}
$paths = $this->excludeSubPaths($paths);
$setColls = array_intersect_key($pathCollMap, array_flip($paths));
$setPayload = [];
foreach ($setColls as $propertyPath => $coll) {
$coll->initialize();
$mapping = $coll->getMapping();
$setData = $this->pb->prepareAssociatedCollectionValue(
$coll,
CollectionHelper::usesSet($mapping['strategy'])
);
$setPayload[$propertyPath] = $setData;
}
if (empty($setPayload)) {
return;
}
$query = ['$set' => $setPayload];
$this->executeQuery($parent, $query, $options);
} | [
"private",
"function",
"setCollections",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collections",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"pathCollMap",
"=",
"[",
"]",
";",
"$",
"paths",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"coll",
")",
"{",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"this",
"->",
"getPathAndParent",
"(",
"$",
"coll",
")",
";",
"$",
"pathCollMap",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"coll",
";",
"$",
"paths",
"[",
"]",
"=",
"$",
"propertyPath",
";",
"}",
"$",
"paths",
"=",
"$",
"this",
"->",
"excludeSubPaths",
"(",
"$",
"paths",
")",
";",
"/** @var PersistentCollectionInterface[] $setColls */",
"$",
"setColls",
"=",
"array_intersect_key",
"(",
"$",
"pathCollMap",
",",
"array_flip",
"(",
"$",
"paths",
")",
")",
";",
"$",
"setPayload",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"setColls",
"as",
"$",
"propertyPath",
"=>",
"$",
"coll",
")",
"{",
"$",
"coll",
"->",
"initialize",
"(",
")",
";",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"$",
"setData",
"=",
"$",
"this",
"->",
"pb",
"->",
"prepareAssociatedCollectionValue",
"(",
"$",
"coll",
",",
"CollectionHelper",
"::",
"usesSet",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
";",
"$",
"setPayload",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"setData",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"setPayload",
")",
")",
"{",
"return",
";",
"}",
"$",
"query",
"=",
"[",
"'$set'",
"=>",
"$",
"setPayload",
"]",
";",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"$",
"query",
",",
"$",
"options",
")",
";",
"}"
] | Sets a list of PersistentCollection instances.
This method is intended to be used with the "set" or "setArray"
strategies. The "setArray" strategy will ensure that the collections is
set as a BSON array, which means the collections elements will be
reindexed numerically before storage.
@param PersistentCollectionInterface[] $collections
@param array $options | [
"Sets",
"a",
"list",
"of",
"PersistentCollection",
"instances",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L155-L184 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.deleteElements | private function deleteElements(object $parent, array $collections, array $options) : void
{
$pathCollMap = [];
$paths = [];
$deleteDiffMap = [];
foreach ($collections as $coll) {
$coll->initialize();
if (! $this->uow->isCollectionScheduledForUpdate($coll)) {
continue;
}
$deleteDiff = $coll->getDeleteDiff();
if (empty($deleteDiff)) {
continue;
}
[$propertyPath ] = $this->getPathAndParent($coll);
$pathCollMap[$propertyPath] = $coll;
$paths[] = $propertyPath;
$deleteDiffMap[$propertyPath] = $deleteDiff;
}
$paths = $this->excludeSubPaths($paths);
$deleteColls = array_intersect_key($pathCollMap, array_flip($paths));
$unsetPayload = [];
$pullPayload = [];
foreach ($deleteColls as $propertyPath => $coll) {
$deleteDiff = $deleteDiffMap[$propertyPath];
foreach ($deleteDiff as $key => $document) {
$unsetPayload[$propertyPath . '.' . $key] = true;
}
$pullPayload[$propertyPath] = null;
}
if (! empty($unsetPayload)) {
$this->executeQuery($parent, ['$unset' => $unsetPayload], $options);
}
if (empty($pullPayload)) {
return;
}
/**
* @todo This is a hack right now because we don't have a proper way to
* remove an element from an array by its key. Unsetting the key results
* in the element being left in the array as null so we have to pull
* null values.
*/
$this->executeQuery($parent, ['$pull' => $pullPayload], $options);
} | php | private function deleteElements(object $parent, array $collections, array $options) : void
{
$pathCollMap = [];
$paths = [];
$deleteDiffMap = [];
foreach ($collections as $coll) {
$coll->initialize();
if (! $this->uow->isCollectionScheduledForUpdate($coll)) {
continue;
}
$deleteDiff = $coll->getDeleteDiff();
if (empty($deleteDiff)) {
continue;
}
[$propertyPath ] = $this->getPathAndParent($coll);
$pathCollMap[$propertyPath] = $coll;
$paths[] = $propertyPath;
$deleteDiffMap[$propertyPath] = $deleteDiff;
}
$paths = $this->excludeSubPaths($paths);
$deleteColls = array_intersect_key($pathCollMap, array_flip($paths));
$unsetPayload = [];
$pullPayload = [];
foreach ($deleteColls as $propertyPath => $coll) {
$deleteDiff = $deleteDiffMap[$propertyPath];
foreach ($deleteDiff as $key => $document) {
$unsetPayload[$propertyPath . '.' . $key] = true;
}
$pullPayload[$propertyPath] = null;
}
if (! empty($unsetPayload)) {
$this->executeQuery($parent, ['$unset' => $unsetPayload], $options);
}
if (empty($pullPayload)) {
return;
}
$this->executeQuery($parent, ['$pull' => $pullPayload], $options);
} | [
"private",
"function",
"deleteElements",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collections",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"pathCollMap",
"=",
"[",
"]",
";",
"$",
"paths",
"=",
"[",
"]",
";",
"$",
"deleteDiffMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"coll",
")",
"{",
"$",
"coll",
"->",
"initialize",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForUpdate",
"(",
"$",
"coll",
")",
")",
"{",
"continue",
";",
"}",
"$",
"deleteDiff",
"=",
"$",
"coll",
"->",
"getDeleteDiff",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"deleteDiff",
")",
")",
"{",
"continue",
";",
"}",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"this",
"->",
"getPathAndParent",
"(",
"$",
"coll",
")",
";",
"$",
"pathCollMap",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"coll",
";",
"$",
"paths",
"[",
"]",
"=",
"$",
"propertyPath",
";",
"$",
"deleteDiffMap",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"deleteDiff",
";",
"}",
"$",
"paths",
"=",
"$",
"this",
"->",
"excludeSubPaths",
"(",
"$",
"paths",
")",
";",
"$",
"deleteColls",
"=",
"array_intersect_key",
"(",
"$",
"pathCollMap",
",",
"array_flip",
"(",
"$",
"paths",
")",
")",
";",
"$",
"unsetPayload",
"=",
"[",
"]",
";",
"$",
"pullPayload",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"deleteColls",
"as",
"$",
"propertyPath",
"=>",
"$",
"coll",
")",
"{",
"$",
"deleteDiff",
"=",
"$",
"deleteDiffMap",
"[",
"$",
"propertyPath",
"]",
";",
"foreach",
"(",
"$",
"deleteDiff",
"as",
"$",
"key",
"=>",
"$",
"document",
")",
"{",
"$",
"unsetPayload",
"[",
"$",
"propertyPath",
".",
"'.'",
".",
"$",
"key",
"]",
"=",
"true",
";",
"}",
"$",
"pullPayload",
"[",
"$",
"propertyPath",
"]",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"unsetPayload",
")",
")",
"{",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"[",
"'$unset'",
"=>",
"$",
"unsetPayload",
"]",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"pullPayload",
")",
")",
"{",
"return",
";",
"}",
"/**\n * @todo This is a hack right now because we don't have a proper way to\n * remove an element from an array by its key. Unsetting the key results\n * in the element being left in the array as null so we have to pull\n * null values.\n */",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"[",
"'$pull'",
"=>",
"$",
"pullPayload",
"]",
",",
"$",
"options",
")",
";",
"}"
] | Deletes removed elements from a list of PersistentCollection instances.
This method is intended to be used with the "pushAll" and "addToSet" strategies.
@param PersistentCollectionInterface[] $collections
@param array $options | [
"Deletes",
"removed",
"elements",
"from",
"a",
"list",
"of",
"PersistentCollection",
"instances",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L194-L243 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.insertElements | private function insertElements(object $parent, array $collections, array $options) : void
{
$pushAllPathCollMap = [];
$addToSetPathCollMap = [];
$pushAllPaths = [];
$addToSetPaths = [];
$diffsMap = [];
foreach ($collections as $coll) {
$coll->initialize();
if (! $this->uow->isCollectionScheduledForUpdate($coll)) {
continue;
}
$insertDiff = $coll->getInsertDiff();
if (empty($insertDiff)) {
continue;
}
$mapping = $coll->getMapping();
$strategy = $mapping['strategy'];
[$propertyPath ] = $this->getPathAndParent($coll);
$diffsMap[$propertyPath] = $insertDiff;
switch ($strategy) {
case ClassMetadata::STORAGE_STRATEGY_PUSH_ALL:
$pushAllPathCollMap[$propertyPath] = $coll;
$pushAllPaths[] = $propertyPath;
break;
case ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET:
$addToSetPathCollMap[$propertyPath] = $coll;
$addToSetPaths[] = $propertyPath;
break;
default:
throw new LogicException('Invalid strategy ' . $strategy . ' given for insertCollections');
}
}
if (! empty($pushAllPaths)) {
$this->pushAllCollections(
$parent,
$pushAllPaths,
$pushAllPathCollMap,
$diffsMap,
$options
);
}
if (empty($addToSetPaths)) {
return;
}
$this->addToSetCollections(
$parent,
$addToSetPaths,
$addToSetPathCollMap,
$diffsMap,
$options
);
} | php | private function insertElements(object $parent, array $collections, array $options) : void
{
$pushAllPathCollMap = [];
$addToSetPathCollMap = [];
$pushAllPaths = [];
$addToSetPaths = [];
$diffsMap = [];
foreach ($collections as $coll) {
$coll->initialize();
if (! $this->uow->isCollectionScheduledForUpdate($coll)) {
continue;
}
$insertDiff = $coll->getInsertDiff();
if (empty($insertDiff)) {
continue;
}
$mapping = $coll->getMapping();
$strategy = $mapping['strategy'];
[$propertyPath ] = $this->getPathAndParent($coll);
$diffsMap[$propertyPath] = $insertDiff;
switch ($strategy) {
case ClassMetadata::STORAGE_STRATEGY_PUSH_ALL:
$pushAllPathCollMap[$propertyPath] = $coll;
$pushAllPaths[] = $propertyPath;
break;
case ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET:
$addToSetPathCollMap[$propertyPath] = $coll;
$addToSetPaths[] = $propertyPath;
break;
default:
throw new LogicException('Invalid strategy ' . $strategy . ' given for insertCollections');
}
}
if (! empty($pushAllPaths)) {
$this->pushAllCollections(
$parent,
$pushAllPaths,
$pushAllPathCollMap,
$diffsMap,
$options
);
}
if (empty($addToSetPaths)) {
return;
}
$this->addToSetCollections(
$parent,
$addToSetPaths,
$addToSetPathCollMap,
$diffsMap,
$options
);
} | [
"private",
"function",
"insertElements",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collections",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"pushAllPathCollMap",
"=",
"[",
"]",
";",
"$",
"addToSetPathCollMap",
"=",
"[",
"]",
";",
"$",
"pushAllPaths",
"=",
"[",
"]",
";",
"$",
"addToSetPaths",
"=",
"[",
"]",
";",
"$",
"diffsMap",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"coll",
")",
"{",
"$",
"coll",
"->",
"initialize",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"uow",
"->",
"isCollectionScheduledForUpdate",
"(",
"$",
"coll",
")",
")",
"{",
"continue",
";",
"}",
"$",
"insertDiff",
"=",
"$",
"coll",
"->",
"getInsertDiff",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"insertDiff",
")",
")",
"{",
"continue",
";",
"}",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"$",
"strategy",
"=",
"$",
"mapping",
"[",
"'strategy'",
"]",
";",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"this",
"->",
"getPathAndParent",
"(",
"$",
"coll",
")",
";",
"$",
"diffsMap",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"insertDiff",
";",
"switch",
"(",
"$",
"strategy",
")",
"{",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_PUSH_ALL",
":",
"$",
"pushAllPathCollMap",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"coll",
";",
"$",
"pushAllPaths",
"[",
"]",
"=",
"$",
"propertyPath",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"STORAGE_STRATEGY_ADD_TO_SET",
":",
"$",
"addToSetPathCollMap",
"[",
"$",
"propertyPath",
"]",
"=",
"$",
"coll",
";",
"$",
"addToSetPaths",
"[",
"]",
"=",
"$",
"propertyPath",
";",
"break",
";",
"default",
":",
"throw",
"new",
"LogicException",
"(",
"'Invalid strategy '",
".",
"$",
"strategy",
".",
"' given for insertCollections'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"pushAllPaths",
")",
")",
"{",
"$",
"this",
"->",
"pushAllCollections",
"(",
"$",
"parent",
",",
"$",
"pushAllPaths",
",",
"$",
"pushAllPathCollMap",
",",
"$",
"diffsMap",
",",
"$",
"options",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"addToSetPaths",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"addToSetCollections",
"(",
"$",
"parent",
",",
"$",
"addToSetPaths",
",",
"$",
"addToSetPathCollMap",
",",
"$",
"diffsMap",
",",
"$",
"options",
")",
";",
"}"
] | Inserts new elements for a PersistentCollection instances.
This method is intended to be used with the "pushAll" and "addToSet" strategies.
@param PersistentCollectionInterface[] $collections
@param array $options | [
"Inserts",
"new",
"elements",
"for",
"a",
"PersistentCollection",
"instances",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L253-L314 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.pushAllCollections | private function pushAllCollections(object $parent, array $collsPaths, array $pathCollsMap, array $diffsMap, array $options) : void
{
$pushAllPaths = $this->excludeSubPaths($collsPaths);
/** @var PersistentCollectionInterface[] $pushAllColls */
$pushAllColls = array_intersect_key($pathCollsMap, array_flip($pushAllPaths));
$pushAllPayload = [];
foreach ($pushAllColls as $propertyPath => $coll) {
$callback = $this->getValuePrepareCallback($coll);
$value = array_values(array_map($callback, $diffsMap[$propertyPath]));
$pushAllPayload[$propertyPath] = ['$each' => $value];
}
if (! empty($pushAllPayload)) {
$this->executeQuery($parent, ['$push' => $pushAllPayload], $options);
}
$pushAllColls = array_diff_key($pathCollsMap, array_flip($pushAllPaths));
foreach ($pushAllColls as $propertyPath => $coll) {
$callback = $this->getValuePrepareCallback($coll);
$value = array_values(array_map($callback, $diffsMap[$propertyPath]));
$query = ['$push' => [$propertyPath => ['$each' => $value]]];
$this->executeQuery($parent, $query, $options);
}
} | php | private function pushAllCollections(object $parent, array $collsPaths, array $pathCollsMap, array $diffsMap, array $options) : void
{
$pushAllPaths = $this->excludeSubPaths($collsPaths);
$pushAllColls = array_intersect_key($pathCollsMap, array_flip($pushAllPaths));
$pushAllPayload = [];
foreach ($pushAllColls as $propertyPath => $coll) {
$callback = $this->getValuePrepareCallback($coll);
$value = array_values(array_map($callback, $diffsMap[$propertyPath]));
$pushAllPayload[$propertyPath] = ['$each' => $value];
}
if (! empty($pushAllPayload)) {
$this->executeQuery($parent, ['$push' => $pushAllPayload], $options);
}
$pushAllColls = array_diff_key($pathCollsMap, array_flip($pushAllPaths));
foreach ($pushAllColls as $propertyPath => $coll) {
$callback = $this->getValuePrepareCallback($coll);
$value = array_values(array_map($callback, $diffsMap[$propertyPath]));
$query = ['$push' => [$propertyPath => ['$each' => $value]]];
$this->executeQuery($parent, $query, $options);
}
} | [
"private",
"function",
"pushAllCollections",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collsPaths",
",",
"array",
"$",
"pathCollsMap",
",",
"array",
"$",
"diffsMap",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"pushAllPaths",
"=",
"$",
"this",
"->",
"excludeSubPaths",
"(",
"$",
"collsPaths",
")",
";",
"/** @var PersistentCollectionInterface[] $pushAllColls */",
"$",
"pushAllColls",
"=",
"array_intersect_key",
"(",
"$",
"pathCollsMap",
",",
"array_flip",
"(",
"$",
"pushAllPaths",
")",
")",
";",
"$",
"pushAllPayload",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"pushAllColls",
"as",
"$",
"propertyPath",
"=>",
"$",
"coll",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"getValuePrepareCallback",
"(",
"$",
"coll",
")",
";",
"$",
"value",
"=",
"array_values",
"(",
"array_map",
"(",
"$",
"callback",
",",
"$",
"diffsMap",
"[",
"$",
"propertyPath",
"]",
")",
")",
";",
"$",
"pushAllPayload",
"[",
"$",
"propertyPath",
"]",
"=",
"[",
"'$each'",
"=>",
"$",
"value",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"pushAllPayload",
")",
")",
"{",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"[",
"'$push'",
"=>",
"$",
"pushAllPayload",
"]",
",",
"$",
"options",
")",
";",
"}",
"$",
"pushAllColls",
"=",
"array_diff_key",
"(",
"$",
"pathCollsMap",
",",
"array_flip",
"(",
"$",
"pushAllPaths",
")",
")",
";",
"foreach",
"(",
"$",
"pushAllColls",
"as",
"$",
"propertyPath",
"=>",
"$",
"coll",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"getValuePrepareCallback",
"(",
"$",
"coll",
")",
";",
"$",
"value",
"=",
"array_values",
"(",
"array_map",
"(",
"$",
"callback",
",",
"$",
"diffsMap",
"[",
"$",
"propertyPath",
"]",
")",
")",
";",
"$",
"query",
"=",
"[",
"'$push'",
"=>",
"[",
"$",
"propertyPath",
"=>",
"[",
"'$each'",
"=>",
"$",
"value",
"]",
"]",
"]",
";",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"$",
"query",
",",
"$",
"options",
")",
";",
"}",
"}"
] | Perform collections update for 'pushAll' strategy.
@param object $parent Parent object to which passed collections is belong.
@param array $collsPaths Paths of collections that is passed.
@param array $pathCollsMap List of collections indexed by their paths.
@param array $diffsMap List of collection diffs indexed by collections paths.
@param array $options | [
"Perform",
"collections",
"update",
"for",
"pushAll",
"strategy",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L325-L348 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.addToSetCollections | private function addToSetCollections(object $parent, array $collsPaths, array $pathCollsMap, array $diffsMap, array $options) : void
{
$addToSetPaths = $this->excludeSubPaths($collsPaths);
/** @var PersistentCollectionInterface[] $addToSetColls */
$addToSetColls = array_intersect_key($pathCollsMap, array_flip($addToSetPaths));
$addToSetPayload = [];
foreach ($addToSetColls as $propertyPath => $coll) {
$callback = $this->getValuePrepareCallback($coll);
$value = array_values(array_map($callback, $diffsMap[$propertyPath]));
$addToSetPayload[$propertyPath] = ['$each' => $value];
}
if (empty($addToSetPayload)) {
return;
}
$this->executeQuery($parent, ['$addToSet' => $addToSetPayload], $options);
} | php | private function addToSetCollections(object $parent, array $collsPaths, array $pathCollsMap, array $diffsMap, array $options) : void
{
$addToSetPaths = $this->excludeSubPaths($collsPaths);
$addToSetColls = array_intersect_key($pathCollsMap, array_flip($addToSetPaths));
$addToSetPayload = [];
foreach ($addToSetColls as $propertyPath => $coll) {
$callback = $this->getValuePrepareCallback($coll);
$value = array_values(array_map($callback, $diffsMap[$propertyPath]));
$addToSetPayload[$propertyPath] = ['$each' => $value];
}
if (empty($addToSetPayload)) {
return;
}
$this->executeQuery($parent, ['$addToSet' => $addToSetPayload], $options);
} | [
"private",
"function",
"addToSetCollections",
"(",
"object",
"$",
"parent",
",",
"array",
"$",
"collsPaths",
",",
"array",
"$",
"pathCollsMap",
",",
"array",
"$",
"diffsMap",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"addToSetPaths",
"=",
"$",
"this",
"->",
"excludeSubPaths",
"(",
"$",
"collsPaths",
")",
";",
"/** @var PersistentCollectionInterface[] $addToSetColls */",
"$",
"addToSetColls",
"=",
"array_intersect_key",
"(",
"$",
"pathCollsMap",
",",
"array_flip",
"(",
"$",
"addToSetPaths",
")",
")",
";",
"$",
"addToSetPayload",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"addToSetColls",
"as",
"$",
"propertyPath",
"=>",
"$",
"coll",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"getValuePrepareCallback",
"(",
"$",
"coll",
")",
";",
"$",
"value",
"=",
"array_values",
"(",
"array_map",
"(",
"$",
"callback",
",",
"$",
"diffsMap",
"[",
"$",
"propertyPath",
"]",
")",
")",
";",
"$",
"addToSetPayload",
"[",
"$",
"propertyPath",
"]",
"=",
"[",
"'$each'",
"=>",
"$",
"value",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"addToSetPayload",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"parent",
",",
"[",
"'$addToSet'",
"=>",
"$",
"addToSetPayload",
"]",
",",
"$",
"options",
")",
";",
"}"
] | Perform collections update by 'addToSet' strategy.
@param object $parent Parent object to which passed collections is belong.
@param array $collsPaths Paths of collections that is passed.
@param array $pathCollsMap List of collections indexed by their paths.
@param array $diffsMap List of collection diffs indexed by collections paths.
@param array $options | [
"Perform",
"collections",
"update",
"by",
"addToSet",
"strategy",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L359-L377 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.getValuePrepareCallback | private function getValuePrepareCallback(PersistentCollectionInterface $coll) : Closure
{
$mapping = $coll->getMapping();
if (isset($mapping['embedded'])) {
return function ($v) use ($mapping) {
return $this->pb->prepareEmbeddedDocumentValue($mapping, $v);
};
}
return function ($v) use ($mapping) {
return $this->pb->prepareReferencedDocumentValue($mapping, $v);
};
} | php | private function getValuePrepareCallback(PersistentCollectionInterface $coll) : Closure
{
$mapping = $coll->getMapping();
if (isset($mapping['embedded'])) {
return function ($v) use ($mapping) {
return $this->pb->prepareEmbeddedDocumentValue($mapping, $v);
};
}
return function ($v) use ($mapping) {
return $this->pb->prepareReferencedDocumentValue($mapping, $v);
};
} | [
"private",
"function",
"getValuePrepareCallback",
"(",
"PersistentCollectionInterface",
"$",
"coll",
")",
":",
"Closure",
"{",
"$",
"mapping",
"=",
"$",
"coll",
"->",
"getMapping",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
"{",
"return",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"$",
"mapping",
")",
"{",
"return",
"$",
"this",
"->",
"pb",
"->",
"prepareEmbeddedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"v",
")",
";",
"}",
";",
"}",
"return",
"function",
"(",
"$",
"v",
")",
"use",
"(",
"$",
"mapping",
")",
"{",
"return",
"$",
"this",
"->",
"pb",
"->",
"prepareReferencedDocumentValue",
"(",
"$",
"mapping",
",",
"$",
"v",
")",
";",
"}",
";",
"}"
] | Return callback instance for specified collection. This callback will prepare values for query from documents
that collection contain. | [
"Return",
"callback",
"instance",
"for",
"specified",
"collection",
".",
"This",
"callback",
"will",
"prepare",
"values",
"for",
"query",
"from",
"documents",
"that",
"collection",
"contain",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L383-L395 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.executeQuery | private function executeQuery(object $document, array $newObj, array $options) : void
{
$className = get_class($document);
$class = $this->dm->getClassMetadata($className);
$id = $class->getDatabaseIdentifierValue($this->uow->getDocumentIdentifier($document));
$query = ['_id' => $id];
if ($class->isVersioned) {
$query[$class->fieldMappings[$class->versionField]['name']] = $class->reflFields[$class->versionField]->getValue($document);
}
$collection = $this->dm->getDocumentCollection($className);
$result = $collection->updateOne($query, $newObj, $options);
if ($class->isVersioned && ! $result->getMatchedCount()) {
throw LockException::lockFailed($document);
}
} | php | private function executeQuery(object $document, array $newObj, array $options) : void
{
$className = get_class($document);
$class = $this->dm->getClassMetadata($className);
$id = $class->getDatabaseIdentifierValue($this->uow->getDocumentIdentifier($document));
$query = ['_id' => $id];
if ($class->isVersioned) {
$query[$class->fieldMappings[$class->versionField]['name']] = $class->reflFields[$class->versionField]->getValue($document);
}
$collection = $this->dm->getDocumentCollection($className);
$result = $collection->updateOne($query, $newObj, $options);
if ($class->isVersioned && ! $result->getMatchedCount()) {
throw LockException::lockFailed($document);
}
} | [
"private",
"function",
"executeQuery",
"(",
"object",
"$",
"document",
",",
"array",
"$",
"newObj",
",",
"array",
"$",
"options",
")",
":",
"void",
"{",
"$",
"className",
"=",
"get_class",
"(",
"$",
"document",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"$",
"id",
"=",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
")",
";",
"$",
"query",
"=",
"[",
"'_id'",
"=>",
"$",
"id",
"]",
";",
"if",
"(",
"$",
"class",
"->",
"isVersioned",
")",
"{",
"$",
"query",
"[",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"class",
"->",
"versionField",
"]",
"[",
"'name'",
"]",
"]",
"=",
"$",
"class",
"->",
"reflFields",
"[",
"$",
"class",
"->",
"versionField",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"}",
"$",
"collection",
"=",
"$",
"this",
"->",
"dm",
"->",
"getDocumentCollection",
"(",
"$",
"className",
")",
";",
"$",
"result",
"=",
"$",
"collection",
"->",
"updateOne",
"(",
"$",
"query",
",",
"$",
"newObj",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isVersioned",
"&&",
"!",
"$",
"result",
"->",
"getMatchedCount",
"(",
")",
")",
"{",
"throw",
"LockException",
"::",
"lockFailed",
"(",
"$",
"document",
")",
";",
"}",
"}"
] | Executes a query updating the given document. | [
"Executes",
"a",
"query",
"updating",
"the",
"given",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L432-L446 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php | CollectionPersister.excludeSubPaths | private function excludeSubPaths(array $paths) : array
{
if (empty($paths)) {
return $paths;
}
sort($paths);
$uniquePaths = [$paths[0]];
for ($i = 1, $count = count($paths); $i < $count; ++$i) {
$lastUniquePath = end($uniquePaths);
assert($lastUniquePath !== false);
if (strpos($paths[$i], $lastUniquePath) === 0) {
continue;
}
$uniquePaths[] = $paths[$i];
}
return $uniquePaths;
} | php | private function excludeSubPaths(array $paths) : array
{
if (empty($paths)) {
return $paths;
}
sort($paths);
$uniquePaths = [$paths[0]];
for ($i = 1, $count = count($paths); $i < $count; ++$i) {
$lastUniquePath = end($uniquePaths);
assert($lastUniquePath !== false);
if (strpos($paths[$i], $lastUniquePath) === 0) {
continue;
}
$uniquePaths[] = $paths[$i];
}
return $uniquePaths;
} | [
"private",
"function",
"excludeSubPaths",
"(",
"array",
"$",
"paths",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"paths",
")",
")",
"{",
"return",
"$",
"paths",
";",
"}",
"sort",
"(",
"$",
"paths",
")",
";",
"$",
"uniquePaths",
"=",
"[",
"$",
"paths",
"[",
"0",
"]",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"1",
",",
"$",
"count",
"=",
"count",
"(",
"$",
"paths",
")",
";",
"$",
"i",
"<",
"$",
"count",
";",
"++",
"$",
"i",
")",
"{",
"$",
"lastUniquePath",
"=",
"end",
"(",
"$",
"uniquePaths",
")",
";",
"assert",
"(",
"$",
"lastUniquePath",
"!==",
"false",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"paths",
"[",
"$",
"i",
"]",
",",
"$",
"lastUniquePath",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"uniquePaths",
"[",
"]",
"=",
"$",
"paths",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"uniquePaths",
";",
"}"
] | Remove from passed paths list all sub-paths.
@param string[] $paths
@return string[] | [
"Remove",
"from",
"passed",
"paths",
"list",
"all",
"sub",
"-",
"paths",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L455-L474 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php | AbstractRepositoryFactory.getRepository | public function getRepository(DocumentManager $documentManager, string $documentName) : ObjectRepository
{
$metadata = $documentManager->getClassMetadata($documentName);
$hashKey = $metadata->getName() . spl_object_hash($documentManager);
if (isset($this->repositoryList[$hashKey])) {
return $this->repositoryList[$hashKey];
}
$repository = $this->createRepository($documentManager, ltrim($documentName, '\\'));
$this->repositoryList[$hashKey] = $repository;
return $repository;
} | php | public function getRepository(DocumentManager $documentManager, string $documentName) : ObjectRepository
{
$metadata = $documentManager->getClassMetadata($documentName);
$hashKey = $metadata->getName() . spl_object_hash($documentManager);
if (isset($this->repositoryList[$hashKey])) {
return $this->repositoryList[$hashKey];
}
$repository = $this->createRepository($documentManager, ltrim($documentName, '\\'));
$this->repositoryList[$hashKey] = $repository;
return $repository;
} | [
"public",
"function",
"getRepository",
"(",
"DocumentManager",
"$",
"documentManager",
",",
"string",
"$",
"documentName",
")",
":",
"ObjectRepository",
"{",
"$",
"metadata",
"=",
"$",
"documentManager",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"$",
"hashKey",
"=",
"$",
"metadata",
"->",
"getName",
"(",
")",
".",
"spl_object_hash",
"(",
"$",
"documentManager",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"repositoryList",
"[",
"$",
"hashKey",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"repositoryList",
"[",
"$",
"hashKey",
"]",
";",
"}",
"$",
"repository",
"=",
"$",
"this",
"->",
"createRepository",
"(",
"$",
"documentManager",
",",
"ltrim",
"(",
"$",
"documentName",
",",
"'\\\\'",
")",
")",
";",
"$",
"this",
"->",
"repositoryList",
"[",
"$",
"hashKey",
"]",
"=",
"$",
"repository",
";",
"return",
"$",
"repository",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php#L28-L42 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php | AbstractRepositoryFactory.createRepository | protected function createRepository(DocumentManager $documentManager, string $documentName) : ObjectRepository
{
$metadata = $documentManager->getClassMetadata($documentName);
if ($metadata->customRepositoryClassName) {
$repositoryClassName = $metadata->customRepositoryClassName;
} elseif ($metadata->isFile) {
$repositoryClassName = $documentManager->getConfiguration()->getDefaultGridFSRepositoryClassName();
} else {
$repositoryClassName = $documentManager->getConfiguration()->getDefaultDocumentRepositoryClassName();
}
return $this->instantiateRepository($repositoryClassName, $documentManager, $metadata);
} | php | protected function createRepository(DocumentManager $documentManager, string $documentName) : ObjectRepository
{
$metadata = $documentManager->getClassMetadata($documentName);
if ($metadata->customRepositoryClassName) {
$repositoryClassName = $metadata->customRepositoryClassName;
} elseif ($metadata->isFile) {
$repositoryClassName = $documentManager->getConfiguration()->getDefaultGridFSRepositoryClassName();
} else {
$repositoryClassName = $documentManager->getConfiguration()->getDefaultDocumentRepositoryClassName();
}
return $this->instantiateRepository($repositoryClassName, $documentManager, $metadata);
} | [
"protected",
"function",
"createRepository",
"(",
"DocumentManager",
"$",
"documentManager",
",",
"string",
"$",
"documentName",
")",
":",
"ObjectRepository",
"{",
"$",
"metadata",
"=",
"$",
"documentManager",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"metadata",
"->",
"customRepositoryClassName",
")",
"{",
"$",
"repositoryClassName",
"=",
"$",
"metadata",
"->",
"customRepositoryClassName",
";",
"}",
"elseif",
"(",
"$",
"metadata",
"->",
"isFile",
")",
"{",
"$",
"repositoryClassName",
"=",
"$",
"documentManager",
"->",
"getConfiguration",
"(",
")",
"->",
"getDefaultGridFSRepositoryClassName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"repositoryClassName",
"=",
"$",
"documentManager",
"->",
"getConfiguration",
"(",
")",
"->",
"getDefaultDocumentRepositoryClassName",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"instantiateRepository",
"(",
"$",
"repositoryClassName",
",",
"$",
"documentManager",
",",
"$",
"metadata",
")",
";",
"}"
] | Create a new repository instance for a document class.
@return ObjectRepository|GridFSRepository | [
"Create",
"a",
"new",
"repository",
"instance",
"for",
"a",
"document",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php#L49-L62 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php | GeoNear.getExpression | public function getExpression() : array
{
$geoNear = [
'near' => $this->near,
'spherical' => $this->spherical,
'distanceField' => $this->distanceField,
'query' => $this->query->getQuery(),
'distanceMultiplier' => $this->distanceMultiplier,
'includeLocs' => $this->includeLocs,
'maxDistance' => $this->maxDistance,
'minDistance' => $this->minDistance,
'num' => $this->num,
'uniqueDocs' => $this->uniqueDocs,
];
foreach (['distanceMultiplier', 'includeLocs', 'maxDistance', 'minDistance', 'num', 'uniqueDocs'] as $option) {
if ($geoNear[$option]) {
continue;
}
unset($geoNear[$option]);
}
return ['$geoNear' => $geoNear];
} | php | public function getExpression() : array
{
$geoNear = [
'near' => $this->near,
'spherical' => $this->spherical,
'distanceField' => $this->distanceField,
'query' => $this->query->getQuery(),
'distanceMultiplier' => $this->distanceMultiplier,
'includeLocs' => $this->includeLocs,
'maxDistance' => $this->maxDistance,
'minDistance' => $this->minDistance,
'num' => $this->num,
'uniqueDocs' => $this->uniqueDocs,
];
foreach (['distanceMultiplier', 'includeLocs', 'maxDistance', 'minDistance', 'num', 'uniqueDocs'] as $option) {
if ($geoNear[$option]) {
continue;
}
unset($geoNear[$option]);
}
return ['$geoNear' => $geoNear];
} | [
"public",
"function",
"getExpression",
"(",
")",
":",
"array",
"{",
"$",
"geoNear",
"=",
"[",
"'near'",
"=>",
"$",
"this",
"->",
"near",
",",
"'spherical'",
"=>",
"$",
"this",
"->",
"spherical",
",",
"'distanceField'",
"=>",
"$",
"this",
"->",
"distanceField",
",",
"'query'",
"=>",
"$",
"this",
"->",
"query",
"->",
"getQuery",
"(",
")",
",",
"'distanceMultiplier'",
"=>",
"$",
"this",
"->",
"distanceMultiplier",
",",
"'includeLocs'",
"=>",
"$",
"this",
"->",
"includeLocs",
",",
"'maxDistance'",
"=>",
"$",
"this",
"->",
"maxDistance",
",",
"'minDistance'",
"=>",
"$",
"this",
"->",
"minDistance",
",",
"'num'",
"=>",
"$",
"this",
"->",
"num",
",",
"'uniqueDocs'",
"=>",
"$",
"this",
"->",
"uniqueDocs",
",",
"]",
";",
"foreach",
"(",
"[",
"'distanceMultiplier'",
",",
"'includeLocs'",
",",
"'maxDistance'",
",",
"'minDistance'",
",",
"'num'",
",",
"'uniqueDocs'",
"]",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"$",
"geoNear",
"[",
"$",
"option",
"]",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"geoNear",
"[",
"$",
"option",
"]",
")",
";",
"}",
"return",
"[",
"'$geoNear'",
"=>",
"$",
"geoNear",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php#L57-L81 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php | GeoNear.near | public function near($x, $y = null) : self
{
if ($x instanceof Point) {
$x = $x->jsonSerialize();
}
$this->near = is_array($x) ? $x : [$x, $y];
$this->spherical = is_array($x) && isset($x['type']);
return $this;
} | php | public function near($x, $y = null) : self
{
if ($x instanceof Point) {
$x = $x->jsonSerialize();
}
$this->near = is_array($x) ? $x : [$x, $y];
$this->spherical = is_array($x) && isset($x['type']);
return $this;
} | [
"public",
"function",
"near",
"(",
"$",
"x",
",",
"$",
"y",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"x",
"instanceof",
"Point",
")",
"{",
"$",
"x",
"=",
"$",
"x",
"->",
"jsonSerialize",
"(",
")",
";",
"}",
"$",
"this",
"->",
"near",
"=",
"is_array",
"(",
"$",
"x",
")",
"?",
"$",
"x",
":",
"[",
"$",
"x",
",",
"$",
"y",
"]",
";",
"$",
"this",
"->",
"spherical",
"=",
"is_array",
"(",
"$",
"x",
")",
"&&",
"isset",
"(",
"$",
"x",
"[",
"'type'",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | The point for which to find the closest documents.
A GeoJSON point may be provided as the first and only argument for
2dsphere queries. This single parameter may be a GeoJSON point object or
an array corresponding to the point's JSON representation. If GeoJSON is
used, the "spherical" option will default to true.
@param float|array|Point $x
@param float $y | [
"The",
"point",
"for",
"which",
"to",
"find",
"the",
"closest",
"documents",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php#L152-L162 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php | ReferencePrimer.primeReferences | public function primeReferences(ClassMetadata $class, $documents, string $fieldName, array $hints = [], ?callable $primer = null) : void
{
$data = $this->parseDotSyntaxForPrimer($fieldName, $class, $documents);
$mapping = $data['mapping'];
$fieldName = $data['fieldName'];
$class = $data['class'];
$documents = $data['documents'];
/* Inverse-side references would need to be populated before we can
* collect references to be primed. This is not supported.
*/
if (! isset($mapping['reference']) || ! $mapping['isOwningSide']) {
throw new InvalidArgumentException(sprintf('Field "%s" is not the owning side of a reference relationship in class "%s"', $fieldName, $class->name));
}
/* Simple reference require a target document class so we can construct
* the priming query.
*/
if ($mapping['storeAs'] === ClassMetadata::REFERENCE_STORE_AS_ID && empty($mapping['targetDocument'])) {
throw new LogicException(sprintf('Field "%s" is an identifier reference without a target document class in class "%s"', $fieldName, $class->name));
}
if ($primer !== null && ! is_callable($primer)) {
throw new InvalidArgumentException('$primer is not callable');
}
$primer = $primer ?: $this->defaultPrimer;
$groupedIds = [];
/** @var PersistentCollectionInterface $document */
foreach ($documents as $document) {
$fieldValue = $class->getFieldValue($document, $fieldName);
/* The field will need to be either a Proxy (reference-one) or
* PersistentCollection (reference-many) in order to prime anything.
*/
if (! is_object($fieldValue)) {
continue;
}
if ($mapping['type'] === 'one' && $fieldValue instanceof GhostObjectInterface && ! $fieldValue->isProxyInitialized()) {
$refClass = $this->dm->getClassMetadata(get_class($fieldValue));
$id = $this->uow->getDocumentIdentifier($fieldValue);
$groupedIds[$refClass->name][serialize($id)] = $id;
} elseif ($mapping['type'] === 'many' && $fieldValue instanceof PersistentCollectionInterface) {
$this->addManyReferences($fieldValue, $groupedIds);
}
}
foreach ($groupedIds as $className => $ids) {
$refClass = $this->dm->getClassMetadata($className);
call_user_func($primer, $this->dm, $refClass, array_values($ids), $hints);
}
} | php | public function primeReferences(ClassMetadata $class, $documents, string $fieldName, array $hints = [], ?callable $primer = null) : void
{
$data = $this->parseDotSyntaxForPrimer($fieldName, $class, $documents);
$mapping = $data['mapping'];
$fieldName = $data['fieldName'];
$class = $data['class'];
$documents = $data['documents'];
if (! isset($mapping['reference']) || ! $mapping['isOwningSide']) {
throw new InvalidArgumentException(sprintf('Field "%s" is not the owning side of a reference relationship in class "%s"', $fieldName, $class->name));
}
if ($mapping['storeAs'] === ClassMetadata::REFERENCE_STORE_AS_ID && empty($mapping['targetDocument'])) {
throw new LogicException(sprintf('Field "%s" is an identifier reference without a target document class in class "%s"', $fieldName, $class->name));
}
if ($primer !== null && ! is_callable($primer)) {
throw new InvalidArgumentException('$primer is not callable');
}
$primer = $primer ?: $this->defaultPrimer;
$groupedIds = [];
foreach ($documents as $document) {
$fieldValue = $class->getFieldValue($document, $fieldName);
if (! is_object($fieldValue)) {
continue;
}
if ($mapping['type'] === 'one' && $fieldValue instanceof GhostObjectInterface && ! $fieldValue->isProxyInitialized()) {
$refClass = $this->dm->getClassMetadata(get_class($fieldValue));
$id = $this->uow->getDocumentIdentifier($fieldValue);
$groupedIds[$refClass->name][serialize($id)] = $id;
} elseif ($mapping['type'] === 'many' && $fieldValue instanceof PersistentCollectionInterface) {
$this->addManyReferences($fieldValue, $groupedIds);
}
}
foreach ($groupedIds as $className => $ids) {
$refClass = $this->dm->getClassMetadata($className);
call_user_func($primer, $this->dm, $refClass, array_values($ids), $hints);
}
} | [
"public",
"function",
"primeReferences",
"(",
"ClassMetadata",
"$",
"class",
",",
"$",
"documents",
",",
"string",
"$",
"fieldName",
",",
"array",
"$",
"hints",
"=",
"[",
"]",
",",
"?",
"callable",
"$",
"primer",
"=",
"null",
")",
":",
"void",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"parseDotSyntaxForPrimer",
"(",
"$",
"fieldName",
",",
"$",
"class",
",",
"$",
"documents",
")",
";",
"$",
"mapping",
"=",
"$",
"data",
"[",
"'mapping'",
"]",
";",
"$",
"fieldName",
"=",
"$",
"data",
"[",
"'fieldName'",
"]",
";",
"$",
"class",
"=",
"$",
"data",
"[",
"'class'",
"]",
";",
"$",
"documents",
"=",
"$",
"data",
"[",
"'documents'",
"]",
";",
"/* Inverse-side references would need to be populated before we can\n * collect references to be primed. This is not supported.\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"||",
"!",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Field \"%s\" is not the owning side of a reference relationship in class \"%s\"'",
",",
"$",
"fieldName",
",",
"$",
"class",
"->",
"name",
")",
")",
";",
"}",
"/* Simple reference require a target document class so we can construct\n * the priming query.\n */",
"if",
"(",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"===",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
"&&",
"empty",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Field \"%s\" is an identifier reference without a target document class in class \"%s\"'",
",",
"$",
"fieldName",
",",
"$",
"class",
"->",
"name",
")",
")",
";",
"}",
"if",
"(",
"$",
"primer",
"!==",
"null",
"&&",
"!",
"is_callable",
"(",
"$",
"primer",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$primer is not callable'",
")",
";",
"}",
"$",
"primer",
"=",
"$",
"primer",
"?",
":",
"$",
"this",
"->",
"defaultPrimer",
";",
"$",
"groupedIds",
"=",
"[",
"]",
";",
"/** @var PersistentCollectionInterface $document */",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"fieldValue",
"=",
"$",
"class",
"->",
"getFieldValue",
"(",
"$",
"document",
",",
"$",
"fieldName",
")",
";",
"/* The field will need to be either a Proxy (reference-one) or\n * PersistentCollection (reference-many) in order to prime anything.\n */",
"if",
"(",
"!",
"is_object",
"(",
"$",
"fieldValue",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'one'",
"&&",
"$",
"fieldValue",
"instanceof",
"GhostObjectInterface",
"&&",
"!",
"$",
"fieldValue",
"->",
"isProxyInitialized",
"(",
")",
")",
"{",
"$",
"refClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"fieldValue",
")",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"uow",
"->",
"getDocumentIdentifier",
"(",
"$",
"fieldValue",
")",
";",
"$",
"groupedIds",
"[",
"$",
"refClass",
"->",
"name",
"]",
"[",
"serialize",
"(",
"$",
"id",
")",
"]",
"=",
"$",
"id",
";",
"}",
"elseif",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
"&&",
"$",
"fieldValue",
"instanceof",
"PersistentCollectionInterface",
")",
"{",
"$",
"this",
"->",
"addManyReferences",
"(",
"$",
"fieldValue",
",",
"$",
"groupedIds",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"groupedIds",
"as",
"$",
"className",
"=>",
"$",
"ids",
")",
"{",
"$",
"refClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"call_user_func",
"(",
"$",
"primer",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"refClass",
",",
"array_values",
"(",
"$",
"ids",
")",
",",
"$",
"hints",
")",
";",
"}",
"}"
] | Prime references within a mapped field of one or more documents.
If a $primer callable is provided, it should have the same signature as
the default primer defined in the constructor. If $primer is not
callable, the default primer will be used.
@param ClassMetadata $class Class metadata for the document
@param array|Traversable $documents Documents containing references to prime
@param string $fieldName Field name containing references to prime
@param array $hints UnitOfWork hints for priming queries
@param callable $primer Optional primer callable
@throws InvalidArgumentException If the mapped field is not the owning
side of a reference relationship.
@throws InvalidArgumentException If $primer is not callable.
@throws LogicException If the mapped field is a simple reference and is
missing a target document class. | [
"Prime",
"references",
"within",
"a",
"mapped",
"field",
"of",
"one",
"or",
"more",
"documents",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php#L109-L162 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php | ReferencePrimer.parseDotSyntaxForPrimer | private function parseDotSyntaxForPrimer(string $fieldName, ClassMetadata $class, $documents, ?array $mapping = null) : array
{
// Recursion passthrough:
if ($mapping !== null) {
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping];
}
// Gather mapping data:
$e = explode('.', $fieldName);
if (! isset($class->fieldMappings[$e[0]])) {
throw new InvalidArgumentException(sprintf('Field %s cannot be further parsed for priming because it is unmapped.', $fieldName));
}
$mapping = $class->fieldMappings[$e[0]];
$e[0] = $mapping['fieldName'];
// Case of embedded document(s) to recurse through:
if (! isset($mapping['reference'])) {
if (empty($mapping['embedded'])) {
throw new InvalidArgumentException(sprintf('Field "%s" of fieldName "%s" is not an embedded document, therefore no children can be primed. Aborting. This feature does not support traversing nested referenced documents at this time.', $e[0], $fieldName));
}
if (! isset($mapping['targetDocument'])) {
throw new InvalidArgumentException(sprintf('No target document class has been specified for this embedded document. However, targetDocument mapping must be specified in order for prime to work on fieldName "%s" for mapping of field "%s".', $fieldName, $mapping['fieldName']));
}
$childDocuments = [];
foreach ($documents as $document) {
$fieldValue = $class->getFieldValue($document, $e[0]);
if ($fieldValue instanceof PersistentCollectionInterface) {
foreach ($fieldValue as $elemDocument) {
array_push($childDocuments, $elemDocument);
}
} else {
array_push($childDocuments, $fieldValue);
}
}
array_shift($e);
$childClass = $this->dm->getClassMetadata($mapping['targetDocument']);
if (! $childClass->hasField($e[0])) {
throw new InvalidArgumentException(sprintf('Field to prime must exist in embedded target document. Reference fieldName "%s" for mapping of target document class "%s".', $fieldName, $mapping['targetDocument']));
}
$childFieldName = implode('.', $e);
return $this->parseDotSyntaxForPrimer($childFieldName, $childClass, $childDocuments);
}
// Case of reference(s) to prime:
if ($mapping['reference']) {
if (count($e) > 1) {
throw new InvalidArgumentException(sprintf('Cannot prime more than one layer deep but field "%s" is a reference and has children in fieldName "%s".', $e[0], $fieldName));
}
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping];
}
} | php | private function parseDotSyntaxForPrimer(string $fieldName, ClassMetadata $class, $documents, ?array $mapping = null) : array
{
if ($mapping !== null) {
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping];
}
$e = explode('.', $fieldName);
if (! isset($class->fieldMappings[$e[0]])) {
throw new InvalidArgumentException(sprintf('Field %s cannot be further parsed for priming because it is unmapped.', $fieldName));
}
$mapping = $class->fieldMappings[$e[0]];
$e[0] = $mapping['fieldName'];
if (! isset($mapping['reference'])) {
if (empty($mapping['embedded'])) {
throw new InvalidArgumentException(sprintf('Field "%s" of fieldName "%s" is not an embedded document, therefore no children can be primed. Aborting. This feature does not support traversing nested referenced documents at this time.', $e[0], $fieldName));
}
if (! isset($mapping['targetDocument'])) {
throw new InvalidArgumentException(sprintf('No target document class has been specified for this embedded document. However, targetDocument mapping must be specified in order for prime to work on fieldName "%s" for mapping of field "%s".', $fieldName, $mapping['fieldName']));
}
$childDocuments = [];
foreach ($documents as $document) {
$fieldValue = $class->getFieldValue($document, $e[0]);
if ($fieldValue instanceof PersistentCollectionInterface) {
foreach ($fieldValue as $elemDocument) {
array_push($childDocuments, $elemDocument);
}
} else {
array_push($childDocuments, $fieldValue);
}
}
array_shift($e);
$childClass = $this->dm->getClassMetadata($mapping['targetDocument']);
if (! $childClass->hasField($e[0])) {
throw new InvalidArgumentException(sprintf('Field to prime must exist in embedded target document. Reference fieldName "%s" for mapping of target document class "%s".', $fieldName, $mapping['targetDocument']));
}
$childFieldName = implode('.', $e);
return $this->parseDotSyntaxForPrimer($childFieldName, $childClass, $childDocuments);
}
if ($mapping['reference']) {
if (count($e) > 1) {
throw new InvalidArgumentException(sprintf('Cannot prime more than one layer deep but field "%s" is a reference and has children in fieldName "%s".', $e[0], $fieldName));
}
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping];
}
} | [
"private",
"function",
"parseDotSyntaxForPrimer",
"(",
"string",
"$",
"fieldName",
",",
"ClassMetadata",
"$",
"class",
",",
"$",
"documents",
",",
"?",
"array",
"$",
"mapping",
"=",
"null",
")",
":",
"array",
"{",
"// Recursion passthrough:",
"if",
"(",
"$",
"mapping",
"!==",
"null",
")",
"{",
"return",
"[",
"'fieldName'",
"=>",
"$",
"fieldName",
",",
"'class'",
"=>",
"$",
"class",
",",
"'documents'",
"=>",
"$",
"documents",
",",
"'mapping'",
"=>",
"$",
"mapping",
"]",
";",
"}",
"// Gather mapping data:",
"$",
"e",
"=",
"explode",
"(",
"'.'",
",",
"$",
"fieldName",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"e",
"[",
"0",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Field %s cannot be further parsed for priming because it is unmapped.'",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"$",
"mapping",
"=",
"$",
"class",
"->",
"fieldMappings",
"[",
"$",
"e",
"[",
"0",
"]",
"]",
";",
"$",
"e",
"[",
"0",
"]",
"=",
"$",
"mapping",
"[",
"'fieldName'",
"]",
";",
"// Case of embedded document(s) to recurse through:",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Field \"%s\" of fieldName \"%s\" is not an embedded document, therefore no children can be primed. Aborting. This feature does not support traversing nested referenced documents at this time.'",
",",
"$",
"e",
"[",
"0",
"]",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'No target document class has been specified for this embedded document. However, targetDocument mapping must be specified in order for prime to work on fieldName \"%s\" for mapping of field \"%s\".'",
",",
"$",
"fieldName",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
")",
";",
"}",
"$",
"childDocuments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"fieldValue",
"=",
"$",
"class",
"->",
"getFieldValue",
"(",
"$",
"document",
",",
"$",
"e",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"fieldValue",
"instanceof",
"PersistentCollectionInterface",
")",
"{",
"foreach",
"(",
"$",
"fieldValue",
"as",
"$",
"elemDocument",
")",
"{",
"array_push",
"(",
"$",
"childDocuments",
",",
"$",
"elemDocument",
")",
";",
"}",
"}",
"else",
"{",
"array_push",
"(",
"$",
"childDocuments",
",",
"$",
"fieldValue",
")",
";",
"}",
"}",
"array_shift",
"(",
"$",
"e",
")",
";",
"$",
"childClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"childClass",
"->",
"hasField",
"(",
"$",
"e",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Field to prime must exist in embedded target document. Reference fieldName \"%s\" for mapping of target document class \"%s\".'",
",",
"$",
"fieldName",
",",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
")",
";",
"}",
"$",
"childFieldName",
"=",
"implode",
"(",
"'.'",
",",
"$",
"e",
")",
";",
"return",
"$",
"this",
"->",
"parseDotSyntaxForPrimer",
"(",
"$",
"childFieldName",
",",
"$",
"childClass",
",",
"$",
"childDocuments",
")",
";",
"}",
"// Case of reference(s) to prime:",
"if",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"e",
")",
">",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Cannot prime more than one layer deep but field \"%s\" is a reference and has children in fieldName \"%s\".'",
",",
"$",
"e",
"[",
"0",
"]",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"return",
"[",
"'fieldName'",
"=>",
"$",
"fieldName",
",",
"'class'",
"=>",
"$",
"class",
",",
"'documents'",
"=>",
"$",
"documents",
",",
"'mapping'",
"=>",
"$",
"mapping",
"]",
";",
"}",
"}"
] | If you are priming references inside an embedded document you'll need to parse the dot syntax.
This method will traverse through embedded documents to find the reference to prime.
However this method will not traverse through multiple layers of references.
I.e. you can prime this: myDocument.embeddedDocument.embeddedDocuments.embeddedDocuments.referencedDocument(s)
... but you cannot prime this: myDocument.embeddedDocument.referencedDocuments.referencedDocument(s)
This addresses Issue #624.
@param array|Traversable $documents | [
"If",
"you",
"are",
"priming",
"references",
"inside",
"an",
"embedded",
"document",
"you",
"ll",
"need",
"to",
"parse",
"the",
"dot",
"syntax",
".",
"This",
"method",
"will",
"traverse",
"through",
"embedded",
"documents",
"to",
"find",
"the",
"reference",
"to",
"prime",
".",
"However",
"this",
"method",
"will",
"not",
"traverse",
"through",
"multiple",
"layers",
"of",
"references",
".",
"I",
".",
"e",
".",
"you",
"can",
"prime",
"this",
":",
"myDocument",
".",
"embeddedDocument",
".",
"embeddedDocuments",
".",
"embeddedDocuments",
".",
"referencedDocument",
"(",
"s",
")",
"...",
"but",
"you",
"cannot",
"prime",
"this",
":",
"myDocument",
".",
"embeddedDocument",
".",
"referencedDocuments",
".",
"referencedDocument",
"(",
"s",
")",
"This",
"addresses",
"Issue",
"#624",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php#L174-L236 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php | ReferencePrimer.addManyReferences | private function addManyReferences(PersistentCollectionInterface $persistentCollection, array &$groupedIds) : void
{
$mapping = $persistentCollection->getMapping();
$class = null;
$className = null;
if ($mapping['storeAs'] === ClassMetadata::REFERENCE_STORE_AS_ID) {
$className = $mapping['targetDocument'];
$class = $this->dm->getClassMetadata($className);
}
foreach ($persistentCollection->getMongoData() as $reference) {
$id = ClassMetadata::getReferenceId($reference, $mapping['storeAs']);
if ($mapping['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID) {
$className = $this->uow->getClassNameForAssociation($mapping, $reference);
$class = $this->dm->getClassMetadata($className);
}
if ($class === null) {
continue;
}
$document = $this->uow->tryGetById($id, $class);
if ($document && ! (($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()))) {
continue;
}
$id = $class->getPHPIdentifierValue($id);
$groupedIds[$className][serialize($id)] = $id;
}
} | php | private function addManyReferences(PersistentCollectionInterface $persistentCollection, array &$groupedIds) : void
{
$mapping = $persistentCollection->getMapping();
$class = null;
$className = null;
if ($mapping['storeAs'] === ClassMetadata::REFERENCE_STORE_AS_ID) {
$className = $mapping['targetDocument'];
$class = $this->dm->getClassMetadata($className);
}
foreach ($persistentCollection->getMongoData() as $reference) {
$id = ClassMetadata::getReferenceId($reference, $mapping['storeAs']);
if ($mapping['storeAs'] !== ClassMetadata::REFERENCE_STORE_AS_ID) {
$className = $this->uow->getClassNameForAssociation($mapping, $reference);
$class = $this->dm->getClassMetadata($className);
}
if ($class === null) {
continue;
}
$document = $this->uow->tryGetById($id, $class);
if ($document && ! (($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()))) {
continue;
}
$id = $class->getPHPIdentifierValue($id);
$groupedIds[$className][serialize($id)] = $id;
}
} | [
"private",
"function",
"addManyReferences",
"(",
"PersistentCollectionInterface",
"$",
"persistentCollection",
",",
"array",
"&",
"$",
"groupedIds",
")",
":",
"void",
"{",
"$",
"mapping",
"=",
"$",
"persistentCollection",
"->",
"getMapping",
"(",
")",
";",
"$",
"class",
"=",
"null",
";",
"$",
"className",
"=",
"null",
";",
"if",
"(",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"===",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
")",
"{",
"$",
"className",
"=",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"}",
"foreach",
"(",
"$",
"persistentCollection",
"->",
"getMongoData",
"(",
")",
"as",
"$",
"reference",
")",
"{",
"$",
"id",
"=",
"ClassMetadata",
"::",
"getReferenceId",
"(",
"$",
"reference",
",",
"$",
"mapping",
"[",
"'storeAs'",
"]",
")",
";",
"if",
"(",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"!==",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"uow",
"->",
"getClassNameForAssociation",
"(",
"$",
"mapping",
",",
"$",
"reference",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"document",
"=",
"$",
"this",
"->",
"uow",
"->",
"tryGetById",
"(",
"$",
"id",
",",
"$",
"class",
")",
";",
"if",
"(",
"$",
"document",
"&&",
"!",
"(",
"(",
"$",
"document",
"instanceof",
"GhostObjectInterface",
"&&",
"!",
"$",
"document",
"->",
"isProxyInitialized",
"(",
")",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"id",
"=",
"$",
"class",
"->",
"getPHPIdentifierValue",
"(",
"$",
"id",
")",
";",
"$",
"groupedIds",
"[",
"$",
"className",
"]",
"[",
"serialize",
"(",
"$",
"id",
")",
"]",
"=",
"$",
"id",
";",
"}",
"}"
] | Adds identifiers from a PersistentCollection to $groupedIds.
If the relation contains simple references, the mapping is assumed to
have a target document class defined. Without that, there is no way to
infer the class of the referenced documents. | [
"Adds",
"identifiers",
"from",
"a",
"PersistentCollection",
"to",
"$groupedIds",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php#L245-L277 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.documentNotFound | public function documentNotFound(object $proxy, $id) : bool
{
$eventArgs = new DocumentNotFoundEventArgs($proxy, $this->dm, $id);
$this->evm->dispatchEvent(Events::documentNotFound, $eventArgs);
return $eventArgs->isExceptionDisabled();
} | php | public function documentNotFound(object $proxy, $id) : bool
{
$eventArgs = new DocumentNotFoundEventArgs($proxy, $this->dm, $id);
$this->evm->dispatchEvent(Events::documentNotFound, $eventArgs);
return $eventArgs->isExceptionDisabled();
} | [
"public",
"function",
"documentNotFound",
"(",
"object",
"$",
"proxy",
",",
"$",
"id",
")",
":",
"bool",
"{",
"$",
"eventArgs",
"=",
"new",
"DocumentNotFoundEventArgs",
"(",
"$",
"proxy",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"id",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"documentNotFound",
",",
"$",
"eventArgs",
")",
";",
"return",
"$",
"eventArgs",
"->",
"isExceptionDisabled",
"(",
")",
";",
"}"
] | @param mixed $id
@return bool Returns whether the exceptionDisabled flag was set | [
"@param",
"mixed",
"$id"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L45-L51 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.postCollectionLoad | public function postCollectionLoad(PersistentCollectionInterface $coll) : void
{
$eventArgs = new PostCollectionLoadEventArgs($coll, $this->dm);
$this->evm->dispatchEvent(Events::postCollectionLoad, $eventArgs);
} | php | public function postCollectionLoad(PersistentCollectionInterface $coll) : void
{
$eventArgs = new PostCollectionLoadEventArgs($coll, $this->dm);
$this->evm->dispatchEvent(Events::postCollectionLoad, $eventArgs);
} | [
"public",
"function",
"postCollectionLoad",
"(",
"PersistentCollectionInterface",
"$",
"coll",
")",
":",
"void",
"{",
"$",
"eventArgs",
"=",
"new",
"PostCollectionLoadEventArgs",
"(",
"$",
"coll",
",",
"$",
"this",
"->",
"dm",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"postCollectionLoad",
",",
"$",
"eventArgs",
")",
";",
"}"
] | Dispatches postCollectionLoad event. | [
"Dispatches",
"postCollectionLoad",
"event",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L56-L60 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.postPersist | public function postPersist(ClassMetadata $class, object $document) : void
{
$class->invokeLifecycleCallbacks(Events::postPersist, $document, [new LifecycleEventArgs($document, $this->dm)]);
$this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($document, $this->dm));
$this->cascadePostPersist($class, $document);
} | php | public function postPersist(ClassMetadata $class, object $document) : void
{
$class->invokeLifecycleCallbacks(Events::postPersist, $document, [new LifecycleEventArgs($document, $this->dm)]);
$this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($document, $this->dm));
$this->cascadePostPersist($class, $document);
} | [
"public",
"function",
"postPersist",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"$",
"class",
"->",
"invokeLifecycleCallbacks",
"(",
"Events",
"::",
"postPersist",
",",
"$",
"document",
",",
"[",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
"]",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"postPersist",
",",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
")",
";",
"$",
"this",
"->",
"cascadePostPersist",
"(",
"$",
"class",
",",
"$",
"document",
")",
";",
"}"
] | Invokes postPersist callbacks and events for given document cascading them to embedded documents as well. | [
"Invokes",
"postPersist",
"callbacks",
"and",
"events",
"for",
"given",
"document",
"cascading",
"them",
"to",
"embedded",
"documents",
"as",
"well",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L65-L70 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.postRemove | public function postRemove(ClassMetadata $class, object $document) : void
{
$class->invokeLifecycleCallbacks(Events::postRemove, $document, [new LifecycleEventArgs($document, $this->dm)]);
$this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm));
} | php | public function postRemove(ClassMetadata $class, object $document) : void
{
$class->invokeLifecycleCallbacks(Events::postRemove, $document, [new LifecycleEventArgs($document, $this->dm)]);
$this->evm->dispatchEvent(Events::postRemove, new LifecycleEventArgs($document, $this->dm));
} | [
"public",
"function",
"postRemove",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"$",
"class",
"->",
"invokeLifecycleCallbacks",
"(",
"Events",
"::",
"postRemove",
",",
"$",
"document",
",",
"[",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
"]",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"postRemove",
",",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
")",
";",
"}"
] | Invokes postRemove callbacks and events for given document. | [
"Invokes",
"postRemove",
"callbacks",
"and",
"events",
"for",
"given",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L75-L79 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.postUpdate | public function postUpdate(ClassMetadata $class, object $document) : void
{
$class->invokeLifecycleCallbacks(Events::postUpdate, $document, [new LifecycleEventArgs($document, $this->dm)]);
$this->evm->dispatchEvent(Events::postUpdate, new LifecycleEventArgs($document, $this->dm));
$this->cascadePostUpdate($class, $document);
} | php | public function postUpdate(ClassMetadata $class, object $document) : void
{
$class->invokeLifecycleCallbacks(Events::postUpdate, $document, [new LifecycleEventArgs($document, $this->dm)]);
$this->evm->dispatchEvent(Events::postUpdate, new LifecycleEventArgs($document, $this->dm));
$this->cascadePostUpdate($class, $document);
} | [
"public",
"function",
"postUpdate",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"$",
"class",
"->",
"invokeLifecycleCallbacks",
"(",
"Events",
"::",
"postUpdate",
",",
"$",
"document",
",",
"[",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
"]",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"postUpdate",
",",
"new",
"LifecycleEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
")",
")",
";",
"$",
"this",
"->",
"cascadePostUpdate",
"(",
"$",
"class",
",",
"$",
"document",
")",
";",
"}"
] | Invokes postUpdate callbacks and events for given document. The same will be done for embedded documents owned
by given document unless they were new in which case postPersist callbacks and events will be dispatched. | [
"Invokes",
"postUpdate",
"callbacks",
"and",
"events",
"for",
"given",
"document",
".",
"The",
"same",
"will",
"be",
"done",
"for",
"embedded",
"documents",
"owned",
"by",
"given",
"document",
"unless",
"they",
"were",
"new",
"in",
"which",
"case",
"postPersist",
"callbacks",
"and",
"events",
"will",
"be",
"dispatched",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L85-L90 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.preUpdate | public function preUpdate(ClassMetadata $class, object $document) : void
{
if (! empty($class->lifecycleCallbacks[Events::preUpdate])) {
$class->invokeLifecycleCallbacks(Events::preUpdate, $document, [new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document))]);
$this->uow->recomputeSingleDocumentChangeSet($class, $document);
}
$this->evm->dispatchEvent(Events::preUpdate, new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document)));
$this->cascadePreUpdate($class, $document);
} | php | public function preUpdate(ClassMetadata $class, object $document) : void
{
if (! empty($class->lifecycleCallbacks[Events::preUpdate])) {
$class->invokeLifecycleCallbacks(Events::preUpdate, $document, [new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document))]);
$this->uow->recomputeSingleDocumentChangeSet($class, $document);
}
$this->evm->dispatchEvent(Events::preUpdate, new PreUpdateEventArgs($document, $this->dm, $this->uow->getDocumentChangeSet($document)));
$this->cascadePreUpdate($class, $document);
} | [
"public",
"function",
"preUpdate",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
"->",
"lifecycleCallbacks",
"[",
"Events",
"::",
"preUpdate",
"]",
")",
")",
"{",
"$",
"class",
"->",
"invokeLifecycleCallbacks",
"(",
"Events",
"::",
"preUpdate",
",",
"$",
"document",
",",
"[",
"new",
"PreUpdateEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"document",
")",
")",
"]",
")",
";",
"$",
"this",
"->",
"uow",
"->",
"recomputeSingleDocumentChangeSet",
"(",
"$",
"class",
",",
"$",
"document",
")",
";",
"}",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"Events",
"::",
"preUpdate",
",",
"new",
"PreUpdateEventArgs",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"document",
")",
")",
")",
";",
"$",
"this",
"->",
"cascadePreUpdate",
"(",
"$",
"class",
",",
"$",
"document",
")",
";",
"}"
] | Invokes preUpdate callbacks and events for given document cascading them to embedded documents as well. | [
"Invokes",
"preUpdate",
"callbacks",
"and",
"events",
"for",
"given",
"document",
"cascading",
"them",
"to",
"embedded",
"documents",
"as",
"well",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L113-L121 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.cascadePreUpdate | private function cascadePreUpdate(ClassMetadata $class, object $document) : void
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;
foreach ($values as $entry) {
if ($this->uow->isScheduledForInsert($entry) || empty($this->uow->getDocumentChangeSet($entry))) {
continue;
}
$this->preUpdate($this->dm->getClassMetadata(get_class($entry)), $entry);
}
}
} | php | private function cascadePreUpdate(ClassMetadata $class, object $document) : void
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;
foreach ($values as $entry) {
if ($this->uow->isScheduledForInsert($entry) || empty($this->uow->getDocumentChangeSet($entry))) {
continue;
}
$this->preUpdate($this->dm->getClassMetadata(get_class($entry)), $entry);
}
}
} | [
"private",
"function",
"cascadePreUpdate",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"class",
"->",
"getEmbeddedFieldsMappings",
"(",
")",
"as",
"$",
"mapping",
")",
"{",
"$",
"value",
"=",
"$",
"class",
"->",
"reflFields",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"values",
"=",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"ClassMetadata",
"::",
"ONE",
"?",
"[",
"$",
"value",
"]",
":",
"$",
"value",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"uow",
"->",
"isScheduledForInsert",
"(",
"$",
"entry",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"entry",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"preUpdate",
"(",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"entry",
")",
")",
",",
"$",
"entry",
")",
";",
"}",
"}",
"}"
] | Cascades the preUpdate event to embedded documents. | [
"Cascades",
"the",
"preUpdate",
"event",
"to",
"embedded",
"documents",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L126-L142 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.cascadePostUpdate | private function cascadePostUpdate(ClassMetadata $class, object $document) : void
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;
foreach ($values as $entry) {
if (empty($this->uow->getDocumentChangeSet($entry)) && ! $this->uow->hasScheduledCollections($entry)) {
continue;
}
$entryClass = $this->dm->getClassMetadata(get_class($entry));
$event = $this->uow->isScheduledForInsert($entry) ? Events::postPersist : Events::postUpdate;
$entryClass->invokeLifecycleCallbacks($event, $entry, [new LifecycleEventArgs($entry, $this->dm)]);
$this->evm->dispatchEvent($event, new LifecycleEventArgs($entry, $this->dm));
$this->cascadePostUpdate($entryClass, $entry);
}
}
} | php | private function cascadePostUpdate(ClassMetadata $class, object $document) : void
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;
foreach ($values as $entry) {
if (empty($this->uow->getDocumentChangeSet($entry)) && ! $this->uow->hasScheduledCollections($entry)) {
continue;
}
$entryClass = $this->dm->getClassMetadata(get_class($entry));
$event = $this->uow->isScheduledForInsert($entry) ? Events::postPersist : Events::postUpdate;
$entryClass->invokeLifecycleCallbacks($event, $entry, [new LifecycleEventArgs($entry, $this->dm)]);
$this->evm->dispatchEvent($event, new LifecycleEventArgs($entry, $this->dm));
$this->cascadePostUpdate($entryClass, $entry);
}
}
} | [
"private",
"function",
"cascadePostUpdate",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"class",
"->",
"getEmbeddedFieldsMappings",
"(",
")",
"as",
"$",
"mapping",
")",
"{",
"$",
"value",
"=",
"$",
"class",
"->",
"reflFields",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"values",
"=",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"ClassMetadata",
"::",
"ONE",
"?",
"[",
"$",
"value",
"]",
":",
"$",
"value",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"uow",
"->",
"getDocumentChangeSet",
"(",
"$",
"entry",
")",
")",
"&&",
"!",
"$",
"this",
"->",
"uow",
"->",
"hasScheduledCollections",
"(",
"$",
"entry",
")",
")",
"{",
"continue",
";",
"}",
"$",
"entryClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"entry",
")",
")",
";",
"$",
"event",
"=",
"$",
"this",
"->",
"uow",
"->",
"isScheduledForInsert",
"(",
"$",
"entry",
")",
"?",
"Events",
"::",
"postPersist",
":",
"Events",
"::",
"postUpdate",
";",
"$",
"entryClass",
"->",
"invokeLifecycleCallbacks",
"(",
"$",
"event",
",",
"$",
"entry",
",",
"[",
"new",
"LifecycleEventArgs",
"(",
"$",
"entry",
",",
"$",
"this",
"->",
"dm",
")",
"]",
")",
";",
"$",
"this",
"->",
"evm",
"->",
"dispatchEvent",
"(",
"$",
"event",
",",
"new",
"LifecycleEventArgs",
"(",
"$",
"entry",
",",
"$",
"this",
"->",
"dm",
")",
")",
";",
"$",
"this",
"->",
"cascadePostUpdate",
"(",
"$",
"entryClass",
",",
"$",
"entry",
")",
";",
"}",
"}",
"}"
] | Cascades the postUpdate and postPersist events to embedded documents. | [
"Cascades",
"the",
"postUpdate",
"and",
"postPersist",
"events",
"to",
"embedded",
"documents",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L147-L168 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php | LifecycleEventManager.cascadePostPersist | private function cascadePostPersist(ClassMetadata $class, object $document) : void
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;
foreach ($values as $embeddedDocument) {
$this->postPersist($this->dm->getClassMetadata(get_class($embeddedDocument)), $embeddedDocument);
}
}
} | php | private function cascadePostPersist(ClassMetadata $class, object $document) : void
{
foreach ($class->getEmbeddedFieldsMappings() as $mapping) {
$value = $class->reflFields[$mapping['fieldName']]->getValue($document);
if ($value === null) {
continue;
}
$values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value;
foreach ($values as $embeddedDocument) {
$this->postPersist($this->dm->getClassMetadata(get_class($embeddedDocument)), $embeddedDocument);
}
}
} | [
"private",
"function",
"cascadePostPersist",
"(",
"ClassMetadata",
"$",
"class",
",",
"object",
"$",
"document",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"class",
"->",
"getEmbeddedFieldsMappings",
"(",
")",
"as",
"$",
"mapping",
")",
"{",
"$",
"value",
"=",
"$",
"class",
"->",
"reflFields",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"$",
"values",
"=",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"ClassMetadata",
"::",
"ONE",
"?",
"[",
"$",
"value",
"]",
":",
"$",
"value",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"embeddedDocument",
")",
"{",
"$",
"this",
"->",
"postPersist",
"(",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"embeddedDocument",
")",
")",
",",
"$",
"embeddedDocument",
")",
";",
"}",
"}",
"}"
] | Cascades the postPersist events to embedded documents. | [
"Cascades",
"the",
"postPersist",
"events",
"to",
"embedded",
"documents",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php#L173-L185 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php | FilterCollection.enable | public function enable(string $name) : BsonFilter
{
if (! $this->has($name)) {
throw new InvalidArgumentException("Filter '" . $name . "' does not exist.");
}
if (! $this->isEnabled($name)) {
$filterClass = $this->config->getFilterClassName($name);
$filterParameters = $this->config->getFilterParameters($name);
$filter = new $filterClass($this->dm);
foreach ($filterParameters as $param => $value) {
$filter->setParameter($param, $value);
}
$this->enabledFilters[$name] = $filter;
}
return $this->enabledFilters[$name];
} | php | public function enable(string $name) : BsonFilter
{
if (! $this->has($name)) {
throw new InvalidArgumentException("Filter '" . $name . "' does not exist.");
}
if (! $this->isEnabled($name)) {
$filterClass = $this->config->getFilterClassName($name);
$filterParameters = $this->config->getFilterParameters($name);
$filter = new $filterClass($this->dm);
foreach ($filterParameters as $param => $value) {
$filter->setParameter($param, $value);
}
$this->enabledFilters[$name] = $filter;
}
return $this->enabledFilters[$name];
} | [
"public",
"function",
"enable",
"(",
"string",
"$",
"name",
")",
":",
"BsonFilter",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Filter '\"",
".",
"$",
"name",
".",
"\"' does not exist.\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isEnabled",
"(",
"$",
"name",
")",
")",
"{",
"$",
"filterClass",
"=",
"$",
"this",
"->",
"config",
"->",
"getFilterClassName",
"(",
"$",
"name",
")",
";",
"$",
"filterParameters",
"=",
"$",
"this",
"->",
"config",
"->",
"getFilterParameters",
"(",
"$",
"name",
")",
";",
"$",
"filter",
"=",
"new",
"$",
"filterClass",
"(",
"$",
"this",
"->",
"dm",
")",
";",
"foreach",
"(",
"$",
"filterParameters",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"$",
"filter",
"->",
"setParameter",
"(",
"$",
"param",
",",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"enabledFilters",
"[",
"$",
"name",
"]",
"=",
"$",
"filter",
";",
"}",
"return",
"$",
"this",
"->",
"enabledFilters",
"[",
"$",
"name",
"]",
";",
"}"
] | Enables a filter from the collection.
@throws InvalidArgumentException If the filter does not exist. | [
"Enables",
"a",
"filter",
"from",
"the",
"collection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php#L71-L90 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php | FilterCollection.disable | public function disable(string $name) : BsonFilter
{
// Get the filter to return it
$filter = $this->getFilter($name);
unset($this->enabledFilters[$name]);
return $filter;
} | php | public function disable(string $name) : BsonFilter
{
$filter = $this->getFilter($name);
unset($this->enabledFilters[$name]);
return $filter;
} | [
"public",
"function",
"disable",
"(",
"string",
"$",
"name",
")",
":",
"BsonFilter",
"{",
"// Get the filter to return it",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"name",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"enabledFilters",
"[",
"$",
"name",
"]",
")",
";",
"return",
"$",
"filter",
";",
"}"
] | Disables a filter.
@throws InvalidArgumentException If the filter does not exist. | [
"Disables",
"a",
"filter",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php#L97-L105 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php | FilterCollection.getFilter | public function getFilter(string $name) : BsonFilter
{
if (! $this->isEnabled($name)) {
throw new InvalidArgumentException("Filter '" . $name . "' is not enabled.");
}
return $this->enabledFilters[$name];
} | php | public function getFilter(string $name) : BsonFilter
{
if (! $this->isEnabled($name)) {
throw new InvalidArgumentException("Filter '" . $name . "' is not enabled.");
}
return $this->enabledFilters[$name];
} | [
"public",
"function",
"getFilter",
"(",
"string",
"$",
"name",
")",
":",
"BsonFilter",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEnabled",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Filter '\"",
".",
"$",
"name",
".",
"\"' is not enabled.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"enabledFilters",
"[",
"$",
"name",
"]",
";",
"}"
] | Get an enabled filter from the collection.
@throws InvalidArgumentException If the filter is not enabled. | [
"Get",
"an",
"enabled",
"filter",
"from",
"the",
"collection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php#L112-L118 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php | FilterCollection.getFilterCriteria | public function getFilterCriteria(ClassMetadata $class) : array
{
if (empty($this->enabledFilters)) {
return [];
}
return $this->cm->merge(
...array_map(
static function ($filter) use ($class) {
return $filter->addFilterCriteria($class);
},
array_values($this->enabledFilters)
)
);
} | php | public function getFilterCriteria(ClassMetadata $class) : array
{
if (empty($this->enabledFilters)) {
return [];
}
return $this->cm->merge(
...array_map(
static function ($filter) use ($class) {
return $filter->addFilterCriteria($class);
},
array_values($this->enabledFilters)
)
);
} | [
"public",
"function",
"getFilterCriteria",
"(",
"ClassMetadata",
"$",
"class",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"enabledFilters",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"cm",
"->",
"merge",
"(",
"...",
"array_map",
"(",
"static",
"function",
"(",
"$",
"filter",
")",
"use",
"(",
"$",
"class",
")",
"{",
"return",
"$",
"filter",
"->",
"addFilterCriteria",
"(",
"$",
"class",
")",
";",
"}",
",",
"array_values",
"(",
"$",
"this",
"->",
"enabledFilters",
")",
")",
")",
";",
"}"
] | Gets enabled filter criteria. | [
"Gets",
"enabled",
"filter",
"criteria",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/FilterCollection.php#L143-L157 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php | GraphLookup.connectFromField | public function connectFromField(string $connectFromField) : self
{
// No targetClass mapping - simply use field name as is
if (! $this->targetClass) {
$this->connectFromField = $connectFromField;
return $this;
}
// connectFromField doesn't have to be a reference - in this case, just convert the field name
if (! $this->targetClass->hasReference($connectFromField)) {
$this->connectFromField = $this->convertTargetFieldName($connectFromField);
return $this;
}
// connectFromField is a reference - do a sanity check
$referenceMapping = $this->targetClass->getFieldMapping($connectFromField);
if ($referenceMapping['targetDocument'] !== $this->targetClass->name) {
throw MappingException::connectFromFieldMustReferenceSameDocument($connectFromField);
}
$this->connectFromField = $this->getReferencedFieldName($connectFromField, $referenceMapping);
return $this;
} | php | public function connectFromField(string $connectFromField) : self
{
if (! $this->targetClass) {
$this->connectFromField = $connectFromField;
return $this;
}
if (! $this->targetClass->hasReference($connectFromField)) {
$this->connectFromField = $this->convertTargetFieldName($connectFromField);
return $this;
}
$referenceMapping = $this->targetClass->getFieldMapping($connectFromField);
if ($referenceMapping['targetDocument'] !== $this->targetClass->name) {
throw MappingException::connectFromFieldMustReferenceSameDocument($connectFromField);
}
$this->connectFromField = $this->getReferencedFieldName($connectFromField, $referenceMapping);
return $this;
} | [
"public",
"function",
"connectFromField",
"(",
"string",
"$",
"connectFromField",
")",
":",
"self",
"{",
"// No targetClass mapping - simply use field name as is",
"if",
"(",
"!",
"$",
"this",
"->",
"targetClass",
")",
"{",
"$",
"this",
"->",
"connectFromField",
"=",
"$",
"connectFromField",
";",
"return",
"$",
"this",
";",
"}",
"// connectFromField doesn't have to be a reference - in this case, just convert the field name",
"if",
"(",
"!",
"$",
"this",
"->",
"targetClass",
"->",
"hasReference",
"(",
"$",
"connectFromField",
")",
")",
"{",
"$",
"this",
"->",
"connectFromField",
"=",
"$",
"this",
"->",
"convertTargetFieldName",
"(",
"$",
"connectFromField",
")",
";",
"return",
"$",
"this",
";",
"}",
"// connectFromField is a reference - do a sanity check",
"$",
"referenceMapping",
"=",
"$",
"this",
"->",
"targetClass",
"->",
"getFieldMapping",
"(",
"$",
"connectFromField",
")",
";",
"if",
"(",
"$",
"referenceMapping",
"[",
"'targetDocument'",
"]",
"!==",
"$",
"this",
"->",
"targetClass",
"->",
"name",
")",
"{",
"throw",
"MappingException",
"::",
"connectFromFieldMustReferenceSameDocument",
"(",
"$",
"connectFromField",
")",
";",
"}",
"$",
"this",
"->",
"connectFromField",
"=",
"$",
"this",
"->",
"getReferencedFieldName",
"(",
"$",
"connectFromField",
",",
"$",
"referenceMapping",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Field name whose value $graphLookup uses to recursively match against the
connectToField of other documents in the collection.
Optionally, connectFromField may be an array of field names, each of
which is individually followed through the traversal process. | [
"Field",
"name",
"whose",
"value",
"$graphLookup",
"uses",
"to",
"recursively",
"match",
"against",
"the",
"connectToField",
"of",
"other",
"documents",
"in",
"the",
"collection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php#L91-L113 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php | GraphLookup.connectToField | public function connectToField(string $connectToField) : self
{
$this->connectToField = $this->convertTargetFieldName($connectToField);
return $this;
} | php | public function connectToField(string $connectToField) : self
{
$this->connectToField = $this->convertTargetFieldName($connectToField);
return $this;
} | [
"public",
"function",
"connectToField",
"(",
"string",
"$",
"connectToField",
")",
":",
"self",
"{",
"$",
"this",
"->",
"connectToField",
"=",
"$",
"this",
"->",
"convertTargetFieldName",
"(",
"$",
"connectToField",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Field name in other documents against which to match the value of the
field specified by the connectFromField parameter. | [
"Field",
"name",
"in",
"other",
"documents",
"against",
"which",
"to",
"match",
"the",
"value",
"of",
"the",
"field",
"specified",
"by",
"the",
"connectFromField",
"parameter",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php#L119-L123 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php | GraphLookup.from | public function from(string $from) : self
{
// $from can either be
// a) a field name indicating a reference to a different document. Currently, only REFERENCE_STORE_AS_ID is supported
// b) a Class name
// c) a collection name
// In cases b) and c) the local and foreign fields need to be filled
if ($this->class->hasReference($from)) {
return $this->fromReference($from);
}
// Check if mapped class with given name exists
try {
$this->targetClass = $this->dm->getClassMetadata($from);
} catch (BaseMappingException $e) {
$this->from = $from;
return $this;
}
if ($this->targetClass->isSharded()) {
throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name);
}
$this->from = $this->targetClass->getCollection();
return $this;
} | php | public function from(string $from) : self
{
if ($this->class->hasReference($from)) {
return $this->fromReference($from);
}
try {
$this->targetClass = $this->dm->getClassMetadata($from);
} catch (BaseMappingException $e) {
$this->from = $from;
return $this;
}
if ($this->targetClass->isSharded()) {
throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name);
}
$this->from = $this->targetClass->getCollection();
return $this;
} | [
"public",
"function",
"from",
"(",
"string",
"$",
"from",
")",
":",
"self",
"{",
"// $from can either be",
"// a) a field name indicating a reference to a different document. Currently, only REFERENCE_STORE_AS_ID is supported",
"// b) a Class name",
"// c) a collection name",
"// In cases b) and c) the local and foreign fields need to be filled",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"hasReference",
"(",
"$",
"from",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fromReference",
"(",
"$",
"from",
")",
";",
"}",
"// Check if mapped class with given name exists",
"try",
"{",
"$",
"this",
"->",
"targetClass",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"from",
")",
";",
"}",
"catch",
"(",
"BaseMappingException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"from",
"=",
"$",
"from",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"targetClass",
"->",
"isSharded",
"(",
")",
")",
"{",
"throw",
"MappingException",
"::",
"cannotUseShardedCollectionInLookupStages",
"(",
"$",
"this",
"->",
"targetClass",
"->",
"name",
")",
";",
"}",
"$",
"this",
"->",
"from",
"=",
"$",
"this",
"->",
"targetClass",
"->",
"getCollection",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Target collection for the $graphLookup operation to search, recursively
matching the connectFromField to the connectToField.
The from collection cannot be sharded and must be in the same database as
any other collections used in the operation. | [
"Target",
"collection",
"for",
"the",
"$graphLookup",
"operation",
"to",
"search",
"recursively",
"matching",
"the",
"connectFromField",
"to",
"the",
"connectToField",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php#L146-L171 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php | GraphLookup.getExpression | public function getExpression() : array
{
$restrictSearchWithMatch = $this->restrictSearchWithMatch->getExpression() ?: (object) [];
$graphLookup = [
'from' => $this->from,
'startWith' => $this->convertExpression($this->startWith),
'connectFromField' => $this->connectFromField,
'connectToField' => $this->connectToField,
'as' => $this->as,
'restrictSearchWithMatch' => $restrictSearchWithMatch,
'maxDepth' => $this->maxDepth,
'depthField' => $this->depthField,
];
foreach (['maxDepth', 'depthField'] as $field) {
if ($graphLookup[$field] !== null) {
continue;
}
unset($graphLookup[$field]);
}
return ['$graphLookup' => $graphLookup];
} | php | public function getExpression() : array
{
$restrictSearchWithMatch = $this->restrictSearchWithMatch->getExpression() ?: (object) [];
$graphLookup = [
'from' => $this->from,
'startWith' => $this->convertExpression($this->startWith),
'connectFromField' => $this->connectFromField,
'connectToField' => $this->connectToField,
'as' => $this->as,
'restrictSearchWithMatch' => $restrictSearchWithMatch,
'maxDepth' => $this->maxDepth,
'depthField' => $this->depthField,
];
foreach (['maxDepth', 'depthField'] as $field) {
if ($graphLookup[$field] !== null) {
continue;
}
unset($graphLookup[$field]);
}
return ['$graphLookup' => $graphLookup];
} | [
"public",
"function",
"getExpression",
"(",
")",
":",
"array",
"{",
"$",
"restrictSearchWithMatch",
"=",
"$",
"this",
"->",
"restrictSearchWithMatch",
"->",
"getExpression",
"(",
")",
"?",
":",
"(",
"object",
")",
"[",
"]",
";",
"$",
"graphLookup",
"=",
"[",
"'from'",
"=>",
"$",
"this",
"->",
"from",
",",
"'startWith'",
"=>",
"$",
"this",
"->",
"convertExpression",
"(",
"$",
"this",
"->",
"startWith",
")",
",",
"'connectFromField'",
"=>",
"$",
"this",
"->",
"connectFromField",
",",
"'connectToField'",
"=>",
"$",
"this",
"->",
"connectToField",
",",
"'as'",
"=>",
"$",
"this",
"->",
"as",
",",
"'restrictSearchWithMatch'",
"=>",
"$",
"restrictSearchWithMatch",
",",
"'maxDepth'",
"=>",
"$",
"this",
"->",
"maxDepth",
",",
"'depthField'",
"=>",
"$",
"this",
"->",
"depthField",
",",
"]",
";",
"foreach",
"(",
"[",
"'maxDepth'",
",",
"'depthField'",
"]",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"graphLookup",
"[",
"$",
"field",
"]",
"!==",
"null",
")",
"{",
"continue",
";",
"}",
"unset",
"(",
"$",
"graphLookup",
"[",
"$",
"field",
"]",
")",
";",
"}",
"return",
"[",
"'$graphLookup'",
"=>",
"$",
"graphLookup",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php#L176-L200 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.add | public function add($expression1, $expression2, ...$expressions) : self
{
$this->expr->add(...func_get_args());
return $this;
} | php | public function add($expression1, $expression2, ...$expressions) : self
{
$this->expr->add(...func_get_args());
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"expression1",
",",
"$",
"expression2",
",",
"...",
"$",
"expressions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"add",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds numbers together or adds numbers and a date. If one of the arguments
is a date, $add treats the other arguments as milliseconds to add to the
date.
The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/add/
@see Expr::add
@param mixed|Expr $expression1
@param mixed|Expr $expression2
@param mixed|Expr ...$expressions Additional expressions | [
"Adds",
"numbers",
"together",
"or",
"adds",
"numbers",
"and",
"a",
"date",
".",
"If",
"one",
"of",
"the",
"arguments",
"is",
"a",
"date",
"$add",
"treats",
"the",
"other",
"arguments",
"as",
"milliseconds",
"to",
"add",
"to",
"the",
"date",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L74-L79 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.cmp | public function cmp($expression1, $expression2) : self
{
$this->expr->cmp($expression1, $expression2);
return $this;
} | php | public function cmp($expression1, $expression2) : self
{
$this->expr->cmp($expression1, $expression2);
return $this;
} | [
"public",
"function",
"cmp",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"cmp",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns:
-1 if the first value is less than the second.
1 if the first value is greater than the second.
0 if the two values are equivalent.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/cmp/
@see Expr::cmp
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
":",
"-",
"1",
"if",
"the",
"first",
"value",
"is",
"less",
"than",
"the",
"second",
".",
"1",
"if",
"the",
"first",
"value",
"is",
"greater",
"than",
"the",
"second",
".",
"0",
"if",
"the",
"two",
"values",
"are",
"equivalent",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L200-L205 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.concat | public function concat($expression1, $expression2, ...$expressions) : self
{
$this->expr->concat(...func_get_args());
return $this;
} | php | public function concat($expression1, $expression2, ...$expressions) : self
{
$this->expr->concat(...func_get_args());
return $this;
} | [
"public",
"function",
"concat",
"(",
"$",
"expression1",
",",
"$",
"expression2",
",",
"...",
"$",
"expressions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"concat",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Concatenates strings and returns the concatenated string.
The arguments can be any valid expression as long as they resolve to
strings. If the argument resolves to a value of null or refers to a field
that is missing, $concat returns null.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/concat/
@see Expr::concat
@param mixed|Expr $expression1
@param mixed|Expr $expression2
@param mixed|Expr ...$expressions Additional expressions | [
"Concatenates",
"strings",
"and",
"returns",
"the",
"concatenated",
"string",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L221-L226 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.concatArrays | public function concatArrays($array1, $array2, ...$arrays) : self
{
$this->expr->concatArrays(...func_get_args());
return $this;
} | php | public function concatArrays($array1, $array2, ...$arrays) : self
{
$this->expr->concatArrays(...func_get_args());
return $this;
} | [
"public",
"function",
"concatArrays",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"...",
"$",
"arrays",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"concatArrays",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Concatenates arrays to return the concatenated array.
The <array> expressions can be any valid expression as long as they
resolve to an array.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/concatArrays/
@see Expr::concatArrays
@param mixed|Expr $array1
@param mixed|Expr $array2
@param mixed|Expr ...$arrays Additional expressions | [
"Concatenates",
"arrays",
"to",
"return",
"the",
"concatenated",
"array",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L241-L246 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.dateToString | public function dateToString($format, $expression) : self
{
$this->expr->dateToString($format, $expression);
return $this;
} | php | public function dateToString($format, $expression) : self
{
$this->expr->dateToString($format, $expression);
return $this;
} | [
"public",
"function",
"dateToString",
"(",
"$",
"format",
",",
"$",
"expression",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"dateToString",
"(",
"$",
"format",
",",
"$",
"expression",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Converts a date object to a string according to a user-specified format.
The format string can be any string literal, containing 0 or more format
specifiers.
The date argument can be any expression as long as it resolves to a date.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/dateToString/
@see Expr::dateToString
@param string $format
@param mixed|Expr $expression | [
"Converts",
"a",
"date",
"object",
"to",
"a",
"string",
"according",
"to",
"a",
"user",
"-",
"specified",
"format",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L281-L286 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.divide | public function divide($expression1, $expression2) : self
{
$this->expr->divide($expression1, $expression2);
return $this;
} | php | public function divide($expression1, $expression2) : self
{
$this->expr->divide($expression1, $expression2);
return $this;
} | [
"public",
"function",
"divide",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"divide",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Divides one number by another and returns the result. The first argument
is divided by the second argument.
The arguments can be any valid expression as long as the resolve to numbers.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/divide/
@see Expr::divide
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Divides",
"one",
"number",
"by",
"another",
"and",
"returns",
"the",
"result",
".",
"The",
"first",
"argument",
"is",
"divided",
"by",
"the",
"second",
"argument",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L352-L357 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.eq | public function eq($expression1, $expression2) : self
{
$this->expr->eq($expression1, $expression2);
return $this;
} | php | public function eq($expression1, $expression2) : self
{
$this->expr->eq($expression1, $expression2);
return $this;
} | [
"public",
"function",
"eq",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"eq",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns whether they are equivalent.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/eq/
@see Expr::eq
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
"whether",
"they",
"are",
"equivalent",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L368-L373 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.gt | public function gt($expression1, $expression2) : self
{
$this->expr->gt($expression1, $expression2);
return $this;
} | php | public function gt($expression1, $expression2) : self
{
$this->expr->gt($expression1, $expression2);
return $this;
} | [
"public",
"function",
"gt",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"gt",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns:
true when the first value is greater than the second value.
false when the first value is less than or equivalent to the second value.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/gt/
@see Expr::gt
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
":",
"true",
"when",
"the",
"first",
"value",
"is",
"greater",
"than",
"the",
"second",
"value",
".",
"false",
"when",
"the",
"first",
"value",
"is",
"less",
"than",
"or",
"equivalent",
"to",
"the",
"second",
"value",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L469-L474 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.gte | public function gte($expression1, $expression2) : self
{
$this->expr->gte($expression1, $expression2);
return $this;
} | php | public function gte($expression1, $expression2) : self
{
$this->expr->gte($expression1, $expression2);
return $this;
} | [
"public",
"function",
"gte",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"gte",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns:
true when the first value is greater than or equivalent to the second value.
false when the first value is less than the second value.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/gte/
@see Expr::gte
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
":",
"true",
"when",
"the",
"first",
"value",
"is",
"greater",
"than",
"or",
"equivalent",
"to",
"the",
"second",
"value",
".",
"false",
"when",
"the",
"first",
"value",
"is",
"less",
"than",
"the",
"second",
"value",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L487-L492 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.in | public function in($expression, $arrayExpression) : self
{
$this->expr->in($expression, $arrayExpression);
return $this;
} | php | public function in($expression, $arrayExpression) : self
{
$this->expr->in($expression, $arrayExpression);
return $this;
} | [
"public",
"function",
"in",
"(",
"$",
"expression",
",",
"$",
"arrayExpression",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"in",
"(",
"$",
"expression",
",",
"$",
"arrayExpression",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Returns a boolean indicating whether a specified value is in an array.
Unlike the $in query operator, the aggregation $in operator does not
support matching by regular expressions.
@see https://docs.mongodb.com/manual/reference/operator/aggregation/in/
@see Expr::in
@param mixed|Expr $expression
@param mixed|Expr $arrayExpression | [
"Returns",
"a",
"boolean",
"indicating",
"whether",
"a",
"specified",
"value",
"is",
"in",
"an",
"array",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L523-L528 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.indexOfArray | public function indexOfArray($arrayExpression, $searchExpression, $start = null, $end = null) : self
{
$this->expr->indexOfArray($arrayExpression, $searchExpression, $start, $end);
return $this;
} | php | public function indexOfArray($arrayExpression, $searchExpression, $start = null, $end = null) : self
{
$this->expr->indexOfArray($arrayExpression, $searchExpression, $start, $end);
return $this;
} | [
"public",
"function",
"indexOfArray",
"(",
"$",
"arrayExpression",
",",
"$",
"searchExpression",
",",
"$",
"start",
"=",
"null",
",",
"$",
"end",
"=",
"null",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"indexOfArray",
"(",
"$",
"arrayExpression",
",",
"$",
"searchExpression",
",",
"$",
"start",
",",
"$",
"end",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Searches an array for an occurrence of a specified value and returns the
array index (zero-based) of the first occurrence. If the value is not
found, returns -1.
@see https://docs.mongodb.com/manual/reference/operator/aggregation/indexOfArray/
@see Expr::indexOfArray
@param mixed|Expr $arrayExpression Can be any valid expression as long as it resolves to an array.
@param mixed|Expr $searchExpression Can be any valid expression.
@param mixed|Expr $start Optional. An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number.
@param mixed|Expr $end An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. | [
"Searches",
"an",
"array",
"for",
"an",
"occurrence",
"of",
"a",
"specified",
"value",
"and",
"returns",
"the",
"array",
"index",
"(",
"zero",
"-",
"based",
")",
"of",
"the",
"first",
"occurrence",
".",
"If",
"the",
"value",
"is",
"not",
"found",
"returns",
"-",
"1",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L543-L548 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.ifNull | public function ifNull($expression, $replacementExpression) : self
{
$this->expr->ifNull($expression, $replacementExpression);
return $this;
} | php | public function ifNull($expression, $replacementExpression) : self
{
$this->expr->ifNull($expression, $replacementExpression);
return $this;
} | [
"public",
"function",
"ifNull",
"(",
"$",
"expression",
",",
"$",
"replacementExpression",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"ifNull",
"(",
"$",
"expression",
",",
"$",
"replacementExpression",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Evaluates an expression and returns the value of the expression if the
expression evaluates to a non-null value. If the expression evaluates to
a null value, including instances of undefined values or missing fields,
returns the value of the replacement expression.
The arguments can be any valid expression.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/ifNull/
@see Expr::ifNull
@param mixed|Expr $expression
@param mixed|Expr $replacementExpression | [
"Evaluates",
"an",
"expression",
"and",
"returns",
"the",
"value",
"of",
"the",
"expression",
"if",
"the",
"expression",
"evaluates",
"to",
"a",
"non",
"-",
"null",
"value",
".",
"If",
"the",
"expression",
"evaluates",
"to",
"a",
"null",
"value",
"including",
"instances",
"of",
"undefined",
"values",
"or",
"missing",
"fields",
"returns",
"the",
"value",
"of",
"the",
"replacement",
"expression",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L602-L607 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.let | public function let($vars, $in) : self
{
$this->expr->let($vars, $in);
return $this;
} | php | public function let($vars, $in) : self
{
$this->expr->let($vars, $in);
return $this;
} | [
"public",
"function",
"let",
"(",
"$",
"vars",
",",
"$",
"in",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"let",
"(",
"$",
"vars",
",",
"$",
"in",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Binds variables for use in the specified expression, and returns the
result of the expression.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/let/
@see Expr::let
@param mixed|Expr $vars Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value.
@param mixed|Expr $in The expression to evaluate. | [
"Binds",
"variables",
"for",
"use",
"in",
"the",
"specified",
"expression",
"and",
"returns",
"the",
"result",
"of",
"the",
"expression",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L691-L696 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.log | public function log($number, $base) : self
{
$this->expr->log($number, $base);
return $this;
} | php | public function log($number, $base) : self
{
$this->expr->log($number, $base);
return $this;
} | [
"public",
"function",
"log",
"(",
"$",
"number",
",",
"$",
"base",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"log",
"(",
"$",
"number",
",",
"$",
"base",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Calculates the log of a number in the specified base and returns the
result as a double.
The <number> expression can be any valid expression as long as it
resolves to a non-negative number.
The <base> expression can be any valid expression as long as it resolves
to a positive number greater than 1.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/log/
@see Expr::log
@param mixed|Expr $number
@param mixed|Expr $base | [
"Calculates",
"the",
"log",
"of",
"a",
"number",
"in",
"the",
"specified",
"base",
"and",
"returns",
"the",
"result",
"as",
"a",
"double",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L748-L753 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.lt | public function lt($expression1, $expression2) : self
{
$this->expr->lt($expression1, $expression2);
return $this;
} | php | public function lt($expression1, $expression2) : self
{
$this->expr->lt($expression1, $expression2);
return $this;
} | [
"public",
"function",
"lt",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"lt",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns:
true when the first value is less than the second value.
false when the first value is greater than or equivalent to the second value.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/lt/
@see Expr::lt
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
":",
"true",
"when",
"the",
"first",
"value",
"is",
"less",
"than",
"the",
"second",
"value",
".",
"false",
"when",
"the",
"first",
"value",
"is",
"greater",
"than",
"or",
"equivalent",
"to",
"the",
"second",
"value",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L786-L791 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.lte | public function lte($expression1, $expression2) : self
{
$this->expr->lte($expression1, $expression2);
return $this;
} | php | public function lte($expression1, $expression2) : self
{
$this->expr->lte($expression1, $expression2);
return $this;
} | [
"public",
"function",
"lte",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"lte",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns:
true when the first value is less than or equivalent to the second value.
false when the first value is greater than the second value.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/lte/
@see Expr::lte
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
":",
"true",
"when",
"the",
"first",
"value",
"is",
"less",
"than",
"or",
"equivalent",
"to",
"the",
"second",
"value",
".",
"false",
"when",
"the",
"first",
"value",
"is",
"greater",
"than",
"the",
"second",
"value",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L804-L809 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.map | public function map($input, $as, $in) : self
{
$this->expr->map($input, $as, $in);
return $this;
} | php | public function map($input, $as, $in) : self
{
$this->expr->map($input, $as, $in);
return $this;
} | [
"public",
"function",
"map",
"(",
"$",
"input",
",",
"$",
"as",
",",
"$",
"in",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"map",
"(",
"$",
"input",
",",
"$",
"as",
",",
"$",
"in",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Applies an expression to each item in an array and returns an array with
the applied results.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/map/
@see Expr::map
@param mixed|Expr $input An expression that resolves to an array.
@param string $as The variable name for the items in the input array. The in expression accesses each item in the input array by this variable.
@param mixed|Expr $in The expression to apply to each item in the input array. The expression accesses the item by its variable name. | [
"Applies",
"an",
"expression",
"to",
"each",
"item",
"in",
"an",
"array",
"and",
"returns",
"an",
"array",
"with",
"the",
"applied",
"results",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L822-L827 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.mod | public function mod($expression1, $expression2) : self
{
$this->expr->mod($expression1, $expression2);
return $this;
} | php | public function mod($expression1, $expression2) : self
{
$this->expr->mod($expression1, $expression2);
return $this;
} | [
"public",
"function",
"mod",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"mod",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Divides one number by another and returns the remainder. The first
argument is divided by the second argument.
The arguments can be any valid expression as long as they resolve to numbers.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/mod/
@see Expr::mod
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Divides",
"one",
"number",
"by",
"another",
"and",
"returns",
"the",
"remainder",
".",
"The",
"first",
"argument",
"is",
"divided",
"by",
"the",
"second",
"argument",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L890-L895 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.multiply | public function multiply($expression1, $expression2, ...$expressions) : self
{
$this->expr->multiply(...func_get_args());
return $this;
} | php | public function multiply($expression1, $expression2, ...$expressions) : self
{
$this->expr->multiply(...func_get_args());
return $this;
} | [
"public",
"function",
"multiply",
"(",
"$",
"expression1",
",",
"$",
"expression2",
",",
"...",
"$",
"expressions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"multiply",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Multiplies numbers together and returns the result.
The arguments can be any valid expression as long as they resolve to numbers.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/multiply/
@see Expr::multiply
@param mixed|Expr $expression1
@param mixed|Expr $expression2
@param mixed|Expr ...$expressions Additional expressions | [
"Multiplies",
"numbers",
"together",
"and",
"returns",
"the",
"result",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L926-L931 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.ne | public function ne($expression1, $expression2) : self
{
$this->expr->ne($expression1, $expression2);
return $this;
} | php | public function ne($expression1, $expression2) : self
{
$this->expr->ne($expression1, $expression2);
return $this;
} | [
"public",
"function",
"ne",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"ne",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Compares two values and returns:
true when the values are not equivalent.
false when the values are equivalent.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/ne/
@see Expr::ne
@param mixed|Expr $expression1
@param mixed|Expr $expression2 | [
"Compares",
"two",
"values",
"and",
"returns",
":",
"true",
"when",
"the",
"values",
"are",
"not",
"equivalent",
".",
"false",
"when",
"the",
"values",
"are",
"equivalent",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L944-L949 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php | Operator.pow | public function pow($number, $exponent) : self
{
$this->expr->pow($number, $exponent);
return $this;
} | php | public function pow($number, $exponent) : self
{
$this->expr->pow($number, $exponent);
return $this;
} | [
"public",
"function",
"pow",
"(",
"$",
"number",
",",
"$",
"exponent",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"pow",
"(",
"$",
"number",
",",
"$",
"exponent",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Raises a number to the specified exponent and returns the result.
The <number> expression can be any valid expression as long as it
resolves to a non-negative number.
The <exponent> expression can be any valid expression as long as it
resolves to a number.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/pow/
@see Expr::pow
@param mixed|Expr $number
@param mixed|Expr $exponent | [
"Raises",
"a",
"number",
"to",
"the",
"specified",
"exponent",
"and",
"returns",
"the",
"result",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L980-L985 |