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/Mapping/ClassMetadata.php | ClassMetadata.setDefaultDiscriminatorValue | public function setDefaultDiscriminatorValue(?string $defaultDiscriminatorValue) : void
{
if ($this->isFile) {
throw MappingException::discriminatorNotAllowedForGridFS($this->name);
}
if ($defaultDiscriminatorValue === null) {
$this->defaultDiscriminatorValue = null;
return;
}
if (! array_key_exists($defaultDiscriminatorValue, $this->discriminatorMap)) {
throw MappingException::invalidDiscriminatorValue($defaultDiscriminatorValue, $this->name);
}
$this->defaultDiscriminatorValue = $defaultDiscriminatorValue;
} | php | public function setDefaultDiscriminatorValue(?string $defaultDiscriminatorValue) : void
{
if ($this->isFile) {
throw MappingException::discriminatorNotAllowedForGridFS($this->name);
}
if ($defaultDiscriminatorValue === null) {
$this->defaultDiscriminatorValue = null;
return;
}
if (! array_key_exists($defaultDiscriminatorValue, $this->discriminatorMap)) {
throw MappingException::invalidDiscriminatorValue($defaultDiscriminatorValue, $this->name);
}
$this->defaultDiscriminatorValue = $defaultDiscriminatorValue;
} | [
"public",
"function",
"setDefaultDiscriminatorValue",
"(",
"?",
"string",
"$",
"defaultDiscriminatorValue",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"isFile",
")",
"{",
"throw",
"MappingException",
"::",
"discriminatorNotAllowedForGridFS",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"if",
"(",
"$",
"defaultDiscriminatorValue",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultDiscriminatorValue",
"=",
"null",
";",
"return",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"defaultDiscriminatorValue",
",",
"$",
"this",
"->",
"discriminatorMap",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidDiscriminatorValue",
"(",
"$",
"defaultDiscriminatorValue",
",",
"$",
"this",
"->",
"name",
")",
";",
"}",
"$",
"this",
"->",
"defaultDiscriminatorValue",
"=",
"$",
"defaultDiscriminatorValue",
";",
"}"
] | Sets the default discriminator value to be used for this class
Used for SINGLE_TABLE inheritance mapping strategies if the document has no discriminator value
@throws MappingException | [
"Sets",
"the",
"default",
"discriminator",
"value",
"to",
"be",
"used",
"for",
"this",
"class",
"Used",
"for",
"SINGLE_TABLE",
"inheritance",
"mapping",
"strategies",
"if",
"the",
"document",
"has",
"no",
"discriminator",
"value"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L812-L829 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setDiscriminatorValue | public function setDiscriminatorValue(string $value) : void
{
if ($this->isFile) {
throw MappingException::discriminatorNotAllowedForGridFS($this->name);
}
$this->discriminatorMap[$value] = $this->name;
$this->discriminatorValue = $value;
} | php | public function setDiscriminatorValue(string $value) : void
{
if ($this->isFile) {
throw MappingException::discriminatorNotAllowedForGridFS($this->name);
}
$this->discriminatorMap[$value] = $this->name;
$this->discriminatorValue = $value;
} | [
"public",
"function",
"setDiscriminatorValue",
"(",
"string",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"isFile",
")",
"{",
"throw",
"MappingException",
"::",
"discriminatorNotAllowedForGridFS",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"$",
"this",
"->",
"discriminatorMap",
"[",
"$",
"value",
"]",
"=",
"$",
"this",
"->",
"name",
";",
"$",
"this",
"->",
"discriminatorValue",
"=",
"$",
"value",
";",
"}"
] | Sets the discriminator value for this class.
Used for JOINED/SINGLE_TABLE inheritance and multiple document types in a single
collection.
@throws MappingException | [
"Sets",
"the",
"discriminator",
"value",
"for",
"this",
"class",
".",
"Used",
"for",
"JOINED",
"/",
"SINGLE_TABLE",
"inheritance",
"and",
"multiple",
"document",
"types",
"in",
"a",
"single",
"collection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L838-L846 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.addIndex | public function addIndex(array $keys, array $options = []) : void
{
$this->indexes[] = [
'keys' => array_map(static function ($value) {
if ($value === 1 || $value === -1) {
return $value;
}
if (is_string($value)) {
$lower = strtolower($value);
if ($lower === 'asc') {
return 1;
}
if ($lower === 'desc') {
return -1;
}
}
return $value;
}, $keys),
'options' => $options,
];
} | php | public function addIndex(array $keys, array $options = []) : void
{
$this->indexes[] = [
'keys' => array_map(static function ($value) {
if ($value === 1 || $value === -1) {
return $value;
}
if (is_string($value)) {
$lower = strtolower($value);
if ($lower === 'asc') {
return 1;
}
if ($lower === 'desc') {
return -1;
}
}
return $value;
}, $keys),
'options' => $options,
];
} | [
"public",
"function",
"addIndex",
"(",
"array",
"$",
"keys",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"this",
"->",
"indexes",
"[",
"]",
"=",
"[",
"'keys'",
"=>",
"array_map",
"(",
"static",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"1",
"||",
"$",
"value",
"===",
"-",
"1",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"lower",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"lower",
"===",
"'asc'",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"$",
"lower",
"===",
"'desc'",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}",
",",
"$",
"keys",
")",
",",
"'options'",
"=>",
"$",
"options",
",",
"]",
";",
"}"
] | Add a index for this Document. | [
"Add",
"a",
"index",
"for",
"this",
"Document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L851-L872 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setShardKey | public function setShardKey(array $keys, array $options = []) : void
{
if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && $this->shardKey !== []) {
throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName());
}
if ($this->isEmbeddedDocument) {
throw MappingException::embeddedDocumentCantHaveShardKey($this->getName());
}
foreach (array_keys($keys) as $field) {
if (! isset($this->fieldMappings[$field])) {
continue;
}
if (in_array($this->fieldMappings[$field]['type'], ['many', 'collection'])) {
throw MappingException::noMultiKeyShardKeys($this->getName(), $field);
}
if ($this->fieldMappings[$field]['strategy'] !== static::STORAGE_STRATEGY_SET) {
throw MappingException::onlySetStrategyAllowedInShardKey($this->getName(), $field);
}
}
$this->shardKey = [
'keys' => array_map(static function ($value) {
if ($value === 1 || $value === -1) {
return $value;
}
if (is_string($value)) {
$lower = strtolower($value);
if ($lower === 'asc') {
return 1;
}
if ($lower === 'desc') {
return -1;
}
}
return $value;
}, $keys),
'options' => $options,
];
} | php | public function setShardKey(array $keys, array $options = []) : void
{
if ($this->inheritanceType === self::INHERITANCE_TYPE_SINGLE_COLLECTION && $this->shardKey !== []) {
throw MappingException::shardKeyInSingleCollInheritanceSubclass($this->getName());
}
if ($this->isEmbeddedDocument) {
throw MappingException::embeddedDocumentCantHaveShardKey($this->getName());
}
foreach (array_keys($keys) as $field) {
if (! isset($this->fieldMappings[$field])) {
continue;
}
if (in_array($this->fieldMappings[$field]['type'], ['many', 'collection'])) {
throw MappingException::noMultiKeyShardKeys($this->getName(), $field);
}
if ($this->fieldMappings[$field]['strategy'] !== static::STORAGE_STRATEGY_SET) {
throw MappingException::onlySetStrategyAllowedInShardKey($this->getName(), $field);
}
}
$this->shardKey = [
'keys' => array_map(static function ($value) {
if ($value === 1 || $value === -1) {
return $value;
}
if (is_string($value)) {
$lower = strtolower($value);
if ($lower === 'asc') {
return 1;
}
if ($lower === 'desc') {
return -1;
}
}
return $value;
}, $keys),
'options' => $options,
];
} | [
"public",
"function",
"setShardKey",
"(",
"array",
"$",
"keys",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"inheritanceType",
"===",
"self",
"::",
"INHERITANCE_TYPE_SINGLE_COLLECTION",
"&&",
"$",
"this",
"->",
"shardKey",
"!==",
"[",
"]",
")",
"{",
"throw",
"MappingException",
"::",
"shardKeyInSingleCollInheritanceSubclass",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isEmbeddedDocument",
")",
"{",
"throw",
"MappingException",
"::",
"embeddedDocumentCantHaveShardKey",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"keys",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"field",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"field",
"]",
"[",
"'type'",
"]",
",",
"[",
"'many'",
",",
"'collection'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"noMultiKeyShardKeys",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"field",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"field",
"]",
"[",
"'strategy'",
"]",
"!==",
"static",
"::",
"STORAGE_STRATEGY_SET",
")",
"{",
"throw",
"MappingException",
"::",
"onlySetStrategyAllowedInShardKey",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
",",
"$",
"field",
")",
";",
"}",
"}",
"$",
"this",
"->",
"shardKey",
"=",
"[",
"'keys'",
"=>",
"array_map",
"(",
"static",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"1",
"||",
"$",
"value",
"===",
"-",
"1",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"lower",
"=",
"strtolower",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"lower",
"===",
"'asc'",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"$",
"lower",
"===",
"'desc'",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}",
",",
"$",
"keys",
")",
",",
"'options'",
"=>",
"$",
"options",
",",
"]",
";",
"}"
] | Set shard key for this Document.
@throws MappingException | [
"Set",
"shard",
"key",
"for",
"this",
"Document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L895-L938 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setReadPreference | public function setReadPreference(?string $readPreference, array $tags) : void
{
$this->readPreference = $readPreference;
$this->readPreferenceTags = $tags;
} | php | public function setReadPreference(?string $readPreference, array $tags) : void
{
$this->readPreference = $readPreference;
$this->readPreferenceTags = $tags;
} | [
"public",
"function",
"setReadPreference",
"(",
"?",
"string",
"$",
"readPreference",
",",
"array",
"$",
"tags",
")",
":",
"void",
"{",
"$",
"this",
"->",
"readPreference",
"=",
"$",
"readPreference",
";",
"$",
"this",
"->",
"readPreferenceTags",
"=",
"$",
"tags",
";",
"}"
] | Sets the read preference used by this class. | [
"Sets",
"the",
"read",
"preference",
"used",
"by",
"this",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L956-L960 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setCollection | public function setCollection($name) : void
{
if (is_array($name)) {
if (! isset($name['name'])) {
throw new InvalidArgumentException('A name key is required when passing an array to setCollection()');
}
$this->collectionCapped = $name['capped'] ?? false;
$this->collectionSize = $name['size'] ?? 0;
$this->collectionMax = $name['max'] ?? 0;
$this->collection = $name['name'];
} else {
$this->collection = $name;
}
} | php | public function setCollection($name) : void
{
if (is_array($name)) {
if (! isset($name['name'])) {
throw new InvalidArgumentException('A name key is required when passing an array to setCollection()');
}
$this->collectionCapped = $name['capped'] ?? false;
$this->collectionSize = $name['size'] ?? 0;
$this->collectionMax = $name['max'] ?? 0;
$this->collection = $name['name'];
} else {
$this->collection = $name;
}
} | [
"public",
"function",
"setCollection",
"(",
"$",
"name",
")",
":",
"void",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"name",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'A name key is required when passing an array to setCollection()'",
")",
";",
"}",
"$",
"this",
"->",
"collectionCapped",
"=",
"$",
"name",
"[",
"'capped'",
"]",
"??",
"false",
";",
"$",
"this",
"->",
"collectionSize",
"=",
"$",
"name",
"[",
"'size'",
"]",
"??",
"0",
";",
"$",
"this",
"->",
"collectionMax",
"=",
"$",
"name",
"[",
"'max'",
"]",
"??",
"0",
";",
"$",
"this",
"->",
"collection",
"=",
"$",
"name",
"[",
"'name'",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"collection",
"=",
"$",
"name",
";",
"}",
"}"
] | Sets the collection this Document is mapped to.
@param array|string $name
@throws InvalidArgumentException | [
"Sets",
"the",
"collection",
"this",
"Document",
"is",
"mapped",
"to",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1075-L1088 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.applyStorageStrategy | private function applyStorageStrategy(array &$mapping) : void
{
if (! isset($mapping['type']) || isset($mapping['id'])) {
return;
}
switch (true) {
case $mapping['type'] === 'int':
case $mapping['type'] === 'float':
$defaultStrategy = self::STORAGE_STRATEGY_SET;
$allowedStrategies = [self::STORAGE_STRATEGY_SET, self::STORAGE_STRATEGY_INCREMENT];
break;
case $mapping['type'] === 'many':
$defaultStrategy = CollectionHelper::DEFAULT_STRATEGY;
$allowedStrategies = [
self::STORAGE_STRATEGY_PUSH_ALL,
self::STORAGE_STRATEGY_ADD_TO_SET,
self::STORAGE_STRATEGY_SET,
self::STORAGE_STRATEGY_SET_ARRAY,
self::STORAGE_STRATEGY_ATOMIC_SET,
self::STORAGE_STRATEGY_ATOMIC_SET_ARRAY,
];
break;
default:
$defaultStrategy = self::STORAGE_STRATEGY_SET;
$allowedStrategies = [self::STORAGE_STRATEGY_SET];
}
if (! isset($mapping['strategy'])) {
$mapping['strategy'] = $defaultStrategy;
}
if (! in_array($mapping['strategy'], $allowedStrategies)) {
throw MappingException::invalidStorageStrategy($this->name, $mapping['fieldName'], $mapping['type'], $mapping['strategy']);
}
if (isset($mapping['reference']) && $mapping['type'] === 'many' && $mapping['isOwningSide']
&& ! empty($mapping['sort']) && ! CollectionHelper::usesSet($mapping['strategy'])) {
throw MappingException::referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($this->name, $mapping['fieldName'], $mapping['strategy']);
}
} | php | private function applyStorageStrategy(array &$mapping) : void
{
if (! isset($mapping['type']) || isset($mapping['id'])) {
return;
}
switch (true) {
case $mapping['type'] === 'int':
case $mapping['type'] === 'float':
$defaultStrategy = self::STORAGE_STRATEGY_SET;
$allowedStrategies = [self::STORAGE_STRATEGY_SET, self::STORAGE_STRATEGY_INCREMENT];
break;
case $mapping['type'] === 'many':
$defaultStrategy = CollectionHelper::DEFAULT_STRATEGY;
$allowedStrategies = [
self::STORAGE_STRATEGY_PUSH_ALL,
self::STORAGE_STRATEGY_ADD_TO_SET,
self::STORAGE_STRATEGY_SET,
self::STORAGE_STRATEGY_SET_ARRAY,
self::STORAGE_STRATEGY_ATOMIC_SET,
self::STORAGE_STRATEGY_ATOMIC_SET_ARRAY,
];
break;
default:
$defaultStrategy = self::STORAGE_STRATEGY_SET;
$allowedStrategies = [self::STORAGE_STRATEGY_SET];
}
if (! isset($mapping['strategy'])) {
$mapping['strategy'] = $defaultStrategy;
}
if (! in_array($mapping['strategy'], $allowedStrategies)) {
throw MappingException::invalidStorageStrategy($this->name, $mapping['fieldName'], $mapping['type'], $mapping['strategy']);
}
if (isset($mapping['reference']) && $mapping['type'] === 'many' && $mapping['isOwningSide']
&& ! empty($mapping['sort']) && ! CollectionHelper::usesSet($mapping['strategy'])) {
throw MappingException::referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($this->name, $mapping['fieldName'], $mapping['strategy']);
}
} | [
"private",
"function",
"applyStorageStrategy",
"(",
"array",
"&",
"$",
"mapping",
")",
":",
"void",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
"||",
"isset",
"(",
"$",
"mapping",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
";",
"}",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'int'",
":",
"case",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'float'",
":",
"$",
"defaultStrategy",
"=",
"self",
"::",
"STORAGE_STRATEGY_SET",
";",
"$",
"allowedStrategies",
"=",
"[",
"self",
"::",
"STORAGE_STRATEGY_SET",
",",
"self",
"::",
"STORAGE_STRATEGY_INCREMENT",
"]",
";",
"break",
";",
"case",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
":",
"$",
"defaultStrategy",
"=",
"CollectionHelper",
"::",
"DEFAULT_STRATEGY",
";",
"$",
"allowedStrategies",
"=",
"[",
"self",
"::",
"STORAGE_STRATEGY_PUSH_ALL",
",",
"self",
"::",
"STORAGE_STRATEGY_ADD_TO_SET",
",",
"self",
"::",
"STORAGE_STRATEGY_SET",
",",
"self",
"::",
"STORAGE_STRATEGY_SET_ARRAY",
",",
"self",
"::",
"STORAGE_STRATEGY_ATOMIC_SET",
",",
"self",
"::",
"STORAGE_STRATEGY_ATOMIC_SET_ARRAY",
",",
"]",
";",
"break",
";",
"default",
":",
"$",
"defaultStrategy",
"=",
"self",
"::",
"STORAGE_STRATEGY_SET",
";",
"$",
"allowedStrategies",
"=",
"[",
"self",
"::",
"STORAGE_STRATEGY_SET",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'strategy'",
"]",
"=",
"$",
"defaultStrategy",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
",",
"$",
"allowedStrategies",
")",
")",
"{",
"throw",
"MappingException",
"::",
"invalidStorageStrategy",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
",",
"$",
"mapping",
"[",
"'type'",
"]",
",",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
"&&",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
"&&",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'sort'",
"]",
")",
"&&",
"!",
"CollectionHelper",
"::",
"usesSet",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"referenceManySortMustNotBeUsedWithNonSetCollectionStrategy",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
",",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
";",
"}",
"}"
] | Validates the storage strategy of a mapping for consistency
@throws MappingException | [
"Validates",
"the",
"storage",
"strategy",
"of",
"a",
"mapping",
"for",
"consistency"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1172-L1214 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.addInheritedFieldMapping | public function addInheritedFieldMapping(array $fieldMapping) : void
{
$this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
if (! isset($fieldMapping['association'])) {
return;
}
$this->associationMappings[$fieldMapping['fieldName']] = $fieldMapping;
} | php | public function addInheritedFieldMapping(array $fieldMapping) : void
{
$this->fieldMappings[$fieldMapping['fieldName']] = $fieldMapping;
if (! isset($fieldMapping['association'])) {
return;
}
$this->associationMappings[$fieldMapping['fieldName']] = $fieldMapping;
} | [
"public",
"function",
"addInheritedFieldMapping",
"(",
"array",
"$",
"fieldMapping",
")",
":",
"void",
"{",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldMapping",
"[",
"'fieldName'",
"]",
"]",
"=",
"$",
"fieldMapping",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"fieldMapping",
"[",
"'association'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"associationMappings",
"[",
"$",
"fieldMapping",
"[",
"'fieldName'",
"]",
"]",
"=",
"$",
"fieldMapping",
";",
"}"
] | Adds a field mapping without completing/validating it.
This is mainly used to add inherited field mappings to derived classes.
@internal | [
"Adds",
"a",
"field",
"mapping",
"without",
"completing",
"/",
"validating",
"it",
".",
"This",
"is",
"mainly",
"used",
"to",
"add",
"inherited",
"field",
"mappings",
"to",
"derived",
"classes",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1262-L1271 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.isSingleValuedReference | public function isSingleValuedReference(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::REFERENCE_ONE;
} | php | public function isSingleValuedReference(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::REFERENCE_ONE;
} | [
"public",
"function",
"isSingleValuedReference",
"(",
"string",
"$",
"fieldName",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
")",
"&&",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
"===",
"self",
"::",
"REFERENCE_ONE",
";",
"}"
] | Checks whether the class has a mapped association for the specified field
and if yes, checks whether it is a single-valued association (to-one). | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"association",
"for",
"the",
"specified",
"field",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"single",
"-",
"valued",
"association",
"(",
"to",
"-",
"one",
")",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1338-L1342 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.isCollectionValuedReference | public function isCollectionValuedReference(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::REFERENCE_MANY;
} | php | public function isCollectionValuedReference(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::REFERENCE_MANY;
} | [
"public",
"function",
"isCollectionValuedReference",
"(",
"string",
"$",
"fieldName",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
")",
"&&",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
"===",
"self",
"::",
"REFERENCE_MANY",
";",
"}"
] | Checks whether the class has a mapped association for the specified field
and if yes, checks whether it is a collection-valued association (to-many). | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"association",
"for",
"the",
"specified",
"field",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"collection",
"-",
"valued",
"association",
"(",
"to",
"-",
"many",
")",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1348-L1352 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.isSingleValuedEmbed | public function isSingleValuedEmbed(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::EMBED_ONE;
} | php | public function isSingleValuedEmbed(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::EMBED_ONE;
} | [
"public",
"function",
"isSingleValuedEmbed",
"(",
"string",
"$",
"fieldName",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
")",
"&&",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
"===",
"self",
"::",
"EMBED_ONE",
";",
"}"
] | Checks whether the class has a mapped embedded document for the specified field
and if yes, checks whether it is a single-valued association (to-one). | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"embedded",
"document",
"for",
"the",
"specified",
"field",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"single",
"-",
"valued",
"association",
"(",
"to",
"-",
"one",
")",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1358-L1362 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.isCollectionValuedEmbed | public function isCollectionValuedEmbed(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::EMBED_MANY;
} | php | public function isCollectionValuedEmbed(string $fieldName) : bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::EMBED_MANY;
} | [
"public",
"function",
"isCollectionValuedEmbed",
"(",
"string",
"$",
"fieldName",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
")",
"&&",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"fieldName",
"]",
"[",
"'association'",
"]",
"===",
"self",
"::",
"EMBED_MANY",
";",
"}"
] | Checks whether the class has a mapped embedded document for the specified field
and if yes, checks whether it is a collection-valued association (to-many). | [
"Checks",
"whether",
"the",
"class",
"has",
"a",
"mapped",
"embedded",
"document",
"for",
"the",
"specified",
"field",
"and",
"if",
"yes",
"checks",
"whether",
"it",
"is",
"a",
"collection",
"-",
"valued",
"association",
"(",
"to",
"-",
"many",
")",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1368-L1372 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.getPHPIdentifierValue | public function getPHPIdentifierValue($id)
{
$idType = $this->fieldMappings[$this->identifier]['type'];
return Type::getType($idType)->convertToPHPValue($id);
} | php | public function getPHPIdentifierValue($id)
{
$idType = $this->fieldMappings[$this->identifier]['type'];
return Type::getType($idType)->convertToPHPValue($id);
} | [
"public",
"function",
"getPHPIdentifierValue",
"(",
"$",
"id",
")",
"{",
"$",
"idType",
"=",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"identifier",
"]",
"[",
"'type'",
"]",
";",
"return",
"Type",
"::",
"getType",
"(",
"$",
"idType",
")",
"->",
"convertToPHPValue",
"(",
"$",
"id",
")",
";",
"}"
] | Casts the identifier to its portable PHP type.
@param mixed $id
@return mixed $id | [
"Casts",
"the",
"identifier",
"to",
"its",
"portable",
"PHP",
"type",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1389-L1393 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.getDatabaseIdentifierValue | public function getDatabaseIdentifierValue($id)
{
$idType = $this->fieldMappings[$this->identifier]['type'];
return Type::getType($idType)->convertToDatabaseValue($id);
} | php | public function getDatabaseIdentifierValue($id)
{
$idType = $this->fieldMappings[$this->identifier]['type'];
return Type::getType($idType)->convertToDatabaseValue($id);
} | [
"public",
"function",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
"{",
"$",
"idType",
"=",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"this",
"->",
"identifier",
"]",
"[",
"'type'",
"]",
";",
"return",
"Type",
"::",
"getType",
"(",
"$",
"idType",
")",
"->",
"convertToDatabaseValue",
"(",
"$",
"id",
")",
";",
"}"
] | Casts the identifier to its database type.
@param mixed $id
@return mixed $id | [
"Casts",
"the",
"identifier",
"to",
"its",
"database",
"type",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1402-L1406 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setIdentifierValue | public function setIdentifierValue(object $document, $id) : void
{
$id = $this->getPHPIdentifierValue($id);
$this->reflFields[$this->identifier]->setValue($document, $id);
} | php | public function setIdentifierValue(object $document, $id) : void
{
$id = $this->getPHPIdentifierValue($id);
$this->reflFields[$this->identifier]->setValue($document, $id);
} | [
"public",
"function",
"setIdentifierValue",
"(",
"object",
"$",
"document",
",",
"$",
"id",
")",
":",
"void",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getPHPIdentifierValue",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"reflFields",
"[",
"$",
"this",
"->",
"identifier",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"id",
")",
";",
"}"
] | Sets the document identifier of a document.
The value will be converted to a PHP type before being set.
@param mixed $id | [
"Sets",
"the",
"document",
"identifier",
"of",
"a",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1415-L1419 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setFieldValue | public function setFieldValue(object $document, string $field, $value) : void
{
if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) {
//property changes to an uninitialized proxy will not be tracked or persisted,
//so the proxy needs to be loaded first.
$document->initializeProxy();
}
$this->reflFields[$field]->setValue($document, $value);
} | php | public function setFieldValue(object $document, string $field, $value) : void
{
if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) {
$document->initializeProxy();
}
$this->reflFields[$field]->setValue($document, $value);
} | [
"public",
"function",
"setFieldValue",
"(",
"object",
"$",
"document",
",",
"string",
"$",
"field",
",",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"$",
"document",
"instanceof",
"GhostObjectInterface",
"&&",
"!",
"$",
"document",
"->",
"isProxyInitialized",
"(",
")",
")",
"{",
"//property changes to an uninitialized proxy will not be tracked or persisted,",
"//so the proxy needs to be loaded first.",
"$",
"document",
"->",
"initializeProxy",
"(",
")",
";",
"}",
"$",
"this",
"->",
"reflFields",
"[",
"$",
"field",
"]",
"->",
"setValue",
"(",
"$",
"document",
",",
"$",
"value",
")",
";",
"}"
] | Sets the specified field to the specified value on the given document.
@param mixed $value | [
"Sets",
"the",
"specified",
"field",
"to",
"the",
"specified",
"value",
"on",
"the",
"given",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1458-L1467 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.getFieldValue | public function getFieldValue(object $document, string $field)
{
if ($document instanceof GhostObjectInterface && $field !== $this->identifier && ! $document->isProxyInitialized()) {
$document->initializeProxy();
}
return $this->reflFields[$field]->getValue($document);
} | php | public function getFieldValue(object $document, string $field)
{
if ($document instanceof GhostObjectInterface && $field !== $this->identifier && ! $document->isProxyInitialized()) {
$document->initializeProxy();
}
return $this->reflFields[$field]->getValue($document);
} | [
"public",
"function",
"getFieldValue",
"(",
"object",
"$",
"document",
",",
"string",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"document",
"instanceof",
"GhostObjectInterface",
"&&",
"$",
"field",
"!==",
"$",
"this",
"->",
"identifier",
"&&",
"!",
"$",
"document",
"->",
"isProxyInitialized",
"(",
")",
")",
"{",
"$",
"document",
"->",
"initializeProxy",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"reflFields",
"[",
"$",
"field",
"]",
"->",
"getValue",
"(",
"$",
"document",
")",
";",
"}"
] | Gets the specified field's value off the given document.
@return mixed | [
"Gets",
"the",
"specified",
"field",
"s",
"value",
"off",
"the",
"given",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1474-L1481 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.getFieldMappingByDbFieldName | public function getFieldMappingByDbFieldName(string $dbFieldName) : array
{
foreach ($this->fieldMappings as $mapping) {
if ($mapping['name'] === $dbFieldName) {
return $mapping;
}
}
throw MappingException::mappingNotFoundByDbName($this->name, $dbFieldName);
} | php | public function getFieldMappingByDbFieldName(string $dbFieldName) : array
{
foreach ($this->fieldMappings as $mapping) {
if ($mapping['name'] === $dbFieldName) {
return $mapping;
}
}
throw MappingException::mappingNotFoundByDbName($this->name, $dbFieldName);
} | [
"public",
"function",
"getFieldMappingByDbFieldName",
"(",
"string",
"$",
"dbFieldName",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fieldMappings",
"as",
"$",
"mapping",
")",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'name'",
"]",
"===",
"$",
"dbFieldName",
")",
"{",
"return",
"$",
"mapping",
";",
"}",
"}",
"throw",
"MappingException",
"::",
"mappingNotFoundByDbName",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"dbFieldName",
")",
";",
"}"
] | Gets the field mapping by its DB name.
E.g. it returns identifier's mapping when called with _id.
@throws MappingException | [
"Gets",
"the",
"field",
"mapping",
"by",
"its",
"DB",
"name",
".",
"E",
".",
"g",
".",
"it",
"returns",
"identifier",
"s",
"mapping",
"when",
"called",
"with",
"_id",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1515-L1524 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.isNullable | public function isNullable(string $fieldName) : bool
{
$mapping = $this->getFieldMapping($fieldName);
return isset($mapping['nullable']) && $mapping['nullable'] === true;
} | php | public function isNullable(string $fieldName) : bool
{
$mapping = $this->getFieldMapping($fieldName);
return isset($mapping['nullable']) && $mapping['nullable'] === true;
} | [
"public",
"function",
"isNullable",
"(",
"string",
"$",
"fieldName",
")",
":",
"bool",
"{",
"$",
"mapping",
"=",
"$",
"this",
"->",
"getFieldMapping",
"(",
"$",
"fieldName",
")",
";",
"return",
"isset",
"(",
"$",
"mapping",
"[",
"'nullable'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'nullable'",
"]",
"===",
"true",
";",
"}"
] | Check if the field is not null. | [
"Check",
"if",
"the",
"field",
"is",
"not",
"null",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1529-L1533 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setParentClasses | public function setParentClasses(array $classNames) : void
{
$this->parentClasses = $classNames;
if (count($classNames) <= 0) {
return;
}
$this->rootDocumentName = (string) array_pop($classNames);
} | php | public function setParentClasses(array $classNames) : void
{
$this->parentClasses = $classNames;
if (count($classNames) <= 0) {
return;
}
$this->rootDocumentName = (string) array_pop($classNames);
} | [
"public",
"function",
"setParentClasses",
"(",
"array",
"$",
"classNames",
")",
":",
"void",
"{",
"$",
"this",
"->",
"parentClasses",
"=",
"$",
"classNames",
";",
"if",
"(",
"count",
"(",
"$",
"classNames",
")",
"<=",
"0",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"rootDocumentName",
"=",
"(",
"string",
")",
"array_pop",
"(",
"$",
"classNames",
")",
";",
"}"
] | Sets the parent class names.
Assumes that the class names in the passed array are in the order:
directParent -> directParentParent -> directParentParentParent ... -> root.
@param string[] $classNames | [
"Sets",
"the",
"parent",
"class",
"names",
".",
"Assumes",
"that",
"the",
"class",
"names",
"in",
"the",
"passed",
"array",
"are",
"in",
"the",
"order",
":",
"directParent",
"-",
">",
"directParentParent",
"-",
">",
"directParentParentParent",
"...",
"-",
">",
"root",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1599-L1608 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.setLockMapping | public function setLockMapping(array &$mapping) : void
{
if ($mapping['type'] !== 'int') {
throw LockException::invalidLockFieldType($mapping['type']);
}
$this->isLockable = true;
$this->lockField = $mapping['fieldName'];
} | php | public function setLockMapping(array &$mapping) : void
{
if ($mapping['type'] !== 'int') {
throw LockException::invalidLockFieldType($mapping['type']);
}
$this->isLockable = true;
$this->lockField = $mapping['fieldName'];
} | [
"public",
"function",
"setLockMapping",
"(",
"array",
"&",
"$",
"mapping",
")",
":",
"void",
"{",
"if",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
"!==",
"'int'",
")",
"{",
"throw",
"LockException",
"::",
"invalidLockFieldType",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"isLockable",
"=",
"true",
";",
"$",
"this",
"->",
"lockField",
"=",
"$",
"mapping",
"[",
"'fieldName'",
"]",
";",
"}"
] | Sets the version field mapping used for versioning. Sets the default
value to use depending on the column type.
@throws LockException | [
"Sets",
"the",
"version",
"field",
"mapping",
"used",
"for",
"versioning",
".",
"Sets",
"the",
"default",
"value",
"to",
"use",
"depending",
"on",
"the",
"column",
"type",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1681-L1689 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.getAssociationCollectionClass | public function getAssociationCollectionClass(string $assocName) : string
{
if (! isset($this->associationMappings[$assocName])) {
throw new InvalidArgumentException("Association name expected, '" . $assocName . "' is not an association.");
}
if (! array_key_exists('collectionClass', $this->associationMappings[$assocName])) {
throw new InvalidArgumentException("collectionClass can only be applied to 'embedMany' and 'referenceMany' associations.");
}
return $this->associationMappings[$assocName]['collectionClass'];
} | php | public function getAssociationCollectionClass(string $assocName) : string
{
if (! isset($this->associationMappings[$assocName])) {
throw new InvalidArgumentException("Association name expected, '" . $assocName . "' is not an association.");
}
if (! array_key_exists('collectionClass', $this->associationMappings[$assocName])) {
throw new InvalidArgumentException("collectionClass can only be applied to 'embedMany' and 'referenceMany' associations.");
}
return $this->associationMappings[$assocName]['collectionClass'];
} | [
"public",
"function",
"getAssociationCollectionClass",
"(",
"string",
"$",
"assocName",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"associationMappings",
"[",
"$",
"assocName",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Association name expected, '\"",
".",
"$",
"assocName",
".",
"\"' is not an association.\"",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'collectionClass'",
",",
"$",
"this",
"->",
"associationMappings",
"[",
"$",
"assocName",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"collectionClass can only be applied to 'embedMany' and 'referenceMany' associations.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"associationMappings",
"[",
"$",
"assocName",
"]",
"[",
"'collectionClass'",
"]",
";",
"}"
] | Retrieve the collectionClass associated with an association | [
"Retrieve",
"the",
"collectionClass",
"associated",
"with",
"an",
"association"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1756-L1767 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | ClassMetadata.mapField | public function mapField(array $mapping) : array
{
if (! isset($mapping['fieldName']) && isset($mapping['name'])) {
$mapping['fieldName'] = $mapping['name'];
}
if (! isset($mapping['fieldName']) || ! is_string($mapping['fieldName'])) {
throw MappingException::missingFieldName($this->name);
}
if (! isset($mapping['name'])) {
$mapping['name'] = $mapping['fieldName'];
}
if ($this->identifier === $mapping['name'] && empty($mapping['id'])) {
throw MappingException::mustNotChangeIdentifierFieldsType($this->name, (string) $mapping['name']);
}
if ($this->discriminatorField !== null && $this->discriminatorField === $mapping['name']) {
throw MappingException::discriminatorFieldConflict($this->name, $this->discriminatorField);
}
if (isset($mapping['collectionClass'])) {
$mapping['collectionClass'] = ltrim($mapping['collectionClass'], '\\');
}
if (! empty($mapping['collectionClass'])) {
$rColl = new ReflectionClass($mapping['collectionClass']);
if (! $rColl->implementsInterface('Doctrine\\Common\\Collections\\Collection')) {
throw MappingException::collectionClassDoesNotImplementCommonInterface($this->name, $mapping['fieldName'], $mapping['collectionClass']);
}
}
if (isset($mapping['cascade']) && isset($mapping['embedded'])) {
throw MappingException::cascadeOnEmbeddedNotAllowed($this->name, $mapping['fieldName']);
}
$cascades = isset($mapping['cascade']) ? array_map('strtolower', (array) $mapping['cascade']) : [];
if (in_array('all', $cascades) || isset($mapping['embedded'])) {
$cascades = ['remove', 'persist', 'refresh', 'merge', 'detach'];
}
if (isset($mapping['embedded'])) {
unset($mapping['cascade']);
} elseif (isset($mapping['cascade'])) {
$mapping['cascade'] = $cascades;
}
$mapping['isCascadeRemove'] = in_array('remove', $cascades);
$mapping['isCascadePersist'] = in_array('persist', $cascades);
$mapping['isCascadeRefresh'] = in_array('refresh', $cascades);
$mapping['isCascadeMerge'] = in_array('merge', $cascades);
$mapping['isCascadeDetach'] = in_array('detach', $cascades);
if (isset($mapping['id']) && $mapping['id'] === true) {
$mapping['name'] = '_id';
$this->identifier = $mapping['fieldName'];
if (isset($mapping['strategy'])) {
$this->generatorType = constant(self::class . '::GENERATOR_TYPE_' . strtoupper($mapping['strategy']));
}
$this->generatorOptions = $mapping['options'] ?? [];
switch ($this->generatorType) {
case self::GENERATOR_TYPE_AUTO:
$mapping['type'] = 'id';
break;
default:
if (! empty($this->generatorOptions['type'])) {
$mapping['type'] = $this->generatorOptions['type'];
} elseif (empty($mapping['type'])) {
$mapping['type'] = $this->generatorType === self::GENERATOR_TYPE_INCREMENT ? 'int_id' : 'custom_id';
}
}
unset($this->generatorOptions['type']);
}
if (! isset($mapping['nullable'])) {
$mapping['nullable'] = false;
}
if (isset($mapping['reference'])
&& isset($mapping['storeAs'])
&& $mapping['storeAs'] === self::REFERENCE_STORE_AS_ID
&& ! isset($mapping['targetDocument'])
) {
throw MappingException::simpleReferenceRequiresTargetDocument($this->name, $mapping['fieldName']);
}
if (isset($mapping['reference']) && empty($mapping['targetDocument']) && empty($mapping['discriminatorMap']) &&
(isset($mapping['mappedBy']) || isset($mapping['inversedBy']))) {
throw MappingException::owningAndInverseReferencesRequireTargetDocument($this->name, $mapping['fieldName']);
}
if ($this->isEmbeddedDocument && $mapping['type'] === 'many' && isset($mapping['strategy']) && CollectionHelper::isAtomic($mapping['strategy'])) {
throw MappingException::atomicCollectionStrategyNotAllowed($mapping['strategy'], $this->name, $mapping['fieldName']);
}
if (isset($mapping['repositoryMethod']) && ! (empty($mapping['skip']) && empty($mapping['limit']) && empty($mapping['sort']))) {
throw MappingException::repositoryMethodCanNotBeCombinedWithSkipLimitAndSort($this->name, $mapping['fieldName']);
}
if (isset($mapping['reference']) && $mapping['type'] === 'one') {
$mapping['association'] = self::REFERENCE_ONE;
}
if (isset($mapping['reference']) && $mapping['type'] === 'many') {
$mapping['association'] = self::REFERENCE_MANY;
}
if (isset($mapping['embedded']) && $mapping['type'] === 'one') {
$mapping['association'] = self::EMBED_ONE;
}
if (isset($mapping['embedded']) && $mapping['type'] === 'many') {
$mapping['association'] = self::EMBED_MANY;
}
if (isset($mapping['association']) && ! isset($mapping['targetDocument']) && ! isset($mapping['discriminatorField'])) {
$mapping['discriminatorField'] = self::DEFAULT_DISCRIMINATOR_FIELD;
}
if (isset($mapping['version'])) {
$mapping['notSaved'] = true;
$this->setVersionMapping($mapping);
}
if (isset($mapping['lock'])) {
$mapping['notSaved'] = true;
$this->setLockMapping($mapping);
}
$mapping['isOwningSide'] = true;
$mapping['isInverseSide'] = false;
if (isset($mapping['reference'])) {
if (isset($mapping['inversedBy']) && $mapping['inversedBy']) {
$mapping['isOwningSide'] = true;
$mapping['isInverseSide'] = false;
}
if (isset($mapping['mappedBy']) && $mapping['mappedBy']) {
$mapping['isInverseSide'] = true;
$mapping['isOwningSide'] = false;
}
if (isset($mapping['repositoryMethod'])) {
$mapping['isInverseSide'] = true;
$mapping['isOwningSide'] = false;
}
if (! isset($mapping['orphanRemoval'])) {
$mapping['orphanRemoval'] = false;
}
}
if (! empty($mapping['prime']) && ($mapping['association'] !== self::REFERENCE_MANY || ! $mapping['isInverseSide'])) {
throw MappingException::referencePrimersOnlySupportedForInverseReferenceMany($this->name, $mapping['fieldName']);
}
if ($this->isFile && ! $this->isAllowedGridFSField($mapping['name'])) {
throw MappingException::fieldNotAllowedForGridFS($this->name, $mapping['fieldName']);
}
$this->applyStorageStrategy($mapping);
$this->checkDuplicateMapping($mapping);
$this->fieldMappings[$mapping['fieldName']] = $mapping;
if (isset($mapping['association'])) {
$this->associationMappings[$mapping['fieldName']] = $mapping;
}
$reflProp = $this->reflClass->getProperty($mapping['fieldName']);
$reflProp->setAccessible(true);
$this->reflFields[$mapping['fieldName']] = $reflProp;
return $mapping;
} | php | public function mapField(array $mapping) : array
{
if (! isset($mapping['fieldName']) && isset($mapping['name'])) {
$mapping['fieldName'] = $mapping['name'];
}
if (! isset($mapping['fieldName']) || ! is_string($mapping['fieldName'])) {
throw MappingException::missingFieldName($this->name);
}
if (! isset($mapping['name'])) {
$mapping['name'] = $mapping['fieldName'];
}
if ($this->identifier === $mapping['name'] && empty($mapping['id'])) {
throw MappingException::mustNotChangeIdentifierFieldsType($this->name, (string) $mapping['name']);
}
if ($this->discriminatorField !== null && $this->discriminatorField === $mapping['name']) {
throw MappingException::discriminatorFieldConflict($this->name, $this->discriminatorField);
}
if (isset($mapping['collectionClass'])) {
$mapping['collectionClass'] = ltrim($mapping['collectionClass'], '\\');
}
if (! empty($mapping['collectionClass'])) {
$rColl = new ReflectionClass($mapping['collectionClass']);
if (! $rColl->implementsInterface('Doctrine\\Common\\Collections\\Collection')) {
throw MappingException::collectionClassDoesNotImplementCommonInterface($this->name, $mapping['fieldName'], $mapping['collectionClass']);
}
}
if (isset($mapping['cascade']) && isset($mapping['embedded'])) {
throw MappingException::cascadeOnEmbeddedNotAllowed($this->name, $mapping['fieldName']);
}
$cascades = isset($mapping['cascade']) ? array_map('strtolower', (array) $mapping['cascade']) : [];
if (in_array('all', $cascades) || isset($mapping['embedded'])) {
$cascades = ['remove', 'persist', 'refresh', 'merge', 'detach'];
}
if (isset($mapping['embedded'])) {
unset($mapping['cascade']);
} elseif (isset($mapping['cascade'])) {
$mapping['cascade'] = $cascades;
}
$mapping['isCascadeRemove'] = in_array('remove', $cascades);
$mapping['isCascadePersist'] = in_array('persist', $cascades);
$mapping['isCascadeRefresh'] = in_array('refresh', $cascades);
$mapping['isCascadeMerge'] = in_array('merge', $cascades);
$mapping['isCascadeDetach'] = in_array('detach', $cascades);
if (isset($mapping['id']) && $mapping['id'] === true) {
$mapping['name'] = '_id';
$this->identifier = $mapping['fieldName'];
if (isset($mapping['strategy'])) {
$this->generatorType = constant(self::class . '::GENERATOR_TYPE_' . strtoupper($mapping['strategy']));
}
$this->generatorOptions = $mapping['options'] ?? [];
switch ($this->generatorType) {
case self::GENERATOR_TYPE_AUTO:
$mapping['type'] = 'id';
break;
default:
if (! empty($this->generatorOptions['type'])) {
$mapping['type'] = $this->generatorOptions['type'];
} elseif (empty($mapping['type'])) {
$mapping['type'] = $this->generatorType === self::GENERATOR_TYPE_INCREMENT ? 'int_id' : 'custom_id';
}
}
unset($this->generatorOptions['type']);
}
if (! isset($mapping['nullable'])) {
$mapping['nullable'] = false;
}
if (isset($mapping['reference'])
&& isset($mapping['storeAs'])
&& $mapping['storeAs'] === self::REFERENCE_STORE_AS_ID
&& ! isset($mapping['targetDocument'])
) {
throw MappingException::simpleReferenceRequiresTargetDocument($this->name, $mapping['fieldName']);
}
if (isset($mapping['reference']) && empty($mapping['targetDocument']) && empty($mapping['discriminatorMap']) &&
(isset($mapping['mappedBy']) || isset($mapping['inversedBy']))) {
throw MappingException::owningAndInverseReferencesRequireTargetDocument($this->name, $mapping['fieldName']);
}
if ($this->isEmbeddedDocument && $mapping['type'] === 'many' && isset($mapping['strategy']) && CollectionHelper::isAtomic($mapping['strategy'])) {
throw MappingException::atomicCollectionStrategyNotAllowed($mapping['strategy'], $this->name, $mapping['fieldName']);
}
if (isset($mapping['repositoryMethod']) && ! (empty($mapping['skip']) && empty($mapping['limit']) && empty($mapping['sort']))) {
throw MappingException::repositoryMethodCanNotBeCombinedWithSkipLimitAndSort($this->name, $mapping['fieldName']);
}
if (isset($mapping['reference']) && $mapping['type'] === 'one') {
$mapping['association'] = self::REFERENCE_ONE;
}
if (isset($mapping['reference']) && $mapping['type'] === 'many') {
$mapping['association'] = self::REFERENCE_MANY;
}
if (isset($mapping['embedded']) && $mapping['type'] === 'one') {
$mapping['association'] = self::EMBED_ONE;
}
if (isset($mapping['embedded']) && $mapping['type'] === 'many') {
$mapping['association'] = self::EMBED_MANY;
}
if (isset($mapping['association']) && ! isset($mapping['targetDocument']) && ! isset($mapping['discriminatorField'])) {
$mapping['discriminatorField'] = self::DEFAULT_DISCRIMINATOR_FIELD;
}
if (isset($mapping['version'])) {
$mapping['notSaved'] = true;
$this->setVersionMapping($mapping);
}
if (isset($mapping['lock'])) {
$mapping['notSaved'] = true;
$this->setLockMapping($mapping);
}
$mapping['isOwningSide'] = true;
$mapping['isInverseSide'] = false;
if (isset($mapping['reference'])) {
if (isset($mapping['inversedBy']) && $mapping['inversedBy']) {
$mapping['isOwningSide'] = true;
$mapping['isInverseSide'] = false;
}
if (isset($mapping['mappedBy']) && $mapping['mappedBy']) {
$mapping['isInverseSide'] = true;
$mapping['isOwningSide'] = false;
}
if (isset($mapping['repositoryMethod'])) {
$mapping['isInverseSide'] = true;
$mapping['isOwningSide'] = false;
}
if (! isset($mapping['orphanRemoval'])) {
$mapping['orphanRemoval'] = false;
}
}
if (! empty($mapping['prime']) && ($mapping['association'] !== self::REFERENCE_MANY || ! $mapping['isInverseSide'])) {
throw MappingException::referencePrimersOnlySupportedForInverseReferenceMany($this->name, $mapping['fieldName']);
}
if ($this->isFile && ! $this->isAllowedGridFSField($mapping['name'])) {
throw MappingException::fieldNotAllowedForGridFS($this->name, $mapping['fieldName']);
}
$this->applyStorageStrategy($mapping);
$this->checkDuplicateMapping($mapping);
$this->fieldMappings[$mapping['fieldName']] = $mapping;
if (isset($mapping['association'])) {
$this->associationMappings[$mapping['fieldName']] = $mapping;
}
$reflProp = $this->reflClass->getProperty($mapping['fieldName']);
$reflProp->setAccessible(true);
$this->reflFields[$mapping['fieldName']] = $reflProp;
return $mapping;
} | [
"public",
"function",
"mapField",
"(",
"array",
"$",
"mapping",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"=",
"$",
"mapping",
"[",
"'name'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
"||",
"!",
"is_string",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"missingFieldName",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'name'",
"]",
"=",
"$",
"mapping",
"[",
"'fieldName'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"identifier",
"===",
"$",
"mapping",
"[",
"'name'",
"]",
"&&",
"empty",
"(",
"$",
"mapping",
"[",
"'id'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"mustNotChangeIdentifierFieldsType",
"(",
"$",
"this",
"->",
"name",
",",
"(",
"string",
")",
"$",
"mapping",
"[",
"'name'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"discriminatorField",
"!==",
"null",
"&&",
"$",
"this",
"->",
"discriminatorField",
"===",
"$",
"mapping",
"[",
"'name'",
"]",
")",
"{",
"throw",
"MappingException",
"::",
"discriminatorFieldConflict",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"discriminatorField",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
"=",
"ltrim",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
",",
"'\\\\'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
")",
"{",
"$",
"rColl",
"=",
"new",
"ReflectionClass",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"rColl",
"->",
"implementsInterface",
"(",
"'Doctrine\\\\Common\\\\Collections\\\\Collection'",
")",
")",
"{",
"throw",
"MappingException",
"::",
"collectionClassDoesNotImplementCommonInterface",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
",",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'cascade'",
"]",
")",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"cascadeOnEmbeddedNotAllowed",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"$",
"cascades",
"=",
"isset",
"(",
"$",
"mapping",
"[",
"'cascade'",
"]",
")",
"?",
"array_map",
"(",
"'strtolower'",
",",
"(",
"array",
")",
"$",
"mapping",
"[",
"'cascade'",
"]",
")",
":",
"[",
"]",
";",
"if",
"(",
"in_array",
"(",
"'all'",
",",
"$",
"cascades",
")",
"||",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
"{",
"$",
"cascades",
"=",
"[",
"'remove'",
",",
"'persist'",
",",
"'refresh'",
",",
"'merge'",
",",
"'detach'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"mapping",
"[",
"'cascade'",
"]",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'cascade'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'cascade'",
"]",
"=",
"$",
"cascades",
";",
"}",
"$",
"mapping",
"[",
"'isCascadeRemove'",
"]",
"=",
"in_array",
"(",
"'remove'",
",",
"$",
"cascades",
")",
";",
"$",
"mapping",
"[",
"'isCascadePersist'",
"]",
"=",
"in_array",
"(",
"'persist'",
",",
"$",
"cascades",
")",
";",
"$",
"mapping",
"[",
"'isCascadeRefresh'",
"]",
"=",
"in_array",
"(",
"'refresh'",
",",
"$",
"cascades",
")",
";",
"$",
"mapping",
"[",
"'isCascadeMerge'",
"]",
"=",
"in_array",
"(",
"'merge'",
",",
"$",
"cascades",
")",
";",
"$",
"mapping",
"[",
"'isCascadeDetach'",
"]",
"=",
"in_array",
"(",
"'detach'",
",",
"$",
"cascades",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'id'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'id'",
"]",
"===",
"true",
")",
"{",
"$",
"mapping",
"[",
"'name'",
"]",
"=",
"'_id'",
";",
"$",
"this",
"->",
"identifier",
"=",
"$",
"mapping",
"[",
"'fieldName'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"generatorType",
"=",
"constant",
"(",
"self",
"::",
"class",
".",
"'::GENERATOR_TYPE_'",
".",
"strtoupper",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"generatorOptions",
"=",
"$",
"mapping",
"[",
"'options'",
"]",
"??",
"[",
"]",
";",
"switch",
"(",
"$",
"this",
"->",
"generatorType",
")",
"{",
"case",
"self",
"::",
"GENERATOR_TYPE_AUTO",
":",
"$",
"mapping",
"[",
"'type'",
"]",
"=",
"'id'",
";",
"break",
";",
"default",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"generatorOptions",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"generatorOptions",
"[",
"'type'",
"]",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"mapping",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"generatorType",
"===",
"self",
"::",
"GENERATOR_TYPE_INCREMENT",
"?",
"'int_id'",
":",
"'custom_id'",
";",
"}",
"}",
"unset",
"(",
"$",
"this",
"->",
"generatorOptions",
"[",
"'type'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'nullable'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'nullable'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'storeAs'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'storeAs'",
"]",
"===",
"self",
"::",
"REFERENCE_STORE_AS_ID",
"&&",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"simpleReferenceRequiresTargetDocument",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"empty",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
"&&",
"empty",
"(",
"$",
"mapping",
"[",
"'discriminatorMap'",
"]",
")",
"&&",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'mappedBy'",
"]",
")",
"||",
"isset",
"(",
"$",
"mapping",
"[",
"'inversedBy'",
"]",
")",
")",
")",
"{",
"throw",
"MappingException",
"::",
"owningAndInverseReferencesRequireTargetDocument",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isEmbeddedDocument",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
"&&",
"isset",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
"&&",
"CollectionHelper",
"::",
"isAtomic",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"atomicCollectionStrategyNotAllowed",
"(",
"$",
"mapping",
"[",
"'strategy'",
"]",
",",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'repositoryMethod'",
"]",
")",
"&&",
"!",
"(",
"empty",
"(",
"$",
"mapping",
"[",
"'skip'",
"]",
")",
"&&",
"empty",
"(",
"$",
"mapping",
"[",
"'limit'",
"]",
")",
"&&",
"empty",
"(",
"$",
"mapping",
"[",
"'sort'",
"]",
")",
")",
")",
"{",
"throw",
"MappingException",
"::",
"repositoryMethodCanNotBeCombinedWithSkipLimitAndSort",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'one'",
")",
"{",
"$",
"mapping",
"[",
"'association'",
"]",
"=",
"self",
"::",
"REFERENCE_ONE",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
")",
"{",
"$",
"mapping",
"[",
"'association'",
"]",
"=",
"self",
"::",
"REFERENCE_MANY",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'one'",
")",
"{",
"$",
"mapping",
"[",
"'association'",
"]",
"=",
"self",
"::",
"EMBED_ONE",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'embedded'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'type'",
"]",
"===",
"'many'",
")",
"{",
"$",
"mapping",
"[",
"'association'",
"]",
"=",
"self",
"::",
"EMBED_MANY",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'discriminatorField'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'discriminatorField'",
"]",
"=",
"self",
"::",
"DEFAULT_DISCRIMINATOR_FIELD",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'version'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'notSaved'",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"setVersionMapping",
"(",
"$",
"mapping",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'lock'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'notSaved'",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"setLockMapping",
"(",
"$",
"mapping",
")",
";",
"}",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
"=",
"true",
";",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'reference'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'inversedBy'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'inversedBy'",
"]",
")",
"{",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
"=",
"true",
";",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'mappedBy'",
"]",
")",
"&&",
"$",
"mapping",
"[",
"'mappedBy'",
"]",
")",
"{",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
"=",
"true",
";",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'repositoryMethod'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
"=",
"true",
";",
"$",
"mapping",
"[",
"'isOwningSide'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"'orphanRemoval'",
"]",
")",
")",
"{",
"$",
"mapping",
"[",
"'orphanRemoval'",
"]",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'prime'",
"]",
")",
"&&",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
"!==",
"self",
"::",
"REFERENCE_MANY",
"||",
"!",
"$",
"mapping",
"[",
"'isInverseSide'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"referencePrimersOnlySupportedForInverseReferenceMany",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isFile",
"&&",
"!",
"$",
"this",
"->",
"isAllowedGridFSField",
"(",
"$",
"mapping",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"MappingException",
"::",
"fieldNotAllowedForGridFS",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"applyStorageStrategy",
"(",
"$",
"mapping",
")",
";",
"$",
"this",
"->",
"checkDuplicateMapping",
"(",
"$",
"mapping",
")",
";",
"$",
"this",
"->",
"fieldMappings",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"=",
"$",
"mapping",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"'association'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"associationMappings",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"=",
"$",
"mapping",
";",
"}",
"$",
"reflProp",
"=",
"$",
"this",
"->",
"reflClass",
"->",
"getProperty",
"(",
"$",
"mapping",
"[",
"'fieldName'",
"]",
")",
";",
"$",
"reflProp",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"this",
"->",
"reflFields",
"[",
"$",
"mapping",
"[",
"'fieldName'",
"]",
"]",
"=",
"$",
"reflProp",
";",
"return",
"$",
"mapping",
";",
"}"
] | Map a field.
@throws MappingException | [
"Map",
"a",
"field",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1790-L1952 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketAutoOutput.php | BucketAutoOutput.groupBy | public function groupBy($expression) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);
return $this->bucket->groupBy($expression);
} | php | public function groupBy($expression) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);
return $this->bucket->groupBy($expression);
} | [
"public",
"function",
"groupBy",
"(",
"$",
"expression",
")",
":",
"Stage",
"\\",
"BucketAuto",
"{",
"assert",
"(",
"$",
"this",
"->",
"bucket",
"instanceof",
"Stage",
"\\",
"BucketAuto",
")",
";",
"return",
"$",
"this",
"->",
"bucket",
"->",
"groupBy",
"(",
"$",
"expression",
")",
";",
"}"
] | An expression to group documents by. To specify a field path, prefix the
field name with a dollar sign $ and enclose it in quotes. | [
"An",
"expression",
"to",
"group",
"documents",
"by",
".",
"To",
"specify",
"a",
"field",
"path",
"prefix",
"the",
"field",
"name",
"with",
"a",
"dollar",
"sign",
"$",
"and",
"enclose",
"it",
"in",
"quotes",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketAutoOutput.php#L25-L29 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketAutoOutput.php | BucketAutoOutput.buckets | public function buckets(int $buckets) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);
return $this->bucket->buckets($buckets);
} | php | public function buckets(int $buckets) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);
return $this->bucket->buckets($buckets);
} | [
"public",
"function",
"buckets",
"(",
"int",
"$",
"buckets",
")",
":",
"Stage",
"\\",
"BucketAuto",
"{",
"assert",
"(",
"$",
"this",
"->",
"bucket",
"instanceof",
"Stage",
"\\",
"BucketAuto",
")",
";",
"return",
"$",
"this",
"->",
"bucket",
"->",
"buckets",
"(",
"$",
"buckets",
")",
";",
"}"
] | A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. | [
"A",
"positive",
"32",
"-",
"bit",
"integer",
"that",
"specifies",
"the",
"number",
"of",
"buckets",
"into",
"which",
"input",
"documents",
"are",
"grouped",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketAutoOutput.php#L34-L38 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketAutoOutput.php | BucketAutoOutput.granularity | public function granularity(string $granularity) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);
return $this->bucket->granularity($granularity);
} | php | public function granularity(string $granularity) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);
return $this->bucket->granularity($granularity);
} | [
"public",
"function",
"granularity",
"(",
"string",
"$",
"granularity",
")",
":",
"Stage",
"\\",
"BucketAuto",
"{",
"assert",
"(",
"$",
"this",
"->",
"bucket",
"instanceof",
"Stage",
"\\",
"BucketAuto",
")",
";",
"return",
"$",
"this",
"->",
"bucket",
"->",
"granularity",
"(",
"$",
"granularity",
")",
";",
"}"
] | A string that specifies the preferred number series to use to ensure that
the calculated boundary edges end on preferred round numbers or their
powers of 10. | [
"A",
"string",
"that",
"specifies",
"the",
"preferred",
"number",
"series",
"to",
"use",
"to",
"ensure",
"that",
"the",
"calculated",
"boundary",
"edges",
"end",
"on",
"preferred",
"round",
"numbers",
"or",
"their",
"powers",
"of",
"10",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketAutoOutput.php#L45-L49 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketOutput.php | BucketOutput.groupBy | public function groupBy($expression)
{
assert($this->bucket instanceof Stage\Bucket);
return $this->bucket->groupBy($expression);
} | php | public function groupBy($expression)
{
assert($this->bucket instanceof Stage\Bucket);
return $this->bucket->groupBy($expression);
} | [
"public",
"function",
"groupBy",
"(",
"$",
"expression",
")",
"{",
"assert",
"(",
"$",
"this",
"->",
"bucket",
"instanceof",
"Stage",
"\\",
"Bucket",
")",
";",
"return",
"$",
"this",
"->",
"bucket",
"->",
"groupBy",
"(",
"$",
"expression",
")",
";",
"}"
] | An expression to group documents by. To specify a field path, prefix the
field name with a dollar sign $ and enclose it in quotes.
@param mixed|Expr $expression
@return Stage\Bucket | [
"An",
"expression",
"to",
"group",
"documents",
"by",
".",
"To",
"specify",
"a",
"field",
"path",
"prefix",
"the",
"field",
"name",
"with",
"a",
"dollar",
"sign",
"$",
"and",
"enclose",
"it",
"in",
"quotes",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketOutput.php#L30-L34 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketOutput.php | BucketOutput.boundaries | public function boundaries(...$boundaries)
{
assert($this->bucket instanceof Stage\Bucket);
return $this->bucket->boundaries(...$boundaries);
} | php | public function boundaries(...$boundaries)
{
assert($this->bucket instanceof Stage\Bucket);
return $this->bucket->boundaries(...$boundaries);
} | [
"public",
"function",
"boundaries",
"(",
"...",
"$",
"boundaries",
")",
"{",
"assert",
"(",
"$",
"this",
"->",
"bucket",
"instanceof",
"Stage",
"\\",
"Bucket",
")",
";",
"return",
"$",
"this",
"->",
"bucket",
"->",
"boundaries",
"(",
"...",
"$",
"boundaries",
")",
";",
"}"
] | An array of values based on the groupBy expression that specify the
boundaries for each bucket.
Each adjacent pair of values acts as the inclusive lower boundary and the
exclusive upper boundary for the bucket. You must specify at least two
boundaries. The specified values must be in ascending order and all of
the same type. The exception is if the values are of mixed numeric types.
@param array ...$boundaries
@return Stage\Bucket | [
"An",
"array",
"of",
"values",
"based",
"on",
"the",
"groupBy",
"expression",
"that",
"specify",
"the",
"boundaries",
"for",
"each",
"bucket",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/BucketOutput.php#L49-L53 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php | DefaultPersistentCollectionGenerator.generateClass | public function generateClass(string $class, string $dir) : void
{
$collClassName = str_replace('\\', '', $class) . 'Persistent';
$className = $this->collectionNamespace . '\\' . $collClassName;
$fileName = $dir . DIRECTORY_SEPARATOR . $collClassName . '.php';
$this->generateCollectionClass($class, $className, $fileName);
} | php | public function generateClass(string $class, string $dir) : void
{
$collClassName = str_replace('\\', '', $class) . 'Persistent';
$className = $this->collectionNamespace . '\\' . $collClassName;
$fileName = $dir . DIRECTORY_SEPARATOR . $collClassName . '.php';
$this->generateCollectionClass($class, $className, $fileName);
} | [
"public",
"function",
"generateClass",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"dir",
")",
":",
"void",
"{",
"$",
"collClassName",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"''",
",",
"$",
"class",
")",
".",
"'Persistent'",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"collectionNamespace",
".",
"'\\\\'",
".",
"$",
"collClassName",
";",
"$",
"fileName",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"collClassName",
".",
"'.php'",
";",
"$",
"this",
"->",
"generateCollectionClass",
"(",
"$",
"class",
",",
"$",
"className",
",",
"$",
"fileName",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php#L62-L68 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php | DefaultPersistentCollectionGenerator.getParameterNamesForDecoratedCall | private function getParameterNamesForDecoratedCall(array $parameters) : array
{
return array_map(
static function (ReflectionParameter $parameter) {
$name = '';
if (method_exists($parameter, 'isVariadic')) {
if ($parameter->isVariadic()) {
$name .= '...';
}
}
return $name . '$' . $parameter->name;
},
$parameters
);
} | php | private function getParameterNamesForDecoratedCall(array $parameters) : array
{
return array_map(
static function (ReflectionParameter $parameter) {
$name = '';
if (method_exists($parameter, 'isVariadic')) {
if ($parameter->isVariadic()) {
$name .= '...';
}
}
return $name . '$' . $parameter->name;
},
$parameters
);
} | [
"private",
"function",
"getParameterNamesForDecoratedCall",
"(",
"array",
"$",
"parameters",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"static",
"function",
"(",
"ReflectionParameter",
"$",
"parameter",
")",
"{",
"$",
"name",
"=",
"''",
";",
"if",
"(",
"method_exists",
"(",
"$",
"parameter",
",",
"'isVariadic'",
")",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isVariadic",
"(",
")",
")",
"{",
"$",
"name",
".=",
"'...'",
";",
"}",
"}",
"return",
"$",
"name",
".",
"'$'",
".",
"$",
"parameter",
"->",
"name",
";",
"}",
",",
"$",
"parameters",
")",
";",
"}"
] | @param ReflectionParameter[] $parameters
@return string[] | [
"@param",
"ReflectionParameter",
"[]",
"$parameters"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php#L277-L293 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php | Match.geoWithinBox | public function geoWithinBox(float $x1, float $y1, float $x2, float $y2) : self
{
$this->query->geoWithinBox($x1, $y1, $x2, $y2);
return $this;
} | php | public function geoWithinBox(float $x1, float $y1, float $x2, float $y2) : self
{
$this->query->geoWithinBox($x1, $y1, $x2, $y2);
return $this;
} | [
"public",
"function",
"geoWithinBox",
"(",
"float",
"$",
"x1",
",",
"float",
"$",
"y1",
",",
"float",
"$",
"x2",
",",
"float",
"$",
"y2",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"->",
"geoWithinBox",
"(",
"$",
"x1",
",",
"$",
"y1",
",",
"$",
"x2",
",",
"$",
"y2",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add $geoWithin criteria with a $box shape to the query.
A rectangular polygon will be constructed from a pair of coordinates
corresponding to the bottom left and top right corners.
Note: the $box operator only supports legacy coordinate pairs and 2d
indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
@see Expr::geoWithinBox()
@see http://docs.mongodb.org/manual/reference/operator/box/ | [
"Add",
"$geoWithin",
"criteria",
"with",
"a",
"$box",
"shape",
"to",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L221-L226 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php | Match.geoWithinCenter | public function geoWithinCenter(float $x, float $y, float $radius) : self
{
$this->query->geoWithinCenter($x, $y, $radius);
return $this;
} | php | public function geoWithinCenter(float $x, float $y, float $radius) : self
{
$this->query->geoWithinCenter($x, $y, $radius);
return $this;
} | [
"public",
"function",
"geoWithinCenter",
"(",
"float",
"$",
"x",
",",
"float",
"$",
"y",
",",
"float",
"$",
"radius",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"->",
"geoWithinCenter",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"radius",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add $geoWithin criteria with a $center shape to the query.
Note: the $center operator only supports legacy coordinate pairs and 2d
indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
@see Expr::geoWithinCenter()
@see http://docs.mongodb.org/manual/reference/operator/center/ | [
"Add",
"$geoWithin",
"criteria",
"with",
"a",
"$center",
"shape",
"to",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L237-L242 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php | Match.geoWithinCenterSphere | public function geoWithinCenterSphere(float $x, float $y, float $radius) : self
{
$this->query->geoWithinCenterSphere($x, $y, $radius);
return $this;
} | php | public function geoWithinCenterSphere(float $x, float $y, float $radius) : self
{
$this->query->geoWithinCenterSphere($x, $y, $radius);
return $this;
} | [
"public",
"function",
"geoWithinCenterSphere",
"(",
"float",
"$",
"x",
",",
"float",
"$",
"y",
",",
"float",
"$",
"radius",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"->",
"geoWithinCenterSphere",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"radius",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add $geoWithin criteria with a $centerSphere shape to the query.
Note: the $centerSphere operator supports both 2d and 2dsphere indexes.
@see Expr::geoWithinCenterSphere()
@see http://docs.mongodb.org/manual/reference/operator/centerSphere/ | [
"Add",
"$geoWithin",
"criteria",
"with",
"a",
"$centerSphere",
"shape",
"to",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L252-L257 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php | Match.geoWithinPolygon | public function geoWithinPolygon($point1, $point2, $point3, ...$points) : self
{
$this->query->geoWithinPolygon(...func_get_args());
return $this;
} | php | public function geoWithinPolygon($point1, $point2, $point3, ...$points) : self
{
$this->query->geoWithinPolygon(...func_get_args());
return $this;
} | [
"public",
"function",
"geoWithinPolygon",
"(",
"$",
"point1",
",",
"$",
"point2",
",",
"$",
"point3",
",",
"...",
"$",
"points",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"->",
"geoWithinPolygon",
"(",
"...",
"func_get_args",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add $geoWithin criteria with a $polygon shape to the query.
Point coordinates are in x, y order (easting, northing for projected
coordinates, longitude, latitude for geographic coordinates).
The last point coordinate is implicitly connected with the first.
Note: the $polygon operator only supports legacy coordinate pairs and 2d
indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
@see Expr::geoWithinPolygon()
@see http://docs.mongodb.org/manual/reference/operator/polygon/
@param array $point1 First point of the polygon
@param array $point2 Second point of the polygon
@param array $point3 Third point of the polygon
@param array ...$points Additional points of the polygon | [
"Add",
"$geoWithin",
"criteria",
"with",
"a",
"$polygon",
"shape",
"to",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L278-L283 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php | Match.mod | public function mod($divisor, $remainder = 0) : self
{
$this->query->mod($divisor, $remainder);
return $this;
} | php | public function mod($divisor, $remainder = 0) : self
{
$this->query->mod($divisor, $remainder);
return $this;
} | [
"public",
"function",
"mod",
"(",
"$",
"divisor",
",",
"$",
"remainder",
"=",
"0",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"->",
"mod",
"(",
"$",
"divisor",
",",
"$",
"remainder",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Specify $mod criteria for the current field.
@see Expr::mod()
@see http://docs.mongodb.org/manual/reference/operator/mod/
@param float|int $divisor
@param float|int $remainder | [
"Specify",
"$mod",
"criteria",
"for",
"the",
"current",
"field",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L399-L404 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php | Match.range | public function range($start, $end) : self
{
$this->query->range($start, $end);
return $this;
} | php | public function range($start, $end) : self
{
$this->query->range($start, $end);
return $this;
} | [
"public",
"function",
"range",
"(",
"$",
"start",
",",
"$",
"end",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"->",
"range",
"(",
"$",
"start",
",",
"$",
"end",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Specify $gte and $lt criteria for the current field.
This method is shorthand for specifying $gte criteria on the lower bound
and $lt criteria on the upper bound. The upper bound is not inclusive.
@see Expr::range()
@param mixed $start
@param mixed $end | [
"Specify",
"$gte",
"and",
"$lt",
"criteria",
"for",
"the",
"current",
"field",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php#L463-L468 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Tools/Console/MetadataFilter.php | MetadataFilter.filter | public static function filter(array $metadatas, $filter) : array
{
$metadatas = new MetadataFilter(new ArrayIterator($metadatas), $filter);
return iterator_to_array($metadatas);
} | php | public static function filter(array $metadatas, $filter) : array
{
$metadatas = new MetadataFilter(new ArrayIterator($metadatas), $filter);
return iterator_to_array($metadatas);
} | [
"public",
"static",
"function",
"filter",
"(",
"array",
"$",
"metadatas",
",",
"$",
"filter",
")",
":",
"array",
"{",
"$",
"metadatas",
"=",
"new",
"MetadataFilter",
"(",
"new",
"ArrayIterator",
"(",
"$",
"metadatas",
")",
",",
"$",
"filter",
")",
";",
"return",
"iterator_to_array",
"(",
"$",
"metadatas",
")",
";",
"}"
] | Filter Metadatas by one or more filter options.
@param ClassMetadata[] $metadatas
@param string[]|string $filter
@return ClassMetadata[] | [
"Filter",
"Metadatas",
"by",
"one",
"or",
"more",
"filter",
"options",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Tools/Console/MetadataFilter.php#L29-L33 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Tools/ResolveTargetDocumentListener.php | ResolveTargetDocumentListener.addResolveTargetDocument | public function addResolveTargetDocument(string $originalDocument, string $newDocument, array $mapping) : void
{
$mapping['targetDocument'] = ltrim($newDocument, '\\');
$this->resolveTargetDocuments[ltrim($originalDocument, '\\')] = $mapping;
} | php | public function addResolveTargetDocument(string $originalDocument, string $newDocument, array $mapping) : void
{
$mapping['targetDocument'] = ltrim($newDocument, '\\');
$this->resolveTargetDocuments[ltrim($originalDocument, '\\')] = $mapping;
} | [
"public",
"function",
"addResolveTargetDocument",
"(",
"string",
"$",
"originalDocument",
",",
"string",
"$",
"newDocument",
",",
"array",
"$",
"mapping",
")",
":",
"void",
"{",
"$",
"mapping",
"[",
"'targetDocument'",
"]",
"=",
"ltrim",
"(",
"$",
"newDocument",
",",
"'\\\\'",
")",
";",
"$",
"this",
"->",
"resolveTargetDocuments",
"[",
"ltrim",
"(",
"$",
"originalDocument",
",",
"'\\\\'",
")",
"]",
"=",
"$",
"mapping",
";",
"}"
] | Add a target-document class name to resolve to a new class name. | [
"Add",
"a",
"target",
"-",
"document",
"class",
"name",
"to",
"resolve",
"to",
"a",
"new",
"class",
"name",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Tools/ResolveTargetDocumentListener.php#L40-L44 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Tools/ResolveTargetDocumentListener.php | ResolveTargetDocumentListener.onClassMetadataNotFound | public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args)
{
if (! array_key_exists($args->getClassName(), $this->resolveTargetDocuments)) {
return;
}
$args->setFoundMetadata(
$args
->getDocumentManager()
->getClassMetadata($this->resolveTargetDocuments[$args->getClassName()]['targetDocument'])
);
} | php | public function onClassMetadataNotFound(OnClassMetadataNotFoundEventArgs $args)
{
if (! array_key_exists($args->getClassName(), $this->resolveTargetDocuments)) {
return;
}
$args->setFoundMetadata(
$args
->getDocumentManager()
->getClassMetadata($this->resolveTargetDocuments[$args->getClassName()]['targetDocument'])
);
} | [
"public",
"function",
"onClassMetadataNotFound",
"(",
"OnClassMetadataNotFoundEventArgs",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"args",
"->",
"getClassName",
"(",
")",
",",
"$",
"this",
"->",
"resolveTargetDocuments",
")",
")",
"{",
"return",
";",
"}",
"$",
"args",
"->",
"setFoundMetadata",
"(",
"$",
"args",
"->",
"getDocumentManager",
"(",
")",
"->",
"getClassMetadata",
"(",
"$",
"this",
"->",
"resolveTargetDocuments",
"[",
"$",
"args",
"->",
"getClassName",
"(",
")",
"]",
"[",
"'targetDocument'",
"]",
")",
")",
";",
"}"
] | @internal this is an event callback, and should not be called directly
@return void | [
"@internal",
"this",
"is",
"an",
"event",
"callback",
"and",
"should",
"not",
"be",
"called",
"directly"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Tools/ResolveTargetDocumentListener.php#L51-L62 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.ensureIndexes | public function ensureIndexes(?int $maxTimeMs = null, ?WriteConcern $writeConcern = null, bool $background = false) : void
{
foreach ($this->metadataFactory->getAllMetadata() as $class) {
assert($class instanceof ClassMetadata);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
continue;
}
$this->ensureDocumentIndexes($class->name, $maxTimeMs, $writeConcern, $background);
}
} | php | public function ensureIndexes(?int $maxTimeMs = null, ?WriteConcern $writeConcern = null, bool $background = false) : void
{
foreach ($this->metadataFactory->getAllMetadata() as $class) {
assert($class instanceof ClassMetadata);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
continue;
}
$this->ensureDocumentIndexes($class->name, $maxTimeMs, $writeConcern, $background);
}
} | [
"public",
"function",
"ensureIndexes",
"(",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
",",
"bool",
"$",
"background",
"=",
"false",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"metadataFactory",
"->",
"getAllMetadata",
"(",
")",
"as",
"$",
"class",
")",
"{",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"ensureDocumentIndexes",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
",",
"$",
"background",
")",
";",
"}",
"}"
] | Ensure indexes are created for all documents that can be loaded with the
metadata factory. | [
"Ensure",
"indexes",
"are",
"created",
"for",
"all",
"documents",
"that",
"can",
"be",
"loaded",
"with",
"the",
"metadata",
"factory",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L58-L68 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.updateDocumentIndexes | public function updateDocumentIndexes(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot update document indexes for mapped super classes, embedded documents or aggregation result documents.');
}
$documentIndexes = $this->getDocumentIndexes($documentName);
$collection = $this->dm->getDocumentCollection($documentName);
$mongoIndexes = iterator_to_array($collection->listIndexes());
/* Determine which Mongo indexes should be deleted. Exclude the ID index
* and those that are equivalent to any in the class metadata.
*/
$self = $this;
$mongoIndexes = array_filter($mongoIndexes, static function (IndexInfo $mongoIndex) use ($documentIndexes, $self) {
if ($mongoIndex['name'] === '_id_') {
return false;
}
foreach ($documentIndexes as $documentIndex) {
if ($self->isMongoIndexEquivalentToDocumentIndex($mongoIndex, $documentIndex)) {
return false;
}
}
return true;
});
// Delete indexes that do not exist in class metadata
foreach ($mongoIndexes as $mongoIndex) {
if (! isset($mongoIndex['name'])) {
continue;
}
$collection->dropIndex($mongoIndex['name'], $this->getWriteOptions($maxTimeMs, $writeConcern));
}
$this->ensureDocumentIndexes($documentName, $maxTimeMs, $writeConcern);
} | php | public function updateDocumentIndexes(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot update document indexes for mapped super classes, embedded documents or aggregation result documents.');
}
$documentIndexes = $this->getDocumentIndexes($documentName);
$collection = $this->dm->getDocumentCollection($documentName);
$mongoIndexes = iterator_to_array($collection->listIndexes());
$self = $this;
$mongoIndexes = array_filter($mongoIndexes, static function (IndexInfo $mongoIndex) use ($documentIndexes, $self) {
if ($mongoIndex['name'] === '_id_') {
return false;
}
foreach ($documentIndexes as $documentIndex) {
if ($self->isMongoIndexEquivalentToDocumentIndex($mongoIndex, $documentIndex)) {
return false;
}
}
return true;
});
foreach ($mongoIndexes as $mongoIndex) {
if (! isset($mongoIndex['name'])) {
continue;
}
$collection->dropIndex($mongoIndex['name'], $this->getWriteOptions($maxTimeMs, $writeConcern));
}
$this->ensureDocumentIndexes($documentName, $maxTimeMs, $writeConcern);
} | [
"public",
"function",
"updateDocumentIndexes",
"(",
"string",
"$",
"documentName",
",",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot update document indexes for mapped super classes, embedded documents or aggregation result documents.'",
")",
";",
"}",
"$",
"documentIndexes",
"=",
"$",
"this",
"->",
"getDocumentIndexes",
"(",
"$",
"documentName",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"dm",
"->",
"getDocumentCollection",
"(",
"$",
"documentName",
")",
";",
"$",
"mongoIndexes",
"=",
"iterator_to_array",
"(",
"$",
"collection",
"->",
"listIndexes",
"(",
")",
")",
";",
"/* Determine which Mongo indexes should be deleted. Exclude the ID index\n * and those that are equivalent to any in the class metadata.\n */",
"$",
"self",
"=",
"$",
"this",
";",
"$",
"mongoIndexes",
"=",
"array_filter",
"(",
"$",
"mongoIndexes",
",",
"static",
"function",
"(",
"IndexInfo",
"$",
"mongoIndex",
")",
"use",
"(",
"$",
"documentIndexes",
",",
"$",
"self",
")",
"{",
"if",
"(",
"$",
"mongoIndex",
"[",
"'name'",
"]",
"===",
"'_id_'",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"documentIndexes",
"as",
"$",
"documentIndex",
")",
"{",
"if",
"(",
"$",
"self",
"->",
"isMongoIndexEquivalentToDocumentIndex",
"(",
"$",
"mongoIndex",
",",
"$",
"documentIndex",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
")",
";",
"// Delete indexes that do not exist in class metadata",
"foreach",
"(",
"$",
"mongoIndexes",
"as",
"$",
"mongoIndex",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"mongoIndex",
"[",
"'name'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"collection",
"->",
"dropIndex",
"(",
"$",
"mongoIndex",
"[",
"'name'",
"]",
",",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
")",
";",
"}",
"$",
"this",
"->",
"ensureDocumentIndexes",
"(",
"$",
"documentName",
",",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
";",
"}"
] | Ensure indexes exist for the mapped document class.
Indexes that exist in MongoDB but not the document metadata will be
deleted.
@throws InvalidArgumentException | [
"Ensure",
"indexes",
"exist",
"for",
"the",
"mapped",
"document",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L96-L136 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.ensureDocumentIndexes | public function ensureDocumentIndexes(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null, bool $background = false) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot create document indexes for mapped super classes, embedded documents or query result documents.');
}
if ($class->isFile) {
$this->ensureGridFSIndexes($class, $maxTimeMs, $writeConcern, $background);
}
$indexes = $this->getDocumentIndexes($documentName);
if (! $indexes) {
return;
}
$collection = $this->dm->getDocumentCollection($class->name);
foreach ($indexes as $index) {
$collection->createIndex($index['keys'], $this->getWriteOptions($maxTimeMs, $writeConcern, $index['options'] + ['background' => $background]));
}
} | php | public function ensureDocumentIndexes(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null, bool $background = false) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot create document indexes for mapped super classes, embedded documents or query result documents.');
}
if ($class->isFile) {
$this->ensureGridFSIndexes($class, $maxTimeMs, $writeConcern, $background);
}
$indexes = $this->getDocumentIndexes($documentName);
if (! $indexes) {
return;
}
$collection = $this->dm->getDocumentCollection($class->name);
foreach ($indexes as $index) {
$collection->createIndex($index['keys'], $this->getWriteOptions($maxTimeMs, $writeConcern, $index['options'] + ['background' => $background]));
}
} | [
"public",
"function",
"ensureDocumentIndexes",
"(",
"string",
"$",
"documentName",
",",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
",",
"bool",
"$",
"background",
"=",
"false",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot create document indexes for mapped super classes, embedded documents or query result documents.'",
")",
";",
"}",
"if",
"(",
"$",
"class",
"->",
"isFile",
")",
"{",
"$",
"this",
"->",
"ensureGridFSIndexes",
"(",
"$",
"class",
",",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
",",
"$",
"background",
")",
";",
"}",
"$",
"indexes",
"=",
"$",
"this",
"->",
"getDocumentIndexes",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"!",
"$",
"indexes",
")",
"{",
"return",
";",
"}",
"$",
"collection",
"=",
"$",
"this",
"->",
"dm",
"->",
"getDocumentCollection",
"(",
"$",
"class",
"->",
"name",
")",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"index",
")",
"{",
"$",
"collection",
"->",
"createIndex",
"(",
"$",
"index",
"[",
"'keys'",
"]",
",",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
",",
"$",
"index",
"[",
"'options'",
"]",
"+",
"[",
"'background'",
"=>",
"$",
"background",
"]",
")",
")",
";",
"}",
"}"
] | Ensure the given document's indexes are created.
@throws InvalidArgumentException | [
"Ensure",
"the",
"given",
"document",
"s",
"indexes",
"are",
"created",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L240-L260 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.deleteDocumentIndexes | public function deleteDocumentIndexes(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot delete document indexes for mapped super classes, embedded documents or query result documents.');
}
$this->dm->getDocumentCollection($documentName)->dropIndexes($this->getWriteOptions($maxTimeMs, $writeConcern));
} | php | public function deleteDocumentIndexes(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot delete document indexes for mapped super classes, embedded documents or query result documents.');
}
$this->dm->getDocumentCollection($documentName)->dropIndexes($this->getWriteOptions($maxTimeMs, $writeConcern));
} | [
"public",
"function",
"deleteDocumentIndexes",
"(",
"string",
"$",
"documentName",
",",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot delete document indexes for mapped super classes, embedded documents or query result documents.'",
")",
";",
"}",
"$",
"this",
"->",
"dm",
"->",
"getDocumentCollection",
"(",
"$",
"documentName",
")",
"->",
"dropIndexes",
"(",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
")",
";",
"}"
] | Delete the given document's indexes.
@throws InvalidArgumentException | [
"Delete",
"the",
"given",
"document",
"s",
"indexes",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L283-L291 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.createCollections | public function createCollections(?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
foreach ($this->metadataFactory->getAllMetadata() as $class) {
assert($class instanceof ClassMetadata);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
continue;
}
$this->createDocumentCollection($class->name, $maxTimeMs, $writeConcern);
}
} | php | public function createCollections(?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
foreach ($this->metadataFactory->getAllMetadata() as $class) {
assert($class instanceof ClassMetadata);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
continue;
}
$this->createDocumentCollection($class->name, $maxTimeMs, $writeConcern);
}
} | [
"public",
"function",
"createCollections",
"(",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"metadataFactory",
"->",
"getAllMetadata",
"(",
")",
"as",
"$",
"class",
")",
"{",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"createDocumentCollection",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
";",
"}",
"}"
] | Create all the mapped document collections in the metadata factory. | [
"Create",
"all",
"the",
"mapped",
"document",
"collections",
"in",
"the",
"metadata",
"factory",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L296-L305 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.createDocumentCollection | public function createDocumentCollection(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot create document collection for mapped super classes, embedded documents or query result documents.');
}
if ($class->isFile) {
$options = $this->getWriteOptions($maxTimeMs, $writeConcern);
$this->dm->getDocumentDatabase($documentName)->createCollection($class->getBucketName() . '.files', $options);
$this->dm->getDocumentDatabase($documentName)->createCollection($class->getBucketName() . '.chunks', $options);
return;
}
$options = [
'capped' => $class->getCollectionCapped(),
'size' => $class->getCollectionSize(),
'max' => $class->getCollectionMax(),
];
$this->dm->getDocumentDatabase($documentName)->createCollection(
$class->getCollection(),
$this->getWriteOptions($maxTimeMs, $writeConcern, $options)
);
} | php | public function createDocumentCollection(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot create document collection for mapped super classes, embedded documents or query result documents.');
}
if ($class->isFile) {
$options = $this->getWriteOptions($maxTimeMs, $writeConcern);
$this->dm->getDocumentDatabase($documentName)->createCollection($class->getBucketName() . '.files', $options);
$this->dm->getDocumentDatabase($documentName)->createCollection($class->getBucketName() . '.chunks', $options);
return;
}
$options = [
'capped' => $class->getCollectionCapped(),
'size' => $class->getCollectionSize(),
'max' => $class->getCollectionMax(),
];
$this->dm->getDocumentDatabase($documentName)->createCollection(
$class->getCollection(),
$this->getWriteOptions($maxTimeMs, $writeConcern, $options)
);
} | [
"public",
"function",
"createDocumentCollection",
"(",
"string",
"$",
"documentName",
",",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot create document collection for mapped super classes, embedded documents or query result documents.'",
")",
";",
"}",
"if",
"(",
"$",
"class",
"->",
"isFile",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
";",
"$",
"this",
"->",
"dm",
"->",
"getDocumentDatabase",
"(",
"$",
"documentName",
")",
"->",
"createCollection",
"(",
"$",
"class",
"->",
"getBucketName",
"(",
")",
".",
"'.files'",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"dm",
"->",
"getDocumentDatabase",
"(",
"$",
"documentName",
")",
"->",
"createCollection",
"(",
"$",
"class",
"->",
"getBucketName",
"(",
")",
".",
"'.chunks'",
",",
"$",
"options",
")",
";",
"return",
";",
"}",
"$",
"options",
"=",
"[",
"'capped'",
"=>",
"$",
"class",
"->",
"getCollectionCapped",
"(",
")",
",",
"'size'",
"=>",
"$",
"class",
"->",
"getCollectionSize",
"(",
")",
",",
"'max'",
"=>",
"$",
"class",
"->",
"getCollectionMax",
"(",
")",
",",
"]",
";",
"$",
"this",
"->",
"dm",
"->",
"getDocumentDatabase",
"(",
"$",
"documentName",
")",
"->",
"createCollection",
"(",
"$",
"class",
"->",
"getCollection",
"(",
")",
",",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
",",
"$",
"options",
")",
")",
";",
"}"
] | Create the document collection for a mapped class.
@throws InvalidArgumentException | [
"Create",
"the",
"document",
"collection",
"for",
"a",
"mapped",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L312-L339 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.dropDocumentCollection | public function dropDocumentCollection(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot delete document indexes for mapped super classes, embedded documents or query result documents.');
}
$options = $this->getWriteOptions($maxTimeMs, $writeConcern);
$this->dm->getDocumentCollection($documentName)->drop($options);
if (! $class->isFile) {
return;
}
$this->dm->getDocumentBucket($documentName)->getChunksCollection()->drop($options);
} | php | public function dropDocumentCollection(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot delete document indexes for mapped super classes, embedded documents or query result documents.');
}
$options = $this->getWriteOptions($maxTimeMs, $writeConcern);
$this->dm->getDocumentCollection($documentName)->drop($options);
if (! $class->isFile) {
return;
}
$this->dm->getDocumentBucket($documentName)->getChunksCollection()->drop($options);
} | [
"public",
"function",
"dropDocumentCollection",
"(",
"string",
"$",
"documentName",
",",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot delete document indexes for mapped super classes, embedded documents or query result documents.'",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
";",
"$",
"this",
"->",
"dm",
"->",
"getDocumentCollection",
"(",
"$",
"documentName",
")",
"->",
"drop",
"(",
"$",
"options",
")",
";",
"if",
"(",
"!",
"$",
"class",
"->",
"isFile",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"dm",
"->",
"getDocumentBucket",
"(",
"$",
"documentName",
")",
"->",
"getChunksCollection",
"(",
")",
"->",
"drop",
"(",
"$",
"options",
")",
";",
"}"
] | Drop the document collection for a mapped class.
@throws InvalidArgumentException | [
"Drop",
"the",
"document",
"collection",
"for",
"a",
"mapped",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L361-L377 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.dropDocumentDatabase | public function dropDocumentDatabase(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot drop document database for mapped super classes, embedded documents or query result documents.');
}
$this->dm->getDocumentDatabase($documentName)->drop($this->getWriteOptions($maxTimeMs, $writeConcern));
} | php | public function dropDocumentDatabase(string $documentName, ?int $maxTimeMs = null, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if ($class->isMappedSuperclass || $class->isEmbeddedDocument || $class->isQueryResultDocument) {
throw new InvalidArgumentException('Cannot drop document database for mapped super classes, embedded documents or query result documents.');
}
$this->dm->getDocumentDatabase($documentName)->drop($this->getWriteOptions($maxTimeMs, $writeConcern));
} | [
"public",
"function",
"dropDocumentDatabase",
"(",
"string",
"$",
"documentName",
",",
"?",
"int",
"$",
"maxTimeMs",
"=",
"null",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"$",
"class",
"->",
"isEmbeddedDocument",
"||",
"$",
"class",
"->",
"isQueryResultDocument",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Cannot drop document database for mapped super classes, embedded documents or query result documents.'",
")",
";",
"}",
"$",
"this",
"->",
"dm",
"->",
"getDocumentDatabase",
"(",
"$",
"documentName",
")",
"->",
"drop",
"(",
"$",
"this",
"->",
"getWriteOptions",
"(",
"$",
"maxTimeMs",
",",
"$",
"writeConcern",
")",
")",
";",
"}"
] | Drop the document database for a mapped class.
@throws InvalidArgumentException | [
"Drop",
"the",
"document",
"database",
"for",
"a",
"mapped",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L399-L407 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.isEquivalentIndexKeys | private function isEquivalentIndexKeys(IndexInfo $mongoIndex, array $documentIndex) : bool
{
$mongoIndexKeys = $mongoIndex['key'];
$documentIndexKeys = $documentIndex['keys'];
/* If we are dealing with text indexes, we need to unset internal fields
* from the MongoDB index and filter out text fields from the document
* index. This will leave only non-text fields, which we can compare as
* normal. Any text fields in the document index will be compared later
* with isEquivalentTextIndexWeights(). */
if (isset($mongoIndexKeys['_fts']) && $mongoIndexKeys['_fts'] === 'text') {
unset($mongoIndexKeys['_fts'], $mongoIndexKeys['_ftsx']);
$documentIndexKeys = array_filter($documentIndexKeys, static function ($type) {
return $type !== 'text';
});
}
/* Avoid a strict equality check here. The numeric type returned by
* MongoDB may differ from the document index without implying that the
* indexes themselves are inequivalent. */
// phpcs:disable SlevomatCodingStandard.ControlStructures.DisallowEqualOperators.DisallowedEqualOperator
return $mongoIndexKeys == $documentIndexKeys;
} | php | private function isEquivalentIndexKeys(IndexInfo $mongoIndex, array $documentIndex) : bool
{
$mongoIndexKeys = $mongoIndex['key'];
$documentIndexKeys = $documentIndex['keys'];
if (isset($mongoIndexKeys['_fts']) && $mongoIndexKeys['_fts'] === 'text') {
unset($mongoIndexKeys['_fts'], $mongoIndexKeys['_ftsx']);
$documentIndexKeys = array_filter($documentIndexKeys, static function ($type) {
return $type !== 'text';
});
}
return $mongoIndexKeys == $documentIndexKeys;
} | [
"private",
"function",
"isEquivalentIndexKeys",
"(",
"IndexInfo",
"$",
"mongoIndex",
",",
"array",
"$",
"documentIndex",
")",
":",
"bool",
"{",
"$",
"mongoIndexKeys",
"=",
"$",
"mongoIndex",
"[",
"'key'",
"]",
";",
"$",
"documentIndexKeys",
"=",
"$",
"documentIndex",
"[",
"'keys'",
"]",
";",
"/* If we are dealing with text indexes, we need to unset internal fields\n * from the MongoDB index and filter out text fields from the document\n * index. This will leave only non-text fields, which we can compare as\n * normal. Any text fields in the document index will be compared later\n * with isEquivalentTextIndexWeights(). */",
"if",
"(",
"isset",
"(",
"$",
"mongoIndexKeys",
"[",
"'_fts'",
"]",
")",
"&&",
"$",
"mongoIndexKeys",
"[",
"'_fts'",
"]",
"===",
"'text'",
")",
"{",
"unset",
"(",
"$",
"mongoIndexKeys",
"[",
"'_fts'",
"]",
",",
"$",
"mongoIndexKeys",
"[",
"'_ftsx'",
"]",
")",
";",
"$",
"documentIndexKeys",
"=",
"array_filter",
"(",
"$",
"documentIndexKeys",
",",
"static",
"function",
"(",
"$",
"type",
")",
"{",
"return",
"$",
"type",
"!==",
"'text'",
";",
"}",
")",
";",
"}",
"/* Avoid a strict equality check here. The numeric type returned by\n * MongoDB may differ from the document index without implying that the\n * indexes themselves are inequivalent. */",
"// phpcs:disable SlevomatCodingStandard.ControlStructures.DisallowEqualOperators.DisallowedEqualOperator",
"return",
"$",
"mongoIndexKeys",
"==",
"$",
"documentIndexKeys",
";",
"}"
] | Determine if the keys for a MongoDB index can be considered equivalent to
those for an index in class metadata. | [
"Determine",
"if",
"the",
"keys",
"for",
"a",
"MongoDB",
"index",
"can",
"be",
"considered",
"equivalent",
"to",
"those",
"for",
"an",
"index",
"in",
"class",
"metadata",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L418-L441 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.isEquivalentIndexOptions | private function isEquivalentIndexOptions(IndexInfo $mongoIndex, array $documentIndex) : bool
{
$mongoIndexOptions = $mongoIndex->__debugInfo();
unset($mongoIndexOptions['v'], $mongoIndexOptions['ns'], $mongoIndexOptions['key']);
$documentIndexOptions = $documentIndex['options'];
if ($this->indexOptionsAreMissing($mongoIndexOptions, $documentIndexOptions)) {
return false;
}
if (empty($mongoIndexOptions['sparse']) xor empty($documentIndexOptions['sparse'])) {
return false;
}
if (empty($mongoIndexOptions['unique']) xor empty($documentIndexOptions['unique'])) {
return false;
}
foreach (['bits', 'max', 'min'] as $option) {
if (isset($mongoIndexOptions[$option], $documentIndexOptions[$option]) &&
$mongoIndexOptions[$option] !== $documentIndexOptions[$option]) {
return false;
}
}
if (empty($mongoIndexOptions['partialFilterExpression']) xor empty($documentIndexOptions['partialFilterExpression'])) {
return false;
}
if (isset($mongoIndexOptions['partialFilterExpression'], $documentIndexOptions['partialFilterExpression']) &&
$mongoIndexOptions['partialFilterExpression'] !== $documentIndexOptions['partialFilterExpression']) {
return false;
}
if (isset($mongoIndexOptions['weights']) && ! $this->isEquivalentTextIndexWeights($mongoIndex, $documentIndex)) {
return false;
}
foreach (['default_language', 'language_override', 'textIndexVersion'] as $option) {
/* Text indexes will always report defaults for these options, so
* only compare if we have explicit values in the document index. */
if (isset($mongoIndexOptions[$option], $documentIndexOptions[$option]) &&
$mongoIndexOptions[$option] !== $documentIndexOptions[$option]) {
return false;
}
}
return true;
} | php | private function isEquivalentIndexOptions(IndexInfo $mongoIndex, array $documentIndex) : bool
{
$mongoIndexOptions = $mongoIndex->__debugInfo();
unset($mongoIndexOptions['v'], $mongoIndexOptions['ns'], $mongoIndexOptions['key']);
$documentIndexOptions = $documentIndex['options'];
if ($this->indexOptionsAreMissing($mongoIndexOptions, $documentIndexOptions)) {
return false;
}
if (empty($mongoIndexOptions['sparse']) xor empty($documentIndexOptions['sparse'])) {
return false;
}
if (empty($mongoIndexOptions['unique']) xor empty($documentIndexOptions['unique'])) {
return false;
}
foreach (['bits', 'max', 'min'] as $option) {
if (isset($mongoIndexOptions[$option], $documentIndexOptions[$option]) &&
$mongoIndexOptions[$option] !== $documentIndexOptions[$option]) {
return false;
}
}
if (empty($mongoIndexOptions['partialFilterExpression']) xor empty($documentIndexOptions['partialFilterExpression'])) {
return false;
}
if (isset($mongoIndexOptions['partialFilterExpression'], $documentIndexOptions['partialFilterExpression']) &&
$mongoIndexOptions['partialFilterExpression'] !== $documentIndexOptions['partialFilterExpression']) {
return false;
}
if (isset($mongoIndexOptions['weights']) && ! $this->isEquivalentTextIndexWeights($mongoIndex, $documentIndex)) {
return false;
}
foreach (['default_language', 'language_override', 'textIndexVersion'] as $option) {
if (isset($mongoIndexOptions[$option], $documentIndexOptions[$option]) &&
$mongoIndexOptions[$option] !== $documentIndexOptions[$option]) {
return false;
}
}
return true;
} | [
"private",
"function",
"isEquivalentIndexOptions",
"(",
"IndexInfo",
"$",
"mongoIndex",
",",
"array",
"$",
"documentIndex",
")",
":",
"bool",
"{",
"$",
"mongoIndexOptions",
"=",
"$",
"mongoIndex",
"->",
"__debugInfo",
"(",
")",
";",
"unset",
"(",
"$",
"mongoIndexOptions",
"[",
"'v'",
"]",
",",
"$",
"mongoIndexOptions",
"[",
"'ns'",
"]",
",",
"$",
"mongoIndexOptions",
"[",
"'key'",
"]",
")",
";",
"$",
"documentIndexOptions",
"=",
"$",
"documentIndex",
"[",
"'options'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"indexOptionsAreMissing",
"(",
"$",
"mongoIndexOptions",
",",
"$",
"documentIndexOptions",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"mongoIndexOptions",
"[",
"'sparse'",
"]",
")",
"xor",
"empty",
"(",
"$",
"documentIndexOptions",
"[",
"'sparse'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"mongoIndexOptions",
"[",
"'unique'",
"]",
")",
"xor",
"empty",
"(",
"$",
"documentIndexOptions",
"[",
"'unique'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"[",
"'bits'",
",",
"'max'",
",",
"'min'",
"]",
"as",
"$",
"option",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mongoIndexOptions",
"[",
"$",
"option",
"]",
",",
"$",
"documentIndexOptions",
"[",
"$",
"option",
"]",
")",
"&&",
"$",
"mongoIndexOptions",
"[",
"$",
"option",
"]",
"!==",
"$",
"documentIndexOptions",
"[",
"$",
"option",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"mongoIndexOptions",
"[",
"'partialFilterExpression'",
"]",
")",
"xor",
"empty",
"(",
"$",
"documentIndexOptions",
"[",
"'partialFilterExpression'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mongoIndexOptions",
"[",
"'partialFilterExpression'",
"]",
",",
"$",
"documentIndexOptions",
"[",
"'partialFilterExpression'",
"]",
")",
"&&",
"$",
"mongoIndexOptions",
"[",
"'partialFilterExpression'",
"]",
"!==",
"$",
"documentIndexOptions",
"[",
"'partialFilterExpression'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"mongoIndexOptions",
"[",
"'weights'",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"isEquivalentTextIndexWeights",
"(",
"$",
"mongoIndex",
",",
"$",
"documentIndex",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"[",
"'default_language'",
",",
"'language_override'",
",",
"'textIndexVersion'",
"]",
"as",
"$",
"option",
")",
"{",
"/* Text indexes will always report defaults for these options, so\n * only compare if we have explicit values in the document index. */",
"if",
"(",
"isset",
"(",
"$",
"mongoIndexOptions",
"[",
"$",
"option",
"]",
",",
"$",
"documentIndexOptions",
"[",
"$",
"option",
"]",
")",
"&&",
"$",
"mongoIndexOptions",
"[",
"$",
"option",
"]",
"!==",
"$",
"documentIndexOptions",
"[",
"$",
"option",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Determine if an index returned by MongoCollection::getIndexInfo() can be
considered equivalent to an index in class metadata based on options.
Indexes are considered different if:
(a) Key/direction pairs differ or are not in the same order
(b) Sparse or unique options differ
(c) Geospatial options differ (bits, max, min)
(d) The partialFilterExpression differs
The background option is only relevant to index creation and is not
considered. | [
"Determine",
"if",
"an",
"index",
"returned",
"by",
"MongoCollection",
"::",
"getIndexInfo",
"()",
"can",
"be",
"considered",
"equivalent",
"to",
"an",
"index",
"in",
"class",
"metadata",
"based",
"on",
"options",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L457-L506 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.indexOptionsAreMissing | private function indexOptionsAreMissing(array $mongoIndexOptions, array $documentIndexOptions) : bool
{
foreach (self::ALLOWED_MISSING_INDEX_OPTIONS as $option) {
unset($mongoIndexOptions[$option], $documentIndexOptions[$option]);
}
return array_diff_key($mongoIndexOptions, $documentIndexOptions) !== [] || array_diff_key($documentIndexOptions, $mongoIndexOptions) !== [];
} | php | private function indexOptionsAreMissing(array $mongoIndexOptions, array $documentIndexOptions) : bool
{
foreach (self::ALLOWED_MISSING_INDEX_OPTIONS as $option) {
unset($mongoIndexOptions[$option], $documentIndexOptions[$option]);
}
return array_diff_key($mongoIndexOptions, $documentIndexOptions) !== [] || array_diff_key($documentIndexOptions, $mongoIndexOptions) !== [];
} | [
"private",
"function",
"indexOptionsAreMissing",
"(",
"array",
"$",
"mongoIndexOptions",
",",
"array",
"$",
"documentIndexOptions",
")",
":",
"bool",
"{",
"foreach",
"(",
"self",
"::",
"ALLOWED_MISSING_INDEX_OPTIONS",
"as",
"$",
"option",
")",
"{",
"unset",
"(",
"$",
"mongoIndexOptions",
"[",
"$",
"option",
"]",
",",
"$",
"documentIndexOptions",
"[",
"$",
"option",
"]",
")",
";",
"}",
"return",
"array_diff_key",
"(",
"$",
"mongoIndexOptions",
",",
"$",
"documentIndexOptions",
")",
"!==",
"[",
"]",
"||",
"array_diff_key",
"(",
"$",
"documentIndexOptions",
",",
"$",
"mongoIndexOptions",
")",
"!==",
"[",
"]",
";",
"}"
] | Checks if any index options are missing.
Options added to the ALLOWED_MISSING_INDEX_OPTIONS constant are ignored
and are expected to be checked later | [
"Checks",
"if",
"any",
"index",
"options",
"are",
"missing",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L514-L521 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.isEquivalentTextIndexWeights | private function isEquivalentTextIndexWeights(IndexInfo $mongoIndex, array $documentIndex) : bool
{
$mongoIndexWeights = $mongoIndex['weights'];
$documentIndexWeights = $documentIndex['options']['weights'] ?? [];
// If not specified, assign a default weight for text fields
foreach ($documentIndex['keys'] as $key => $type) {
if ($type !== 'text' || isset($documentIndexWeights[$key])) {
continue;
}
$documentIndexWeights[$key] = 1;
}
/* MongoDB returns the weights sorted by field name, but we'll sort both
* arrays in case that is internal behavior not to be relied upon. */
ksort($mongoIndexWeights);
ksort($documentIndexWeights);
/* Avoid a strict equality check here. The numeric type returned by
* MongoDB may differ from the document index without implying that the
* indexes themselves are inequivalent. */
// phpcs:disable SlevomatCodingStandard.ControlStructures.DisallowEqualOperators.DisallowedEqualOperator
return $mongoIndexWeights == $documentIndexWeights;
} | php | private function isEquivalentTextIndexWeights(IndexInfo $mongoIndex, array $documentIndex) : bool
{
$mongoIndexWeights = $mongoIndex['weights'];
$documentIndexWeights = $documentIndex['options']['weights'] ?? [];
foreach ($documentIndex['keys'] as $key => $type) {
if ($type !== 'text' || isset($documentIndexWeights[$key])) {
continue;
}
$documentIndexWeights[$key] = 1;
}
ksort($mongoIndexWeights);
ksort($documentIndexWeights);
return $mongoIndexWeights == $documentIndexWeights;
} | [
"private",
"function",
"isEquivalentTextIndexWeights",
"(",
"IndexInfo",
"$",
"mongoIndex",
",",
"array",
"$",
"documentIndex",
")",
":",
"bool",
"{",
"$",
"mongoIndexWeights",
"=",
"$",
"mongoIndex",
"[",
"'weights'",
"]",
";",
"$",
"documentIndexWeights",
"=",
"$",
"documentIndex",
"[",
"'options'",
"]",
"[",
"'weights'",
"]",
"??",
"[",
"]",
";",
"// If not specified, assign a default weight for text fields",
"foreach",
"(",
"$",
"documentIndex",
"[",
"'keys'",
"]",
"as",
"$",
"key",
"=>",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"!==",
"'text'",
"||",
"isset",
"(",
"$",
"documentIndexWeights",
"[",
"$",
"key",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"documentIndexWeights",
"[",
"$",
"key",
"]",
"=",
"1",
";",
"}",
"/* MongoDB returns the weights sorted by field name, but we'll sort both\n * arrays in case that is internal behavior not to be relied upon. */",
"ksort",
"(",
"$",
"mongoIndexWeights",
")",
";",
"ksort",
"(",
"$",
"documentIndexWeights",
")",
";",
"/* Avoid a strict equality check here. The numeric type returned by\n * MongoDB may differ from the document index without implying that the\n * indexes themselves are inequivalent. */",
"// phpcs:disable SlevomatCodingStandard.ControlStructures.DisallowEqualOperators.DisallowedEqualOperator",
"return",
"$",
"mongoIndexWeights",
"==",
"$",
"documentIndexWeights",
";",
"}"
] | Determine if the text index weights for a MongoDB index can be considered
equivalent to those for an index in class metadata. | [
"Determine",
"if",
"the",
"text",
"index",
"weights",
"for",
"a",
"MongoDB",
"index",
"can",
"be",
"considered",
"equivalent",
"to",
"those",
"for",
"an",
"index",
"in",
"class",
"metadata",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L527-L551 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.ensureSharding | public function ensureSharding(?WriteConcern $writeConcern = null) : void
{
foreach ($this->metadataFactory->getAllMetadata() as $class) {
assert($class instanceof ClassMetadata);
if ($class->isMappedSuperclass || ! $class->isSharded()) {
continue;
}
$this->ensureDocumentSharding($class->name, $writeConcern);
}
} | php | public function ensureSharding(?WriteConcern $writeConcern = null) : void
{
foreach ($this->metadataFactory->getAllMetadata() as $class) {
assert($class instanceof ClassMetadata);
if ($class->isMappedSuperclass || ! $class->isSharded()) {
continue;
}
$this->ensureDocumentSharding($class->name, $writeConcern);
}
} | [
"public",
"function",
"ensureSharding",
"(",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"metadataFactory",
"->",
"getAllMetadata",
"(",
")",
"as",
"$",
"class",
")",
"{",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"if",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"||",
"!",
"$",
"class",
"->",
"isSharded",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"ensureDocumentSharding",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"writeConcern",
")",
";",
"}",
"}"
] | Ensure collections are sharded for all documents that can be loaded with the
metadata factory.
@throws MongoDBException | [
"Ensure",
"collections",
"are",
"sharded",
"for",
"all",
"documents",
"that",
"can",
"be",
"loaded",
"with",
"the",
"metadata",
"factory",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L559-L569 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.ensureDocumentSharding | public function ensureDocumentSharding(string $documentName, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if (! $class->isSharded()) {
return;
}
if ($this->collectionIsSharded($documentName)) {
return;
}
$this->enableShardingForDbByDocumentName($documentName);
try {
$this->runShardCollectionCommand($documentName, $writeConcern);
} catch (RuntimeException $e) {
throw MongoDBException::failedToEnsureDocumentSharding($documentName, $e->getMessage());
}
} | php | public function ensureDocumentSharding(string $documentName, ?WriteConcern $writeConcern = null) : void
{
$class = $this->dm->getClassMetadata($documentName);
if (! $class->isSharded()) {
return;
}
if ($this->collectionIsSharded($documentName)) {
return;
}
$this->enableShardingForDbByDocumentName($documentName);
try {
$this->runShardCollectionCommand($documentName, $writeConcern);
} catch (RuntimeException $e) {
throw MongoDBException::failedToEnsureDocumentSharding($documentName, $e->getMessage());
}
} | [
"public",
"function",
"ensureDocumentSharding",
"(",
"string",
"$",
"documentName",
",",
"?",
"WriteConcern",
"$",
"writeConcern",
"=",
"null",
")",
":",
"void",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"!",
"$",
"class",
"->",
"isSharded",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"collectionIsSharded",
"(",
"$",
"documentName",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"enableShardingForDbByDocumentName",
"(",
"$",
"documentName",
")",
";",
"try",
"{",
"$",
"this",
"->",
"runShardCollectionCommand",
"(",
"$",
"documentName",
",",
"$",
"writeConcern",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"throw",
"MongoDBException",
"::",
"failedToEnsureDocumentSharding",
"(",
"$",
"documentName",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Ensure sharding for collection by document name.
@throws MongoDBException | [
"Ensure",
"sharding",
"for",
"collection",
"by",
"document",
"name",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L576-L594 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/SchemaManager.php | SchemaManager.enableShardingForDbByDocumentName | public function enableShardingForDbByDocumentName(string $documentName) : void
{
$dbName = $this->dm->getDocumentDatabase($documentName)->getDatabaseName();
$adminDb = $this->dm->getClient()->selectDatabase('admin');
try {
$adminDb->command(['enableSharding' => $dbName]);
} catch (ServerException $e) {
// Don't throw an exception if sharding is already enabled; there's just no other way to check this
if ($e->getCode() !== self::CODE_SHARDING_ALREADY_INITIALIZED) {
throw MongoDBException::failedToEnableSharding($dbName, $e->getMessage());
}
} catch (RuntimeException $e) {
throw MongoDBException::failedToEnableSharding($dbName, $e->getMessage());
}
} | php | public function enableShardingForDbByDocumentName(string $documentName) : void
{
$dbName = $this->dm->getDocumentDatabase($documentName)->getDatabaseName();
$adminDb = $this->dm->getClient()->selectDatabase('admin');
try {
$adminDb->command(['enableSharding' => $dbName]);
} catch (ServerException $e) {
if ($e->getCode() !== self::CODE_SHARDING_ALREADY_INITIALIZED) {
throw MongoDBException::failedToEnableSharding($dbName, $e->getMessage());
}
} catch (RuntimeException $e) {
throw MongoDBException::failedToEnableSharding($dbName, $e->getMessage());
}
} | [
"public",
"function",
"enableShardingForDbByDocumentName",
"(",
"string",
"$",
"documentName",
")",
":",
"void",
"{",
"$",
"dbName",
"=",
"$",
"this",
"->",
"dm",
"->",
"getDocumentDatabase",
"(",
"$",
"documentName",
")",
"->",
"getDatabaseName",
"(",
")",
";",
"$",
"adminDb",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClient",
"(",
")",
"->",
"selectDatabase",
"(",
"'admin'",
")",
";",
"try",
"{",
"$",
"adminDb",
"->",
"command",
"(",
"[",
"'enableSharding'",
"=>",
"$",
"dbName",
"]",
")",
";",
"}",
"catch",
"(",
"ServerException",
"$",
"e",
")",
"{",
"// Don't throw an exception if sharding is already enabled; there's just no other way to check this",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"!==",
"self",
"::",
"CODE_SHARDING_ALREADY_INITIALIZED",
")",
"{",
"throw",
"MongoDBException",
"::",
"failedToEnableSharding",
"(",
"$",
"dbName",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"throw",
"MongoDBException",
"::",
"failedToEnableSharding",
"(",
"$",
"dbName",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Enable sharding for database which contains documents with given name.
@throws MongoDBException | [
"Enable",
"sharding",
"for",
"database",
"which",
"contains",
"documents",
"with",
"given",
"name",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/SchemaManager.php#L601-L616 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.create | public static function create(?Client $client = null, ?Configuration $config = null, ?EventManager $eventManager = null) : DocumentManager
{
return new static($client, $config, $eventManager);
} | php | public static function create(?Client $client = null, ?Configuration $config = null, ?EventManager $eventManager = null) : DocumentManager
{
return new static($client, $config, $eventManager);
} | [
"public",
"static",
"function",
"create",
"(",
"?",
"Client",
"$",
"client",
"=",
"null",
",",
"?",
"Configuration",
"$",
"config",
"=",
"null",
",",
"?",
"EventManager",
"$",
"eventManager",
"=",
"null",
")",
":",
"DocumentManager",
"{",
"return",
"new",
"static",
"(",
"$",
"client",
",",
"$",
"config",
",",
"$",
"eventManager",
")",
";",
"}"
] | Creates a new Document that operates on the given Mongo connection
and uses the given Configuration. | [
"Creates",
"a",
"new",
"Document",
"that",
"operates",
"on",
"the",
"given",
"Mongo",
"connection",
"and",
"uses",
"the",
"given",
"Configuration",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L201-L204 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.getDocumentDatabase | public function getDocumentDatabase(string $className) : Database
{
$className = $this->classNameResolver->getRealClass($className);
if (isset($this->documentDatabases[$className])) {
return $this->documentDatabases[$className];
}
$metadata = $this->metadataFactory->getMetadataFor($className);
assert($metadata instanceof ClassMetadata);
$db = $metadata->getDatabase();
$db = $db ?: $this->config->getDefaultDB();
$db = $db ?: 'doctrine';
$this->documentDatabases[$className] = $this->client->selectDatabase($db);
return $this->documentDatabases[$className];
} | php | public function getDocumentDatabase(string $className) : Database
{
$className = $this->classNameResolver->getRealClass($className);
if (isset($this->documentDatabases[$className])) {
return $this->documentDatabases[$className];
}
$metadata = $this->metadataFactory->getMetadataFor($className);
assert($metadata instanceof ClassMetadata);
$db = $metadata->getDatabase();
$db = $db ?: $this->config->getDefaultDB();
$db = $db ?: 'doctrine';
$this->documentDatabases[$className] = $this->client->selectDatabase($db);
return $this->documentDatabases[$className];
} | [
"public",
"function",
"getDocumentDatabase",
"(",
"string",
"$",
"className",
")",
":",
"Database",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"classNameResolver",
"->",
"getRealClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"documentDatabases",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"documentDatabases",
"[",
"$",
"className",
"]",
";",
"}",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"className",
")",
";",
"assert",
"(",
"$",
"metadata",
"instanceof",
"ClassMetadata",
")",
";",
"$",
"db",
"=",
"$",
"metadata",
"->",
"getDatabase",
"(",
")",
";",
"$",
"db",
"=",
"$",
"db",
"?",
":",
"$",
"this",
"->",
"config",
"->",
"getDefaultDB",
"(",
")",
";",
"$",
"db",
"=",
"$",
"db",
"?",
":",
"'doctrine'",
";",
"$",
"this",
"->",
"documentDatabases",
"[",
"$",
"className",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"selectDatabase",
"(",
"$",
"db",
")",
";",
"return",
"$",
"this",
"->",
"documentDatabases",
"[",
"$",
"className",
"]",
";",
"}"
] | Returns the MongoDB instance for a class. | [
"Returns",
"the",
"MongoDB",
"instance",
"for",
"a",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L290-L307 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.getDocumentCollection | public function getDocumentCollection(string $className) : Collection
{
$className = $this->classNameResolver->getRealClass($className);
/** @var ClassMetadata $metadata */
$metadata = $this->metadataFactory->getMetadataFor($className);
assert($metadata instanceof ClassMetadata);
if ($metadata->isFile) {
return $this->getDocumentBucket($className)->getFilesCollection();
}
$collectionName = $metadata->getCollection();
if (! $collectionName) {
throw MongoDBException::documentNotMappedToCollection($className);
}
if (! isset($this->documentCollections[$className])) {
$db = $this->getDocumentDatabase($className);
$options = [];
if ($metadata->readPreference !== null) {
$options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
}
$this->documentCollections[$className] = $db->selectCollection($collectionName, $options);
}
return $this->documentCollections[$className];
} | php | public function getDocumentCollection(string $className) : Collection
{
$className = $this->classNameResolver->getRealClass($className);
$metadata = $this->metadataFactory->getMetadataFor($className);
assert($metadata instanceof ClassMetadata);
if ($metadata->isFile) {
return $this->getDocumentBucket($className)->getFilesCollection();
}
$collectionName = $metadata->getCollection();
if (! $collectionName) {
throw MongoDBException::documentNotMappedToCollection($className);
}
if (! isset($this->documentCollections[$className])) {
$db = $this->getDocumentDatabase($className);
$options = [];
if ($metadata->readPreference !== null) {
$options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
}
$this->documentCollections[$className] = $db->selectCollection($collectionName, $options);
}
return $this->documentCollections[$className];
} | [
"public",
"function",
"getDocumentCollection",
"(",
"string",
"$",
"className",
")",
":",
"Collection",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"classNameResolver",
"->",
"getRealClass",
"(",
"$",
"className",
")",
";",
"/** @var ClassMetadata $metadata */",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"className",
")",
";",
"assert",
"(",
"$",
"metadata",
"instanceof",
"ClassMetadata",
")",
";",
"if",
"(",
"$",
"metadata",
"->",
"isFile",
")",
"{",
"return",
"$",
"this",
"->",
"getDocumentBucket",
"(",
"$",
"className",
")",
"->",
"getFilesCollection",
"(",
")",
";",
"}",
"$",
"collectionName",
"=",
"$",
"metadata",
"->",
"getCollection",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collectionName",
")",
"{",
"throw",
"MongoDBException",
"::",
"documentNotMappedToCollection",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"documentCollections",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getDocumentDatabase",
"(",
"$",
"className",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"metadata",
"->",
"readPreference",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"new",
"ReadPreference",
"(",
"$",
"metadata",
"->",
"readPreference",
",",
"$",
"metadata",
"->",
"readPreferenceTags",
")",
";",
"}",
"$",
"this",
"->",
"documentCollections",
"[",
"$",
"className",
"]",
"=",
"$",
"db",
"->",
"selectCollection",
"(",
"$",
"collectionName",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"documentCollections",
"[",
"$",
"className",
"]",
";",
"}"
] | Returns the collection instance for a class.
@throws MongoDBException When the $className param is not mapped to a collection. | [
"Returns",
"the",
"collection",
"instance",
"for",
"a",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L324-L353 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.getDocumentBucket | public function getDocumentBucket(string $className) : Bucket
{
$className = $this->classNameResolver->getRealClass($className);
/** @var ClassMetadata $metadata */
$metadata = $this->metadataFactory->getMetadataFor($className);
if (! $metadata->isFile) {
throw MongoDBException::documentBucketOnlyAvailableForGridFSFiles($className);
}
$bucketName = $metadata->getBucketName();
if (! $bucketName) {
throw MongoDBException::documentNotMappedToCollection($className);
}
if (! isset($this->documentBuckets[$className])) {
$db = $this->getDocumentDatabase($className);
$options = ['bucketName' => $bucketName];
if ($metadata->readPreference !== null) {
$options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
}
$this->documentBuckets[$className] = $db->selectGridFSBucket($options);
}
return $this->documentBuckets[$className];
} | php | public function getDocumentBucket(string $className) : Bucket
{
$className = $this->classNameResolver->getRealClass($className);
$metadata = $this->metadataFactory->getMetadataFor($className);
if (! $metadata->isFile) {
throw MongoDBException::documentBucketOnlyAvailableForGridFSFiles($className);
}
$bucketName = $metadata->getBucketName();
if (! $bucketName) {
throw MongoDBException::documentNotMappedToCollection($className);
}
if (! isset($this->documentBuckets[$className])) {
$db = $this->getDocumentDatabase($className);
$options = ['bucketName' => $bucketName];
if ($metadata->readPreference !== null) {
$options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
}
$this->documentBuckets[$className] = $db->selectGridFSBucket($options);
}
return $this->documentBuckets[$className];
} | [
"public",
"function",
"getDocumentBucket",
"(",
"string",
"$",
"className",
")",
":",
"Bucket",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"classNameResolver",
"->",
"getRealClass",
"(",
"$",
"className",
")",
";",
"/** @var ClassMetadata $metadata */",
"$",
"metadata",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"$",
"metadata",
"->",
"isFile",
")",
"{",
"throw",
"MongoDBException",
"::",
"documentBucketOnlyAvailableForGridFSFiles",
"(",
"$",
"className",
")",
";",
"}",
"$",
"bucketName",
"=",
"$",
"metadata",
"->",
"getBucketName",
"(",
")",
";",
"if",
"(",
"!",
"$",
"bucketName",
")",
"{",
"throw",
"MongoDBException",
"::",
"documentNotMappedToCollection",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"documentBuckets",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getDocumentDatabase",
"(",
"$",
"className",
")",
";",
"$",
"options",
"=",
"[",
"'bucketName'",
"=>",
"$",
"bucketName",
"]",
";",
"if",
"(",
"$",
"metadata",
"->",
"readPreference",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'readPreference'",
"]",
"=",
"new",
"ReadPreference",
"(",
"$",
"metadata",
"->",
"readPreference",
",",
"$",
"metadata",
"->",
"readPreferenceTags",
")",
";",
"}",
"$",
"this",
"->",
"documentBuckets",
"[",
"$",
"className",
"]",
"=",
"$",
"db",
"->",
"selectGridFSBucket",
"(",
"$",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"documentBuckets",
"[",
"$",
"className",
"]",
";",
"}"
] | Returns the bucket instance for a class.
@throws MongoDBException When the $className param is not mapped to a collection. | [
"Returns",
"the",
"bucket",
"instance",
"for",
"a",
"class",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L360-L388 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.lock | public function lock(object $document, int $lockMode, ?int $lockVersion = null) : void
{
$this->unitOfWork->lock($document, $lockMode, $lockVersion);
} | php | public function lock(object $document, int $lockMode, ?int $lockVersion = null) : void
{
$this->unitOfWork->lock($document, $lockMode, $lockVersion);
} | [
"public",
"function",
"lock",
"(",
"object",
"$",
"document",
",",
"int",
"$",
"lockMode",
",",
"?",
"int",
"$",
"lockVersion",
"=",
"null",
")",
":",
"void",
"{",
"$",
"this",
"->",
"unitOfWork",
"->",
"lock",
"(",
"$",
"document",
",",
"$",
"lockMode",
",",
"$",
"lockVersion",
")",
";",
"}"
] | Acquire a lock on the given document.
@throws InvalidArgumentException
@throws LockException | [
"Acquire",
"a",
"lock",
"on",
"the",
"given",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L522-L525 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.getPartialReference | public function getPartialReference(string $documentName, $identifier) : object
{
$class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\'));
assert($class instanceof ClassMetadata);
$document = $this->unitOfWork->tryGetById($identifier, $class);
// Check identity map first, if its already in there just return it.
if ($document) {
return $document;
}
$document = $class->newInstance();
$class->setIdentifierValue($document, $identifier);
$this->unitOfWork->registerManaged($document, $identifier, []);
return $document;
} | php | public function getPartialReference(string $documentName, $identifier) : object
{
$class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\'));
assert($class instanceof ClassMetadata);
$document = $this->unitOfWork->tryGetById($identifier, $class);
if ($document) {
return $document;
}
$document = $class->newInstance();
$class->setIdentifierValue($document, $identifier);
$this->unitOfWork->registerManaged($document, $identifier, []);
return $document;
} | [
"public",
"function",
"getPartialReference",
"(",
"string",
"$",
"documentName",
",",
"$",
"identifier",
")",
":",
"object",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"metadataFactory",
"->",
"getMetadataFor",
"(",
"ltrim",
"(",
"$",
"documentName",
",",
"'\\\\'",
")",
")",
";",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"$",
"document",
"=",
"$",
"this",
"->",
"unitOfWork",
"->",
"tryGetById",
"(",
"$",
"identifier",
",",
"$",
"class",
")",
";",
"// Check identity map first, if its already in there just return it.",
"if",
"(",
"$",
"document",
")",
"{",
"return",
"$",
"document",
";",
"}",
"$",
"document",
"=",
"$",
"class",
"->",
"newInstance",
"(",
")",
";",
"$",
"class",
"->",
"setIdentifierValue",
"(",
"$",
"document",
",",
"$",
"identifier",
")",
";",
"$",
"this",
"->",
"unitOfWork",
"->",
"registerManaged",
"(",
"$",
"document",
",",
"$",
"identifier",
",",
"[",
"]",
")",
";",
"return",
"$",
"document",
";",
"}"
] | Gets a partial reference to the document identified by the given type and identifier
without actually loading it, if the document is not yet loaded.
The returned reference may be a partial object if the document is not yet loaded/managed.
If it is a partial object it will not initialize the rest of the document state on access.
Thus you can only ever safely access the identifier of a document obtained through
this method.
The use-cases for partial references involve maintaining bidirectional associations
without loading one side of the association or to update a document without loading it.
Note, however, that in the latter case the original (persistent) document data will
never be visible to the application (especially not event listeners) as it will
never be loaded in the first place.
@param mixed $identifier The document identifier. | [
"Gets",
"a",
"partial",
"reference",
"to",
"the",
"document",
"identified",
"by",
"the",
"given",
"type",
"and",
"identifier",
"without",
"actually",
"loading",
"it",
"if",
"the",
"document",
"is",
"not",
"yet",
"loaded",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L606-L621 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.find | public function find($documentName, $identifier, $lockMode = LockMode::NONE, $lockVersion = null) : ?object
{
$repository = $this->getRepository($documentName);
if ($repository instanceof DocumentRepository) {
return $repository->find($identifier, $lockMode, $lockVersion);
}
return $repository->find($identifier);
} | php | public function find($documentName, $identifier, $lockMode = LockMode::NONE, $lockVersion = null) : ?object
{
$repository = $this->getRepository($documentName);
if ($repository instanceof DocumentRepository) {
return $repository->find($identifier, $lockMode, $lockVersion);
}
return $repository->find($identifier);
} | [
"public",
"function",
"find",
"(",
"$",
"documentName",
",",
"$",
"identifier",
",",
"$",
"lockMode",
"=",
"LockMode",
"::",
"NONE",
",",
"$",
"lockVersion",
"=",
"null",
")",
":",
"?",
"object",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"getRepository",
"(",
"$",
"documentName",
")",
";",
"if",
"(",
"$",
"repository",
"instanceof",
"DocumentRepository",
")",
"{",
"return",
"$",
"repository",
"->",
"find",
"(",
"$",
"identifier",
",",
"$",
"lockMode",
",",
"$",
"lockVersion",
")",
";",
"}",
"return",
"$",
"repository",
"->",
"find",
"(",
"$",
"identifier",
")",
";",
"}"
] | Finds a Document by its identifier.
This is just a convenient shortcut for getRepository($documentName)->find($id).
@param string $documentName
@param mixed $identifier
@param int $lockMode
@param int $lockVersion | [
"Finds",
"a",
"Document",
"by",
"its",
"identifier",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L633-L641 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.createReference | public function createReference(object $document, array $referenceMapping)
{
$class = $this->getClassMetadata(get_class($document));
$id = $this->unitOfWork->getDocumentIdentifier($document);
if ($id === null) {
throw new RuntimeException(
sprintf('Cannot create a DBRef for class %s without an identifier. Have you forgotten to persist/merge the document first?', $class->name)
);
}
$storeAs = $referenceMapping['storeAs'] ?? null;
switch ($storeAs) {
case ClassMetadata::REFERENCE_STORE_AS_ID:
if ($class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION) {
throw MappingException::simpleReferenceMustNotTargetDiscriminatedDocument($referenceMapping['targetDocument']);
}
return $class->getDatabaseIdentifierValue($id);
break;
case ClassMetadata::REFERENCE_STORE_AS_REF:
$reference = ['id' => $class->getDatabaseIdentifierValue($id)];
break;
case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
$reference = [
'$ref' => $class->getCollection(),
'$id' => $class->getDatabaseIdentifierValue($id),
];
break;
case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
$reference = [
'$ref' => $class->getCollection(),
'$id' => $class->getDatabaseIdentifierValue($id),
'$db' => $this->getDocumentDatabase($class->name)->getDatabaseName(),
];
break;
default:
throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
}
return $reference + $this->getDiscriminatorData($referenceMapping, $class);
} | php | public function createReference(object $document, array $referenceMapping)
{
$class = $this->getClassMetadata(get_class($document));
$id = $this->unitOfWork->getDocumentIdentifier($document);
if ($id === null) {
throw new RuntimeException(
sprintf('Cannot create a DBRef for class %s without an identifier. Have you forgotten to persist/merge the document first?', $class->name)
);
}
$storeAs = $referenceMapping['storeAs'] ?? null;
switch ($storeAs) {
case ClassMetadata::REFERENCE_STORE_AS_ID:
if ($class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION) {
throw MappingException::simpleReferenceMustNotTargetDiscriminatedDocument($referenceMapping['targetDocument']);
}
return $class->getDatabaseIdentifierValue($id);
break;
case ClassMetadata::REFERENCE_STORE_AS_REF:
$reference = ['id' => $class->getDatabaseIdentifierValue($id)];
break;
case ClassMetadata::REFERENCE_STORE_AS_DB_REF:
$reference = [
'$ref' => $class->getCollection(),
'$id' => $class->getDatabaseIdentifierValue($id),
];
break;
case ClassMetadata::REFERENCE_STORE_AS_DB_REF_WITH_DB:
$reference = [
'$ref' => $class->getCollection(),
'$id' => $class->getDatabaseIdentifierValue($id),
'$db' => $this->getDocumentDatabase($class->name)->getDatabaseName(),
];
break;
default:
throw new InvalidArgumentException(sprintf('Reference type %s is invalid.', $storeAs));
}
return $reference + $this->getDiscriminatorData($referenceMapping, $class);
} | [
"public",
"function",
"createReference",
"(",
"object",
"$",
"document",
",",
"array",
"$",
"referenceMapping",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"document",
")",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"unitOfWork",
"->",
"getDocumentIdentifier",
"(",
"$",
"document",
")",
";",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Cannot create a DBRef for class %s without an identifier. Have you forgotten to persist/merge the document first?'",
",",
"$",
"class",
"->",
"name",
")",
")",
";",
"}",
"$",
"storeAs",
"=",
"$",
"referenceMapping",
"[",
"'storeAs'",
"]",
"??",
"null",
";",
"switch",
"(",
"$",
"storeAs",
")",
"{",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_ID",
":",
"if",
"(",
"$",
"class",
"->",
"inheritanceType",
"===",
"ClassMetadata",
"::",
"INHERITANCE_TYPE_SINGLE_COLLECTION",
")",
"{",
"throw",
"MappingException",
"::",
"simpleReferenceMustNotTargetDiscriminatedDocument",
"(",
"$",
"referenceMapping",
"[",
"'targetDocument'",
"]",
")",
";",
"}",
"return",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_REF",
":",
"$",
"reference",
"=",
"[",
"'id'",
"=>",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
"]",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF",
":",
"$",
"reference",
"=",
"[",
"'$ref'",
"=>",
"$",
"class",
"->",
"getCollection",
"(",
")",
",",
"'$id'",
"=>",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
",",
"]",
";",
"break",
";",
"case",
"ClassMetadata",
"::",
"REFERENCE_STORE_AS_DB_REF_WITH_DB",
":",
"$",
"reference",
"=",
"[",
"'$ref'",
"=>",
"$",
"class",
"->",
"getCollection",
"(",
")",
",",
"'$id'",
"=>",
"$",
"class",
"->",
"getDatabaseIdentifierValue",
"(",
"$",
"id",
")",
",",
"'$db'",
"=>",
"$",
"this",
"->",
"getDocumentDatabase",
"(",
"$",
"class",
"->",
"name",
")",
"->",
"getDatabaseName",
"(",
")",
",",
"]",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Reference type %s is invalid.'",
",",
"$",
"storeAs",
")",
")",
";",
"}",
"return",
"$",
"reference",
"+",
"$",
"this",
"->",
"getDiscriminatorData",
"(",
"$",
"referenceMapping",
",",
"$",
"class",
")",
";",
"}"
] | Returns a reference to the supplied document.
@return mixed The reference for the document in question, according to the desired mapping
@throws MappingException
@throws RuntimeException | [
"Returns",
"a",
"reference",
"to",
"the",
"supplied",
"document",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L702-L747 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/DocumentManager.php | DocumentManager.getDiscriminatorData | private function getDiscriminatorData(array $referenceMapping, ClassMetadata $class) : array
{
$discriminatorField = null;
$discriminatorValue = null;
$discriminatorMap = null;
if (isset($referenceMapping['discriminatorField'])) {
$discriminatorField = $referenceMapping['discriminatorField'];
if (isset($referenceMapping['discriminatorMap'])) {
$discriminatorMap = $referenceMapping['discriminatorMap'];
}
} else {
$discriminatorField = $class->discriminatorField;
$discriminatorValue = $class->discriminatorValue;
$discriminatorMap = $class->discriminatorMap;
}
if ($discriminatorField === null) {
return [];
}
if ($discriminatorValue === null) {
if (! empty($discriminatorMap)) {
$pos = array_search($class->name, $discriminatorMap);
if ($pos !== false) {
$discriminatorValue = $pos;
}
} else {
$discriminatorValue = $class->name;
}
}
if ($discriminatorValue === null) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
return [$discriminatorField => $discriminatorValue];
} | php | private function getDiscriminatorData(array $referenceMapping, ClassMetadata $class) : array
{
$discriminatorField = null;
$discriminatorValue = null;
$discriminatorMap = null;
if (isset($referenceMapping['discriminatorField'])) {
$discriminatorField = $referenceMapping['discriminatorField'];
if (isset($referenceMapping['discriminatorMap'])) {
$discriminatorMap = $referenceMapping['discriminatorMap'];
}
} else {
$discriminatorField = $class->discriminatorField;
$discriminatorValue = $class->discriminatorValue;
$discriminatorMap = $class->discriminatorMap;
}
if ($discriminatorField === null) {
return [];
}
if ($discriminatorValue === null) {
if (! empty($discriminatorMap)) {
$pos = array_search($class->name, $discriminatorMap);
if ($pos !== false) {
$discriminatorValue = $pos;
}
} else {
$discriminatorValue = $class->name;
}
}
if ($discriminatorValue === null) {
throw MappingException::unlistedClassInDiscriminatorMap($class->name);
}
return [$discriminatorField => $discriminatorValue];
} | [
"private",
"function",
"getDiscriminatorData",
"(",
"array",
"$",
"referenceMapping",
",",
"ClassMetadata",
"$",
"class",
")",
":",
"array",
"{",
"$",
"discriminatorField",
"=",
"null",
";",
"$",
"discriminatorValue",
"=",
"null",
";",
"$",
"discriminatorMap",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"referenceMapping",
"[",
"'discriminatorField'",
"]",
")",
")",
"{",
"$",
"discriminatorField",
"=",
"$",
"referenceMapping",
"[",
"'discriminatorField'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"referenceMapping",
"[",
"'discriminatorMap'",
"]",
")",
")",
"{",
"$",
"discriminatorMap",
"=",
"$",
"referenceMapping",
"[",
"'discriminatorMap'",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"discriminatorField",
"=",
"$",
"class",
"->",
"discriminatorField",
";",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"discriminatorValue",
";",
"$",
"discriminatorMap",
"=",
"$",
"class",
"->",
"discriminatorMap",
";",
"}",
"if",
"(",
"$",
"discriminatorField",
"===",
"null",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"discriminatorValue",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"discriminatorMap",
")",
")",
"{",
"$",
"pos",
"=",
"array_search",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"discriminatorMap",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"discriminatorValue",
"=",
"$",
"pos",
";",
"}",
"}",
"else",
"{",
"$",
"discriminatorValue",
"=",
"$",
"class",
"->",
"name",
";",
"}",
"}",
"if",
"(",
"$",
"discriminatorValue",
"===",
"null",
")",
"{",
"throw",
"MappingException",
"::",
"unlistedClassInDiscriminatorMap",
"(",
"$",
"class",
"->",
"name",
")",
";",
"}",
"return",
"[",
"$",
"discriminatorField",
"=>",
"$",
"discriminatorValue",
"]",
";",
"}"
] | Build discriminator portion of reference for specified reference mapping and class metadata.
@param array $referenceMapping Mappings of reference for which discriminator data is created.
@param ClassMetadata $class Metadata of reference document class.
@return array with next structure [{discriminator field} => {discriminator value}]
@throws MappingException When discriminator map is present and reference class in not registered in it. | [
"Build",
"discriminator",
"portion",
"of",
"reference",
"for",
"specified",
"reference",
"mapping",
"and",
"class",
"metadata",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/DocumentManager.php#L759-L798 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AbstractBucket.php | AbstractBucket.getExpression | public function getExpression() : array
{
$stage = [
$this->getStageName() => [
'groupBy' => $this->convertExpression($this->groupBy),
] + $this->getExtraPipelineFields(),
];
if ($this->output !== null) {
$stage[$this->getStageName()]['output'] = $this->output->getExpression();
}
return $stage;
} | php | public function getExpression() : array
{
$stage = [
$this->getStageName() => [
'groupBy' => $this->convertExpression($this->groupBy),
] + $this->getExtraPipelineFields(),
];
if ($this->output !== null) {
$stage[$this->getStageName()]['output'] = $this->output->getExpression();
}
return $stage;
} | [
"public",
"function",
"getExpression",
"(",
")",
":",
"array",
"{",
"$",
"stage",
"=",
"[",
"$",
"this",
"->",
"getStageName",
"(",
")",
"=>",
"[",
"'groupBy'",
"=>",
"$",
"this",
"->",
"convertExpression",
"(",
"$",
"this",
"->",
"groupBy",
")",
",",
"]",
"+",
"$",
"this",
"->",
"getExtraPipelineFields",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"output",
"!==",
"null",
")",
"{",
"$",
"stage",
"[",
"$",
"this",
"->",
"getStageName",
"(",
")",
"]",
"[",
"'output'",
"]",
"=",
"$",
"this",
"->",
"output",
"->",
"getExpression",
"(",
")",
";",
"}",
"return",
"$",
"stage",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AbstractBucket.php#L62-L75 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Repository/DefaultRepositoryFactory.php | DefaultRepositoryFactory.instantiateRepository | protected function instantiateRepository(string $repositoryClassName, DocumentManager $documentManager, ClassMetadata $metadata) : ObjectRepository
{
return new $repositoryClassName($documentManager, $documentManager->getUnitOfWork(), $metadata);
} | php | protected function instantiateRepository(string $repositoryClassName, DocumentManager $documentManager, ClassMetadata $metadata) : ObjectRepository
{
return new $repositoryClassName($documentManager, $documentManager->getUnitOfWork(), $metadata);
} | [
"protected",
"function",
"instantiateRepository",
"(",
"string",
"$",
"repositoryClassName",
",",
"DocumentManager",
"$",
"documentManager",
",",
"ClassMetadata",
"$",
"metadata",
")",
":",
"ObjectRepository",
"{",
"return",
"new",
"$",
"repositoryClassName",
"(",
"$",
"documentManager",
",",
"$",
"documentManager",
"->",
"getUnitOfWork",
"(",
")",
",",
"$",
"metadata",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Repository/DefaultRepositoryFactory.php#L19-L22 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/PersistentCollection/AbstractPersistentCollectionFactory.php | AbstractPersistentCollectionFactory.create | public function create(DocumentManager $dm, array $mapping, ?BaseCollection $coll = null) : PersistentCollectionInterface
{
if ($coll === null) {
$coll = ! empty($mapping['collectionClass'])
? $this->createCollectionClass($mapping['collectionClass'])
: new ArrayCollection();
}
if (empty($mapping['collectionClass'])) {
return new PersistentCollection($coll, $dm, $dm->getUnitOfWork());
}
$className = $dm->getConfiguration()->getPersistentCollectionGenerator()
->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses());
return new $className($coll, $dm, $dm->getUnitOfWork());
} | php | public function create(DocumentManager $dm, array $mapping, ?BaseCollection $coll = null) : PersistentCollectionInterface
{
if ($coll === null) {
$coll = ! empty($mapping['collectionClass'])
? $this->createCollectionClass($mapping['collectionClass'])
: new ArrayCollection();
}
if (empty($mapping['collectionClass'])) {
return new PersistentCollection($coll, $dm, $dm->getUnitOfWork());
}
$className = $dm->getConfiguration()->getPersistentCollectionGenerator()
->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses());
return new $className($coll, $dm, $dm->getUnitOfWork());
} | [
"public",
"function",
"create",
"(",
"DocumentManager",
"$",
"dm",
",",
"array",
"$",
"mapping",
",",
"?",
"BaseCollection",
"$",
"coll",
"=",
"null",
")",
":",
"PersistentCollectionInterface",
"{",
"if",
"(",
"$",
"coll",
"===",
"null",
")",
"{",
"$",
"coll",
"=",
"!",
"empty",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
"?",
"$",
"this",
"->",
"createCollectionClass",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
":",
"new",
"ArrayCollection",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
")",
")",
"{",
"return",
"new",
"PersistentCollection",
"(",
"$",
"coll",
",",
"$",
"dm",
",",
"$",
"dm",
"->",
"getUnitOfWork",
"(",
")",
")",
";",
"}",
"$",
"className",
"=",
"$",
"dm",
"->",
"getConfiguration",
"(",
")",
"->",
"getPersistentCollectionGenerator",
"(",
")",
"->",
"loadClass",
"(",
"$",
"mapping",
"[",
"'collectionClass'",
"]",
",",
"$",
"dm",
"->",
"getConfiguration",
"(",
")",
"->",
"getAutoGeneratePersistentCollectionClasses",
"(",
")",
")",
";",
"return",
"new",
"$",
"className",
"(",
"$",
"coll",
",",
"$",
"dm",
",",
"$",
"dm",
"->",
"getUnitOfWork",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/AbstractPersistentCollectionFactory.php#L20-L36 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/MongoDBException.php | MongoDBException.invalidValueForType | public static function invalidValueForType(string $type, $expected, $got) : self
{
if (is_array($expected)) {
$expected = sprintf(
'%s or %s',
implode(', ', array_slice($expected, 0, -1)),
end($expected)
);
}
if (is_object($got)) {
$gotType = get_class($got);
} elseif (is_array($got)) {
$gotType = 'array';
} else {
$gotType = 'scalar';
}
return new self(sprintf('%s type requires value of type %s, %s given', $type, $expected, $gotType));
} | php | public static function invalidValueForType(string $type, $expected, $got) : self
{
if (is_array($expected)) {
$expected = sprintf(
'%s or %s',
implode(', ', array_slice($expected, 0, -1)),
end($expected)
);
}
if (is_object($got)) {
$gotType = get_class($got);
} elseif (is_array($got)) {
$gotType = 'array';
} else {
$gotType = 'scalar';
}
return new self(sprintf('%s type requires value of type %s, %s given', $type, $expected, $gotType));
} | [
"public",
"static",
"function",
"invalidValueForType",
"(",
"string",
"$",
"type",
",",
"$",
"expected",
",",
"$",
"got",
")",
":",
"self",
"{",
"if",
"(",
"is_array",
"(",
"$",
"expected",
")",
")",
"{",
"$",
"expected",
"=",
"sprintf",
"(",
"'%s or %s'",
",",
"implode",
"(",
"', '",
",",
"array_slice",
"(",
"$",
"expected",
",",
"0",
",",
"-",
"1",
")",
")",
",",
"end",
"(",
"$",
"expected",
")",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"got",
")",
")",
"{",
"$",
"gotType",
"=",
"get_class",
"(",
"$",
"got",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"got",
")",
")",
"{",
"$",
"gotType",
"=",
"'array'",
";",
"}",
"else",
"{",
"$",
"gotType",
"=",
"'scalar'",
";",
"}",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'%s type requires value of type %s, %s given'",
",",
"$",
"type",
",",
"$",
"expected",
",",
"$",
"gotType",
")",
")",
";",
"}"
] | @param string|array $expected
@param mixed $got
@return MongoDBException | [
"@param",
"string|array",
"$expected",
"@param",
"mixed",
"$got"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/MongoDBException.php#L69-L86 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.distinct | public function distinct(string $field) : self
{
$this->query['type'] = Query::TYPE_DISTINCT;
$this->query['distinct'] = $field;
return $this;
} | php | public function distinct(string $field) : self
{
$this->query['type'] = Query::TYPE_DISTINCT;
$this->query['distinct'] = $field;
return $this;
} | [
"public",
"function",
"distinct",
"(",
"string",
"$",
"field",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"=",
"Query",
"::",
"TYPE_DISTINCT",
";",
"$",
"this",
"->",
"query",
"[",
"'distinct'",
"]",
"=",
"$",
"field",
";",
"return",
"$",
"this",
";",
"}"
] | Change the query type to a distinct command.
@see http://docs.mongodb.org/manual/reference/command/distinct/ | [
"Change",
"the",
"query",
"type",
"to",
"a",
"distinct",
"command",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L398-L403 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.expr | public function expr() : Expr
{
$expr = new Expr($this->dm);
$expr->setClassMetadata($this->class);
return $expr;
} | php | public function expr() : Expr
{
$expr = new Expr($this->dm);
$expr->setClassMetadata($this->class);
return $expr;
} | [
"public",
"function",
"expr",
"(",
")",
":",
"Expr",
"{",
"$",
"expr",
"=",
"new",
"Expr",
"(",
"$",
"this",
"->",
"dm",
")",
";",
"$",
"expr",
"->",
"setClassMetadata",
"(",
"$",
"this",
"->",
"class",
")",
";",
"return",
"$",
"expr",
";",
"}"
] | Create a new Expr instance that can be used as an expression with the Builder | [
"Create",
"a",
"new",
"Expr",
"instance",
"that",
"can",
"be",
"used",
"as",
"an",
"expression",
"with",
"the",
"Builder"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L472-L478 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.field | public function field(string $field) : self
{
$this->currentField = $field;
$this->expr->field($field);
return $this;
} | php | public function field(string $field) : self
{
$this->currentField = $field;
$this->expr->field($field);
return $this;
} | [
"public",
"function",
"field",
"(",
"string",
"$",
"field",
")",
":",
"self",
"{",
"$",
"this",
"->",
"currentField",
"=",
"$",
"field",
";",
"$",
"this",
"->",
"expr",
"->",
"field",
"(",
"$",
"field",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the current field to operate on. | [
"Set",
"the",
"current",
"field",
"to",
"operate",
"on",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L483-L489 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.find | public function find(?string $documentName = null) : self
{
$this->setDocumentName($documentName);
$this->query['type'] = Query::TYPE_FIND;
return $this;
} | php | public function find(?string $documentName = null) : self
{
$this->setDocumentName($documentName);
$this->query['type'] = Query::TYPE_FIND;
return $this;
} | [
"public",
"function",
"find",
"(",
"?",
"string",
"$",
"documentName",
"=",
"null",
")",
":",
"self",
"{",
"$",
"this",
"->",
"setDocumentName",
"(",
"$",
"documentName",
")",
";",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"=",
"Query",
"::",
"TYPE_FIND",
";",
"return",
"$",
"this",
";",
"}"
] | Change the query type to find and optionally set and change the class being queried. | [
"Change",
"the",
"query",
"type",
"to",
"find",
"and",
"optionally",
"set",
"and",
"change",
"the",
"class",
"being",
"queried",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L494-L500 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.geoWithinCenter | public function geoWithinCenter(float $x, float $y, float $radius) : self
{
$this->expr->geoWithinCenter($x, $y, $radius);
return $this;
} | php | public function geoWithinCenter(float $x, float $y, float $radius) : self
{
$this->expr->geoWithinCenter($x, $y, $radius);
return $this;
} | [
"public",
"function",
"geoWithinCenter",
"(",
"float",
"$",
"x",
",",
"float",
"$",
"y",
",",
"float",
"$",
"radius",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"geoWithinCenter",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"radius",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add $geoWithin criteria with a $center shape to the query.
Note: the $center operator only supports legacy coordinate pairs and 2d
indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
@see Expr::geoWithinCenter()
@see http://docs.mongodb.org/manual/reference/operator/center/ | [
"Add",
"$geoWithin",
"criteria",
"with",
"a",
"$center",
"shape",
"to",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L579-L583 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.geoWithinCenterSphere | public function geoWithinCenterSphere(float $x, float $y, float $radius) : self
{
$this->expr->geoWithinCenterSphere($x, $y, $radius);
return $this;
} | php | public function geoWithinCenterSphere(float $x, float $y, float $radius) : self
{
$this->expr->geoWithinCenterSphere($x, $y, $radius);
return $this;
} | [
"public",
"function",
"geoWithinCenterSphere",
"(",
"float",
"$",
"x",
",",
"float",
"$",
"y",
",",
"float",
"$",
"radius",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"geoWithinCenterSphere",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"radius",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add $geoWithin criteria with a $centerSphere shape to the query.
Note: the $centerSphere operator supports both 2d and 2dsphere indexes.
@see Expr::geoWithinCenterSphere()
@see http://docs.mongodb.org/manual/reference/operator/centerSphere/ | [
"Add",
"$geoWithin",
"criteria",
"with",
"a",
"$centerSphere",
"shape",
"to",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L593-L597 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.getQuery | public function getQuery(array $options = []) : Query
{
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
$query = $this->query;
$query['query'] = $this->expr->getQuery();
$query['query'] = $documentPersister->addDiscriminatorToPreparedQuery($query['query']);
$query['query'] = $documentPersister->addFilterToPreparedQuery($query['query']);
$query['newObj'] = $this->expr->getNewObj();
if (isset($query['distinct'])) {
$query['distinct'] = $documentPersister->prepareFieldName($query['distinct']);
}
if ($this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION && ! empty($query['upsert']) &&
(empty($query['query'][$this->class->discriminatorField]) || is_array($query['query'][$this->class->discriminatorField]))) {
throw new InvalidArgumentException('Upsert query that is to be performed on discriminated document does not have single ' .
'discriminator. Either not use base class or set \'' . $this->class->discriminatorField . '\' field manually.');
}
if (! empty($query['select'])) {
$query['select'] = $documentPersister->prepareProjection($query['select']);
if ($this->hydrate && $this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION
&& ! isset($query['select'][$this->class->discriminatorField])) {
$includeMode = 0 < count(array_filter($query['select'], static function ($mode) {
return $mode === 1;
}));
if ($includeMode && ! isset($query['select'][$this->class->discriminatorField])) {
$query['select'][$this->class->discriminatorField] = 1;
}
}
}
if (isset($query['sort'])) {
$query['sort'] = $documentPersister->prepareSort($query['sort']);
}
if ($this->class->readPreference && ! array_key_exists('readPreference', $query)) {
$query['readPreference'] = new ReadPreference($this->class->readPreference, $this->class->readPreferenceTags);
}
return new Query(
$this->dm,
$this->class,
$this->collection,
$query,
$options,
$this->hydrate,
$this->refresh,
$this->primers,
$this->readOnly
);
} | php | public function getQuery(array $options = []) : Query
{
$documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name);
$query = $this->query;
$query['query'] = $this->expr->getQuery();
$query['query'] = $documentPersister->addDiscriminatorToPreparedQuery($query['query']);
$query['query'] = $documentPersister->addFilterToPreparedQuery($query['query']);
$query['newObj'] = $this->expr->getNewObj();
if (isset($query['distinct'])) {
$query['distinct'] = $documentPersister->prepareFieldName($query['distinct']);
}
if ($this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION && ! empty($query['upsert']) &&
(empty($query['query'][$this->class->discriminatorField]) || is_array($query['query'][$this->class->discriminatorField]))) {
throw new InvalidArgumentException('Upsert query that is to be performed on discriminated document does not have single ' .
'discriminator. Either not use base class or set \'' . $this->class->discriminatorField . '\' field manually.');
}
if (! empty($query['select'])) {
$query['select'] = $documentPersister->prepareProjection($query['select']);
if ($this->hydrate && $this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION
&& ! isset($query['select'][$this->class->discriminatorField])) {
$includeMode = 0 < count(array_filter($query['select'], static function ($mode) {
return $mode === 1;
}));
if ($includeMode && ! isset($query['select'][$this->class->discriminatorField])) {
$query['select'][$this->class->discriminatorField] = 1;
}
}
}
if (isset($query['sort'])) {
$query['sort'] = $documentPersister->prepareSort($query['sort']);
}
if ($this->class->readPreference && ! array_key_exists('readPreference', $query)) {
$query['readPreference'] = new ReadPreference($this->class->readPreference, $this->class->readPreferenceTags);
}
return new Query(
$this->dm,
$this->class,
$this->collection,
$query,
$options,
$this->hydrate,
$this->refresh,
$this->primers,
$this->readOnly
);
} | [
"public",
"function",
"getQuery",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"Query",
"{",
"$",
"documentPersister",
"=",
"$",
"this",
"->",
"dm",
"->",
"getUnitOfWork",
"(",
")",
"->",
"getDocumentPersister",
"(",
"$",
"this",
"->",
"class",
"->",
"name",
")",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
";",
"$",
"query",
"[",
"'query'",
"]",
"=",
"$",
"this",
"->",
"expr",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"[",
"'query'",
"]",
"=",
"$",
"documentPersister",
"->",
"addDiscriminatorToPreparedQuery",
"(",
"$",
"query",
"[",
"'query'",
"]",
")",
";",
"$",
"query",
"[",
"'query'",
"]",
"=",
"$",
"documentPersister",
"->",
"addFilterToPreparedQuery",
"(",
"$",
"query",
"[",
"'query'",
"]",
")",
";",
"$",
"query",
"[",
"'newObj'",
"]",
"=",
"$",
"this",
"->",
"expr",
"->",
"getNewObj",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"query",
"[",
"'distinct'",
"]",
")",
")",
"{",
"$",
"query",
"[",
"'distinct'",
"]",
"=",
"$",
"documentPersister",
"->",
"prepareFieldName",
"(",
"$",
"query",
"[",
"'distinct'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"inheritanceType",
"===",
"ClassMetadata",
"::",
"INHERITANCE_TYPE_SINGLE_COLLECTION",
"&&",
"!",
"empty",
"(",
"$",
"query",
"[",
"'upsert'",
"]",
")",
"&&",
"(",
"empty",
"(",
"$",
"query",
"[",
"'query'",
"]",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
")",
"||",
"is_array",
"(",
"$",
"query",
"[",
"'query'",
"]",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Upsert query that is to be performed on discriminated document does not have single '",
".",
"'discriminator. Either not use base class or set \\''",
".",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
".",
"'\\' field manually.'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
"[",
"'select'",
"]",
")",
")",
"{",
"$",
"query",
"[",
"'select'",
"]",
"=",
"$",
"documentPersister",
"->",
"prepareProjection",
"(",
"$",
"query",
"[",
"'select'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hydrate",
"&&",
"$",
"this",
"->",
"class",
"->",
"inheritanceType",
"===",
"ClassMetadata",
"::",
"INHERITANCE_TYPE_SINGLE_COLLECTION",
"&&",
"!",
"isset",
"(",
"$",
"query",
"[",
"'select'",
"]",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
")",
")",
"{",
"$",
"includeMode",
"=",
"0",
"<",
"count",
"(",
"array_filter",
"(",
"$",
"query",
"[",
"'select'",
"]",
",",
"static",
"function",
"(",
"$",
"mode",
")",
"{",
"return",
"$",
"mode",
"===",
"1",
";",
"}",
")",
")",
";",
"if",
"(",
"$",
"includeMode",
"&&",
"!",
"isset",
"(",
"$",
"query",
"[",
"'select'",
"]",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
")",
")",
"{",
"$",
"query",
"[",
"'select'",
"]",
"[",
"$",
"this",
"->",
"class",
"->",
"discriminatorField",
"]",
"=",
"1",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"query",
"[",
"'sort'",
"]",
")",
")",
"{",
"$",
"query",
"[",
"'sort'",
"]",
"=",
"$",
"documentPersister",
"->",
"prepareSort",
"(",
"$",
"query",
"[",
"'sort'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"class",
"->",
"readPreference",
"&&",
"!",
"array_key_exists",
"(",
"'readPreference'",
",",
"$",
"query",
")",
")",
"{",
"$",
"query",
"[",
"'readPreference'",
"]",
"=",
"new",
"ReadPreference",
"(",
"$",
"this",
"->",
"class",
"->",
"readPreference",
",",
"$",
"this",
"->",
"class",
"->",
"readPreferenceTags",
")",
";",
"}",
"return",
"new",
"Query",
"(",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"class",
",",
"$",
"this",
"->",
"collection",
",",
"$",
"query",
",",
"$",
"options",
",",
"$",
"this",
"->",
"hydrate",
",",
"$",
"this",
"->",
"refresh",
",",
"$",
"this",
"->",
"primers",
",",
"$",
"this",
"->",
"readOnly",
")",
";",
"}"
] | Gets the Query executable. | [
"Gets",
"the",
"Query",
"executable",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L637-L691 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.mod | public function mod($divisor, $remainder = 0) : self
{
$this->expr->mod($divisor, $remainder);
return $this;
} | php | public function mod($divisor, $remainder = 0) : self
{
$this->expr->mod($divisor, $remainder);
return $this;
} | [
"public",
"function",
"mod",
"(",
"$",
"divisor",
",",
"$",
"remainder",
"=",
"0",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"mod",
"(",
"$",
"divisor",
",",
"$",
"remainder",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Specify $mod criteria for the current field.
@see Expr::mod()
@see http://docs.mongodb.org/manual/reference/operator/mod/
@param float|int $divisor
@param float|int $remainder | [
"Specify",
"$mod",
"criteria",
"for",
"the",
"current",
"field",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L908-L912 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.prime | public function prime($primer = true) : self
{
if (! is_bool($primer) && ! is_callable($primer)) {
throw new InvalidArgumentException('$primer is not a boolean or callable');
}
if ($primer === false) {
unset($this->primers[$this->currentField]);
return $this;
}
$this->primers[$this->currentField] = $primer;
return $this;
} | php | public function prime($primer = true) : self
{
if (! is_bool($primer) && ! is_callable($primer)) {
throw new InvalidArgumentException('$primer is not a boolean or callable');
}
if ($primer === false) {
unset($this->primers[$this->currentField]);
return $this;
}
$this->primers[$this->currentField] = $primer;
return $this;
} | [
"public",
"function",
"prime",
"(",
"$",
"primer",
"=",
"true",
")",
":",
"self",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"primer",
")",
"&&",
"!",
"is_callable",
"(",
"$",
"primer",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'$primer is not a boolean or callable'",
")",
";",
"}",
"if",
"(",
"$",
"primer",
"===",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"primers",
"[",
"$",
"this",
"->",
"currentField",
"]",
")",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"primers",
"[",
"$",
"this",
"->",
"currentField",
"]",
"=",
"$",
"primer",
";",
"return",
"$",
"this",
";",
"}"
] | Use a primer to eagerly load all references in the current field.
If $primer is true or a callable is provided, referenced documents for
this field will loaded into UnitOfWork immediately after the query is
executed. This will avoid multiple queries due to lazy initialization of
Proxy objects.
If $primer is false, no priming will take place. That is also the default
behavior.
If a custom callable is used, its signature should conform to the default
Closure defined in {@link ReferencePrimer::__construct()}.
@param bool|callable $primer
@throws InvalidArgumentException If $primer is not boolean or callable. | [
"Use",
"a",
"primer",
"to",
"eagerly",
"load",
"all",
"references",
"in",
"the",
"current",
"field",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1054-L1068 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.selectElemMatch | public function selectElemMatch(string $fieldName, $expression) : self
{
if ($expression instanceof Expr) {
$expression = $expression->getQuery();
}
$this->query['select'][$fieldName] = ['$elemMatch' => $expression];
return $this;
} | php | public function selectElemMatch(string $fieldName, $expression) : self
{
if ($expression instanceof Expr) {
$expression = $expression->getQuery();
}
$this->query['select'][$fieldName] = ['$elemMatch' => $expression];
return $this;
} | [
"public",
"function",
"selectElemMatch",
"(",
"string",
"$",
"fieldName",
",",
"$",
"expression",
")",
":",
"self",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"Expr",
")",
"{",
"$",
"expression",
"=",
"$",
"expression",
"->",
"getQuery",
"(",
")",
";",
"}",
"$",
"this",
"->",
"query",
"[",
"'select'",
"]",
"[",
"$",
"fieldName",
"]",
"=",
"[",
"'$elemMatch'",
"=>",
"$",
"expression",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Select only matching embedded documents in an array field for the query
projection.
@see http://docs.mongodb.org/manual/reference/projection/elemMatch/
@param array|Expr $expression | [
"Select",
"only",
"matching",
"embedded",
"documents",
"in",
"an",
"array",
"field",
"for",
"the",
"query",
"projection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1214-L1221 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.selectMeta | public function selectMeta(string $fieldName, string $metaDataKeyword) : self
{
$this->query['select'][$fieldName] = ['$meta' => $metaDataKeyword];
return $this;
} | php | public function selectMeta(string $fieldName, string $metaDataKeyword) : self
{
$this->query['select'][$fieldName] = ['$meta' => $metaDataKeyword];
return $this;
} | [
"public",
"function",
"selectMeta",
"(",
"string",
"$",
"fieldName",
",",
"string",
"$",
"metaDataKeyword",
")",
":",
"self",
"{",
"$",
"this",
"->",
"query",
"[",
"'select'",
"]",
"[",
"$",
"fieldName",
"]",
"=",
"[",
"'$meta'",
"=>",
"$",
"metaDataKeyword",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Select a metadata field for the query projection.
@see http://docs.mongodb.org/master/reference/operator/projection/meta/ | [
"Select",
"a",
"metadata",
"field",
"for",
"the",
"query",
"projection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1228-L1232 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.selectSlice | public function selectSlice(string $fieldName, int $countOrSkip, ?int $limit = null) : self
{
$slice = $countOrSkip;
if ($limit !== null) {
$slice = [$slice, $limit];
}
$this->query['select'][$fieldName] = ['$slice' => $slice];
return $this;
} | php | public function selectSlice(string $fieldName, int $countOrSkip, ?int $limit = null) : self
{
$slice = $countOrSkip;
if ($limit !== null) {
$slice = [$slice, $limit];
}
$this->query['select'][$fieldName] = ['$slice' => $slice];
return $this;
} | [
"public",
"function",
"selectSlice",
"(",
"string",
"$",
"fieldName",
",",
"int",
"$",
"countOrSkip",
",",
"?",
"int",
"$",
"limit",
"=",
"null",
")",
":",
"self",
"{",
"$",
"slice",
"=",
"$",
"countOrSkip",
";",
"if",
"(",
"$",
"limit",
"!==",
"null",
")",
"{",
"$",
"slice",
"=",
"[",
"$",
"slice",
",",
"$",
"limit",
"]",
";",
"}",
"$",
"this",
"->",
"query",
"[",
"'select'",
"]",
"[",
"$",
"fieldName",
"]",
"=",
"[",
"'$slice'",
"=>",
"$",
"slice",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Select a slice of an array field for the query projection.
The $countOrSkip parameter has two very different meanings, depending on
whether or not $limit is provided. See the MongoDB documentation for more
information.
@see http://docs.mongodb.org/manual/reference/projection/slice/ | [
"Select",
"a",
"slice",
"of",
"an",
"array",
"field",
"for",
"the",
"query",
"projection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1243-L1251 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.set | public function set($value, bool $atomic = true) : self
{
$this->expr->set($value, $atomic && $this->query['type'] !== Query::TYPE_INSERT);
return $this;
} | php | public function set($value, bool $atomic = true) : self
{
$this->expr->set($value, $atomic && $this->query['type'] !== Query::TYPE_INSERT);
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"value",
",",
"bool",
"$",
"atomic",
"=",
"true",
")",
":",
"self",
"{",
"$",
"this",
"->",
"expr",
"->",
"set",
"(",
"$",
"value",
",",
"$",
"atomic",
"&&",
"$",
"this",
"->",
"query",
"[",
"'type'",
"]",
"!==",
"Query",
"::",
"TYPE_INSERT",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the current field to a value.
This is only relevant for insert, update, or findAndUpdate queries. For
update and findAndUpdate queries, the $atomic parameter will determine
whether or not a $set operator is used.
@see Expr::set()
@see http://docs.mongodb.org/manual/reference/operator/set/
@param mixed $value | [
"Set",
"the",
"current",
"field",
"to",
"a",
"value",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1265-L1269 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.sort | public function sort($fieldName, $order = 1) : self
{
if (! isset($this->query['sort'])) {
$this->query['sort'] = [];
}
$fields = is_array($fieldName) ? $fieldName : [$fieldName => $order];
foreach ($fields as $fieldName => $order) {
if (is_string($order)) {
$order = strtolower($order) === 'asc' ? 1 : -1;
}
$this->query['sort'][$fieldName] = (int) $order;
}
return $this;
} | php | public function sort($fieldName, $order = 1) : self
{
if (! isset($this->query['sort'])) {
$this->query['sort'] = [];
}
$fields = is_array($fieldName) ? $fieldName : [$fieldName => $order];
foreach ($fields as $fieldName => $order) {
if (is_string($order)) {
$order = strtolower($order) === 'asc' ? 1 : -1;
}
$this->query['sort'][$fieldName] = (int) $order;
}
return $this;
} | [
"public",
"function",
"sort",
"(",
"$",
"fieldName",
",",
"$",
"order",
"=",
"1",
")",
":",
"self",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"query",
"[",
"'sort'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"query",
"[",
"'sort'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"fields",
"=",
"is_array",
"(",
"$",
"fieldName",
")",
"?",
"$",
"fieldName",
":",
"[",
"$",
"fieldName",
"=>",
"$",
"order",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldName",
"=>",
"$",
"order",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"order",
")",
")",
"{",
"$",
"order",
"=",
"strtolower",
"(",
"$",
"order",
")",
"===",
"'asc'",
"?",
"1",
":",
"-",
"1",
";",
"}",
"$",
"this",
"->",
"query",
"[",
"'sort'",
"]",
"[",
"$",
"fieldName",
"]",
"=",
"(",
"int",
")",
"$",
"order",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set one or more field/order pairs on which to sort the query.
If sorting by multiple fields, the first argument should be an array of
field name (key) and order (value) pairs.
@param array|string $fieldName Field name or array of field/order pairs
@param int|string $order Field order (if one field is specified) | [
"Set",
"one",
"or",
"more",
"field",
"/",
"order",
"pairs",
"on",
"which",
"to",
"sort",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1370-L1386 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.sortMeta | public function sortMeta(string $fieldName, string $metaDataKeyword) : self
{
/* It's possible that the field is already projected without the $meta
* operator. We'll assume that the user knows what they're doing in that
* case and will not attempt to override the projection.
*/
if (! isset($this->query['select'][$fieldName])) {
$this->selectMeta($fieldName, $metaDataKeyword);
}
$this->query['sort'][$fieldName] = ['$meta' => $metaDataKeyword];
return $this;
} | php | public function sortMeta(string $fieldName, string $metaDataKeyword) : self
{
if (! isset($this->query['select'][$fieldName])) {
$this->selectMeta($fieldName, $metaDataKeyword);
}
$this->query['sort'][$fieldName] = ['$meta' => $metaDataKeyword];
return $this;
} | [
"public",
"function",
"sortMeta",
"(",
"string",
"$",
"fieldName",
",",
"string",
"$",
"metaDataKeyword",
")",
":",
"self",
"{",
"/* It's possible that the field is already projected without the $meta\n * operator. We'll assume that the user knows what they're doing in that\n * case and will not attempt to override the projection.\n */",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"query",
"[",
"'select'",
"]",
"[",
"$",
"fieldName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"selectMeta",
"(",
"$",
"fieldName",
",",
"$",
"metaDataKeyword",
")",
";",
"}",
"$",
"this",
"->",
"query",
"[",
"'sort'",
"]",
"[",
"$",
"fieldName",
"]",
"=",
"[",
"'$meta'",
"=>",
"$",
"metaDataKeyword",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Specify a projected metadata field on which to sort the query.
Sort order is not configurable for metadata fields. Sorting by a metadata
field requires the same field and $meta expression to exist in the
projection document. This method will call {@link Builder::selectMeta()}
if the field is not already set in the projection.
@see http://docs.mongodb.org/master/reference/operator/projection/meta/#sort | [
"Specify",
"a",
"projected",
"metadata",
"field",
"on",
"which",
"to",
"sort",
"the",
"query",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1398-L1411 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Query/Builder.php | Builder.getDiscriminatorValues | private function getDiscriminatorValues($classNames) : array
{
$discriminatorValues = [];
$collections = [];
foreach ($classNames as $className) {
$class = $this->dm->getClassMetadata($className);
$discriminatorValues[] = $class->discriminatorValue;
$key = $this->dm->getDocumentDatabase($className)->getDatabaseName() . '.' . $class->getCollection();
$collections[$key] = $key;
}
if (count($collections) > 1) {
throw new InvalidArgumentException('Documents involved are not all mapped to the same database collection.');
}
return $discriminatorValues;
} | php | private function getDiscriminatorValues($classNames) : array
{
$discriminatorValues = [];
$collections = [];
foreach ($classNames as $className) {
$class = $this->dm->getClassMetadata($className);
$discriminatorValues[] = $class->discriminatorValue;
$key = $this->dm->getDocumentDatabase($className)->getDatabaseName() . '.' . $class->getCollection();
$collections[$key] = $key;
}
if (count($collections) > 1) {
throw new InvalidArgumentException('Documents involved are not all mapped to the same database collection.');
}
return $discriminatorValues;
} | [
"private",
"function",
"getDiscriminatorValues",
"(",
"$",
"classNames",
")",
":",
"array",
"{",
"$",
"discriminatorValues",
"=",
"[",
"]",
";",
"$",
"collections",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classNames",
"as",
"$",
"className",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"className",
")",
";",
"$",
"discriminatorValues",
"[",
"]",
"=",
"$",
"class",
"->",
"discriminatorValue",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"dm",
"->",
"getDocumentDatabase",
"(",
"$",
"className",
")",
"->",
"getDatabaseName",
"(",
")",
".",
"'.'",
".",
"$",
"class",
"->",
"getCollection",
"(",
")",
";",
"$",
"collections",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"collections",
")",
">",
"1",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Documents involved are not all mapped to the same database collection.'",
")",
";",
"}",
"return",
"$",
"discriminatorValues",
";",
"}"
] | Get Discriminator Values
@param string[] $classNames
@throws InvalidArgumentException If the number of found collections > 1. | [
"Get",
"Discriminator",
"Values"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Builder.php#L1503-L1517 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Id/UuidGenerator.php | UuidGenerator.generate | public function generate(DocumentManager $dm, object $document)
{
$uuid = $this->generateV4();
return $this->generateV5($uuid, $this->salt ?: php_uname('n'));
} | php | public function generate(DocumentManager $dm, object $document)
{
$uuid = $this->generateV4();
return $this->generateV5($uuid, $this->salt ?: php_uname('n'));
} | [
"public",
"function",
"generate",
"(",
"DocumentManager",
"$",
"dm",
",",
"object",
"$",
"document",
")",
"{",
"$",
"uuid",
"=",
"$",
"this",
"->",
"generateV4",
"(",
")",
";",
"return",
"$",
"this",
"->",
"generateV5",
"(",
"$",
"uuid",
",",
"$",
"this",
"->",
"salt",
"?",
":",
"php_uname",
"(",
"'n'",
")",
")",
";",
"}"
] | Generates a new UUID
@param DocumentManager $dm Not used.
@param object $document Not used.
@return string UUID
@throws Exception | [
"Generates",
"a",
"new",
"UUID"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Id/UuidGenerator.php#L69-L73 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Id/UuidGenerator.php | UuidGenerator.generateV4 | public function generateV4() : string
{
return sprintf(
'%04x%04x%04x%04x%04x%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
);
} | php | public function generateV4() : string
{
return sprintf(
'%04x%04x%04x%04x%04x%04x%04x%04x',
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
);
} | [
"public",
"function",
"generateV4",
"(",
")",
":",
"string",
"{",
"return",
"sprintf",
"(",
"'%04x%04x%04x%04x%04x%04x%04x%04x'",
",",
"// 32 bits for \"time_low\"",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"// 16 bits for \"time_mid\"",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"// 16 bits for \"time_hi_and_version\",",
"// four most significant bits holds version number 4",
"mt_rand",
"(",
"0",
",",
"0x0fff",
")",
"|",
"0x4000",
",",
"// 16 bits, 8 bits for \"clk_seq_hi_res\",",
"// 8 bits for \"clk_seq_low\",",
"// two most significant bits holds zero and one for variant DCE1.1",
"mt_rand",
"(",
"0",
",",
"0x3fff",
")",
"|",
"0x8000",
",",
"// 48 bits for \"node\"",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
",",
"mt_rand",
"(",
"0",
",",
"0xffff",
")",
")",
";",
"}"
] | Generates a v4 UUID | [
"Generates",
"a",
"v4",
"UUID"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Id/UuidGenerator.php#L78-L99 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php | AnnotationDriver.loadMetadataForClass | public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $class) : void
{
assert($class instanceof ClassMetadata);
$reflClass = $class->getReflectionClass();
$classAnnotations = $this->reader->getClassAnnotations($reflClass);
$documentAnnot = null;
foreach ($classAnnotations as $annot) {
$classAnnotations[get_class($annot)] = $annot;
if ($annot instanceof ODM\AbstractDocument) {
if ($documentAnnot !== null) {
throw MappingException::classCanOnlyBeMappedByOneAbstractDocument($className, $documentAnnot, $annot);
}
$documentAnnot = $annot;
}
// non-document class annotations
if ($annot instanceof ODM\AbstractIndex) {
$this->addIndex($class, $annot);
}
if ($annot instanceof ODM\Indexes) {
// Setting the type to mixed is a workaround until https://github.com/doctrine/annotations/pull/209 is released.
/** @var mixed $value */
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
$this->addIndex($class, $index);
}
} elseif ($annot instanceof ODM\InheritanceType) {
$class->setInheritanceType(constant(ClassMetadata::class . '::INHERITANCE_TYPE_' . $annot->value));
} elseif ($annot instanceof ODM\DiscriminatorField) {
$class->setDiscriminatorField($annot->value);
} elseif ($annot instanceof ODM\DiscriminatorMap) {
/** @var array $value */
$value = $annot->value;
$class->setDiscriminatorMap($value);
} elseif ($annot instanceof ODM\DiscriminatorValue) {
$class->setDiscriminatorValue($annot->value);
} elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
$class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . $annot->value));
} elseif ($annot instanceof ODM\DefaultDiscriminatorValue) {
$class->setDefaultDiscriminatorValue($annot->value);
} elseif ($annot instanceof ODM\ReadPreference) {
$class->setReadPreference($annot->value, $annot->tags ?? []);
}
}
if ($documentAnnot === null) {
throw MappingException::classIsNotAValidDocument($className);
}
if ($documentAnnot instanceof ODM\MappedSuperclass) {
$class->isMappedSuperclass = true;
} elseif ($documentAnnot instanceof ODM\EmbeddedDocument) {
$class->isEmbeddedDocument = true;
} elseif ($documentAnnot instanceof ODM\QueryResultDocument) {
$class->isQueryResultDocument = true;
} elseif ($documentAnnot instanceof ODM\File) {
$class->isFile = true;
if ($documentAnnot->chunkSizeBytes !== null) {
$class->setChunkSizeBytes($documentAnnot->chunkSizeBytes);
}
}
if (isset($documentAnnot->db)) {
$class->setDatabase($documentAnnot->db);
}
if (isset($documentAnnot->collection)) {
$class->setCollection($documentAnnot->collection);
}
// Store bucketName as collection name for GridFS files
if (isset($documentAnnot->bucketName)) {
$class->setBucketName($documentAnnot->bucketName);
}
if (isset($documentAnnot->repositoryClass)) {
$class->setCustomRepositoryClass($documentAnnot->repositoryClass);
}
if (isset($documentAnnot->writeConcern)) {
$class->setWriteConcern($documentAnnot->writeConcern);
}
if (isset($documentAnnot->indexes)) {
foreach ($documentAnnot->indexes as $index) {
$this->addIndex($class, $index);
}
}
if (! empty($documentAnnot->readOnly)) {
$class->markReadOnly();
}
foreach ($reflClass->getProperties() as $property) {
if (($class->isMappedSuperclass && ! $property->isPrivate())
||
($class->isInheritedField($property->name) && $property->getDeclaringClass()->name !== $class->name)) {
continue;
}
$indexes = [];
$mapping = ['fieldName' => $property->getName()];
$fieldAnnot = null;
foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
if ($annot instanceof ODM\AbstractField) {
$fieldAnnot = $annot;
if ($annot->isDeprecated()) {
@trigger_error($annot->getDeprecationMessage(), E_USER_DEPRECATED);
}
}
if ($annot instanceof ODM\AbstractIndex) {
$indexes[] = $annot;
}
if ($annot instanceof ODM\Indexes) {
// Setting the type to mixed is a workaround until https://github.com/doctrine/annotations/pull/209 is released.
/** @var mixed $value */
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
$indexes[] = $index;
}
} elseif ($annot instanceof ODM\AlsoLoad) {
$mapping['alsoLoadFields'] = (array) $annot->value;
} elseif ($annot instanceof ODM\Version) {
$mapping['version'] = true;
} elseif ($annot instanceof ODM\Lock) {
$mapping['lock'] = true;
}
}
if ($fieldAnnot) {
$mapping = array_replace($mapping, (array) $fieldAnnot);
$class->mapField($mapping);
}
if (! $indexes) {
continue;
}
foreach ($indexes as $index) {
$name = $mapping['name'] ?? $mapping['fieldName'];
$keys = [$name => $index->order ?: 'asc'];
$this->addIndex($class, $index, $keys);
}
}
// Set shard key after all fields to ensure we mapped all its keys
if (isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\Annotations\ShardKey'])) {
$this->setShardKey($class, $classAnnotations['Doctrine\ODM\MongoDB\Mapping\Annotations\ShardKey']);
}
/** @var ReflectionMethod $method */
foreach ($reflClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
/* Filter for the declaring class only. Callbacks from parent
* classes will already be registered.
*/
if ($method->getDeclaringClass()->name !== $reflClass->name) {
continue;
}
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
if ($annot instanceof ODM\AlsoLoad) {
$class->registerAlsoLoadMethod($method->getName(), $annot->value);
}
if (! isset($classAnnotations[ODM\HasLifecycleCallbacks::class])) {
continue;
}
if ($annot instanceof ODM\PrePersist) {
$class->addLifecycleCallback($method->getName(), Events::prePersist);
} elseif ($annot instanceof ODM\PostPersist) {
$class->addLifecycleCallback($method->getName(), Events::postPersist);
} elseif ($annot instanceof ODM\PreUpdate) {
$class->addLifecycleCallback($method->getName(), Events::preUpdate);
} elseif ($annot instanceof ODM\PostUpdate) {
$class->addLifecycleCallback($method->getName(), Events::postUpdate);
} elseif ($annot instanceof ODM\PreRemove) {
$class->addLifecycleCallback($method->getName(), Events::preRemove);
} elseif ($annot instanceof ODM\PostRemove) {
$class->addLifecycleCallback($method->getName(), Events::postRemove);
} elseif ($annot instanceof ODM\PreLoad) {
$class->addLifecycleCallback($method->getName(), Events::preLoad);
} elseif ($annot instanceof ODM\PostLoad) {
$class->addLifecycleCallback($method->getName(), Events::postLoad);
} elseif ($annot instanceof ODM\PreFlush) {
$class->addLifecycleCallback($method->getName(), Events::preFlush);
}
}
}
} | php | public function loadMetadataForClass($className, \Doctrine\Common\Persistence\Mapping\ClassMetadata $class) : void
{
assert($class instanceof ClassMetadata);
$reflClass = $class->getReflectionClass();
$classAnnotations = $this->reader->getClassAnnotations($reflClass);
$documentAnnot = null;
foreach ($classAnnotations as $annot) {
$classAnnotations[get_class($annot)] = $annot;
if ($annot instanceof ODM\AbstractDocument) {
if ($documentAnnot !== null) {
throw MappingException::classCanOnlyBeMappedByOneAbstractDocument($className, $documentAnnot, $annot);
}
$documentAnnot = $annot;
}
if ($annot instanceof ODM\AbstractIndex) {
$this->addIndex($class, $annot);
}
if ($annot instanceof ODM\Indexes) {
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
$this->addIndex($class, $index);
}
} elseif ($annot instanceof ODM\InheritanceType) {
$class->setInheritanceType(constant(ClassMetadata::class . '::INHERITANCE_TYPE_' . $annot->value));
} elseif ($annot instanceof ODM\DiscriminatorField) {
$class->setDiscriminatorField($annot->value);
} elseif ($annot instanceof ODM\DiscriminatorMap) {
$value = $annot->value;
$class->setDiscriminatorMap($value);
} elseif ($annot instanceof ODM\DiscriminatorValue) {
$class->setDiscriminatorValue($annot->value);
} elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
$class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . $annot->value));
} elseif ($annot instanceof ODM\DefaultDiscriminatorValue) {
$class->setDefaultDiscriminatorValue($annot->value);
} elseif ($annot instanceof ODM\ReadPreference) {
$class->setReadPreference($annot->value, $annot->tags ?? []);
}
}
if ($documentAnnot === null) {
throw MappingException::classIsNotAValidDocument($className);
}
if ($documentAnnot instanceof ODM\MappedSuperclass) {
$class->isMappedSuperclass = true;
} elseif ($documentAnnot instanceof ODM\EmbeddedDocument) {
$class->isEmbeddedDocument = true;
} elseif ($documentAnnot instanceof ODM\QueryResultDocument) {
$class->isQueryResultDocument = true;
} elseif ($documentAnnot instanceof ODM\File) {
$class->isFile = true;
if ($documentAnnot->chunkSizeBytes !== null) {
$class->setChunkSizeBytes($documentAnnot->chunkSizeBytes);
}
}
if (isset($documentAnnot->db)) {
$class->setDatabase($documentAnnot->db);
}
if (isset($documentAnnot->collection)) {
$class->setCollection($documentAnnot->collection);
}
if (isset($documentAnnot->bucketName)) {
$class->setBucketName($documentAnnot->bucketName);
}
if (isset($documentAnnot->repositoryClass)) {
$class->setCustomRepositoryClass($documentAnnot->repositoryClass);
}
if (isset($documentAnnot->writeConcern)) {
$class->setWriteConcern($documentAnnot->writeConcern);
}
if (isset($documentAnnot->indexes)) {
foreach ($documentAnnot->indexes as $index) {
$this->addIndex($class, $index);
}
}
if (! empty($documentAnnot->readOnly)) {
$class->markReadOnly();
}
foreach ($reflClass->getProperties() as $property) {
if (($class->isMappedSuperclass && ! $property->isPrivate())
||
($class->isInheritedField($property->name) && $property->getDeclaringClass()->name !== $class->name)) {
continue;
}
$indexes = [];
$mapping = ['fieldName' => $property->getName()];
$fieldAnnot = null;
foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
if ($annot instanceof ODM\AbstractField) {
$fieldAnnot = $annot;
if ($annot->isDeprecated()) {
@trigger_error($annot->getDeprecationMessage(), E_USER_DEPRECATED);
}
}
if ($annot instanceof ODM\AbstractIndex) {
$indexes[] = $annot;
}
if ($annot instanceof ODM\Indexes) {
$value = $annot->value;
foreach (is_array($value) ? $value : [$value] as $index) {
$indexes[] = $index;
}
} elseif ($annot instanceof ODM\AlsoLoad) {
$mapping['alsoLoadFields'] = (array) $annot->value;
} elseif ($annot instanceof ODM\Version) {
$mapping['version'] = true;
} elseif ($annot instanceof ODM\Lock) {
$mapping['lock'] = true;
}
}
if ($fieldAnnot) {
$mapping = array_replace($mapping, (array) $fieldAnnot);
$class->mapField($mapping);
}
if (! $indexes) {
continue;
}
foreach ($indexes as $index) {
$name = $mapping['name'] ?? $mapping['fieldName'];
$keys = [$name => $index->order ?: 'asc'];
$this->addIndex($class, $index, $keys);
}
}
if (isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\Annotations\ShardKey'])) {
$this->setShardKey($class, $classAnnotations['Doctrine\ODM\MongoDB\Mapping\Annotations\ShardKey']);
}
foreach ($reflClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if ($method->getDeclaringClass()->name !== $reflClass->name) {
continue;
}
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
if ($annot instanceof ODM\AlsoLoad) {
$class->registerAlsoLoadMethod($method->getName(), $annot->value);
}
if (! isset($classAnnotations[ODM\HasLifecycleCallbacks::class])) {
continue;
}
if ($annot instanceof ODM\PrePersist) {
$class->addLifecycleCallback($method->getName(), Events::prePersist);
} elseif ($annot instanceof ODM\PostPersist) {
$class->addLifecycleCallback($method->getName(), Events::postPersist);
} elseif ($annot instanceof ODM\PreUpdate) {
$class->addLifecycleCallback($method->getName(), Events::preUpdate);
} elseif ($annot instanceof ODM\PostUpdate) {
$class->addLifecycleCallback($method->getName(), Events::postUpdate);
} elseif ($annot instanceof ODM\PreRemove) {
$class->addLifecycleCallback($method->getName(), Events::preRemove);
} elseif ($annot instanceof ODM\PostRemove) {
$class->addLifecycleCallback($method->getName(), Events::postRemove);
} elseif ($annot instanceof ODM\PreLoad) {
$class->addLifecycleCallback($method->getName(), Events::preLoad);
} elseif ($annot instanceof ODM\PostLoad) {
$class->addLifecycleCallback($method->getName(), Events::postLoad);
} elseif ($annot instanceof ODM\PreFlush) {
$class->addLifecycleCallback($method->getName(), Events::preFlush);
}
}
}
} | [
"public",
"function",
"loadMetadataForClass",
"(",
"$",
"className",
",",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Persistence",
"\\",
"Mapping",
"\\",
"ClassMetadata",
"$",
"class",
")",
":",
"void",
"{",
"assert",
"(",
"$",
"class",
"instanceof",
"ClassMetadata",
")",
";",
"$",
"reflClass",
"=",
"$",
"class",
"->",
"getReflectionClass",
"(",
")",
";",
"$",
"classAnnotations",
"=",
"$",
"this",
"->",
"reader",
"->",
"getClassAnnotations",
"(",
"$",
"reflClass",
")",
";",
"$",
"documentAnnot",
"=",
"null",
";",
"foreach",
"(",
"$",
"classAnnotations",
"as",
"$",
"annot",
")",
"{",
"$",
"classAnnotations",
"[",
"get_class",
"(",
"$",
"annot",
")",
"]",
"=",
"$",
"annot",
";",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"AbstractDocument",
")",
"{",
"if",
"(",
"$",
"documentAnnot",
"!==",
"null",
")",
"{",
"throw",
"MappingException",
"::",
"classCanOnlyBeMappedByOneAbstractDocument",
"(",
"$",
"className",
",",
"$",
"documentAnnot",
",",
"$",
"annot",
")",
";",
"}",
"$",
"documentAnnot",
"=",
"$",
"annot",
";",
"}",
"// non-document class annotations",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"AbstractIndex",
")",
"{",
"$",
"this",
"->",
"addIndex",
"(",
"$",
"class",
",",
"$",
"annot",
")",
";",
"}",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"Indexes",
")",
"{",
"// Setting the type to mixed is a workaround until https://github.com/doctrine/annotations/pull/209 is released.",
"/** @var mixed $value */",
"$",
"value",
"=",
"$",
"annot",
"->",
"value",
";",
"foreach",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"[",
"$",
"value",
"]",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"addIndex",
"(",
"$",
"class",
",",
"$",
"index",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"InheritanceType",
")",
"{",
"$",
"class",
"->",
"setInheritanceType",
"(",
"constant",
"(",
"ClassMetadata",
"::",
"class",
".",
"'::INHERITANCE_TYPE_'",
".",
"$",
"annot",
"->",
"value",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"DiscriminatorField",
")",
"{",
"$",
"class",
"->",
"setDiscriminatorField",
"(",
"$",
"annot",
"->",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"DiscriminatorMap",
")",
"{",
"/** @var array $value */",
"$",
"value",
"=",
"$",
"annot",
"->",
"value",
";",
"$",
"class",
"->",
"setDiscriminatorMap",
"(",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"DiscriminatorValue",
")",
"{",
"$",
"class",
"->",
"setDiscriminatorValue",
"(",
"$",
"annot",
"->",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"ChangeTrackingPolicy",
")",
"{",
"$",
"class",
"->",
"setChangeTrackingPolicy",
"(",
"constant",
"(",
"ClassMetadata",
"::",
"class",
".",
"'::CHANGETRACKING_'",
".",
"$",
"annot",
"->",
"value",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"DefaultDiscriminatorValue",
")",
"{",
"$",
"class",
"->",
"setDefaultDiscriminatorValue",
"(",
"$",
"annot",
"->",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"ReadPreference",
")",
"{",
"$",
"class",
"->",
"setReadPreference",
"(",
"$",
"annot",
"->",
"value",
",",
"$",
"annot",
"->",
"tags",
"??",
"[",
"]",
")",
";",
"}",
"}",
"if",
"(",
"$",
"documentAnnot",
"===",
"null",
")",
"{",
"throw",
"MappingException",
"::",
"classIsNotAValidDocument",
"(",
"$",
"className",
")",
";",
"}",
"if",
"(",
"$",
"documentAnnot",
"instanceof",
"ODM",
"\\",
"MappedSuperclass",
")",
"{",
"$",
"class",
"->",
"isMappedSuperclass",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"documentAnnot",
"instanceof",
"ODM",
"\\",
"EmbeddedDocument",
")",
"{",
"$",
"class",
"->",
"isEmbeddedDocument",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"documentAnnot",
"instanceof",
"ODM",
"\\",
"QueryResultDocument",
")",
"{",
"$",
"class",
"->",
"isQueryResultDocument",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"documentAnnot",
"instanceof",
"ODM",
"\\",
"File",
")",
"{",
"$",
"class",
"->",
"isFile",
"=",
"true",
";",
"if",
"(",
"$",
"documentAnnot",
"->",
"chunkSizeBytes",
"!==",
"null",
")",
"{",
"$",
"class",
"->",
"setChunkSizeBytes",
"(",
"$",
"documentAnnot",
"->",
"chunkSizeBytes",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"documentAnnot",
"->",
"db",
")",
")",
"{",
"$",
"class",
"->",
"setDatabase",
"(",
"$",
"documentAnnot",
"->",
"db",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"documentAnnot",
"->",
"collection",
")",
")",
"{",
"$",
"class",
"->",
"setCollection",
"(",
"$",
"documentAnnot",
"->",
"collection",
")",
";",
"}",
"// Store bucketName as collection name for GridFS files",
"if",
"(",
"isset",
"(",
"$",
"documentAnnot",
"->",
"bucketName",
")",
")",
"{",
"$",
"class",
"->",
"setBucketName",
"(",
"$",
"documentAnnot",
"->",
"bucketName",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"documentAnnot",
"->",
"repositoryClass",
")",
")",
"{",
"$",
"class",
"->",
"setCustomRepositoryClass",
"(",
"$",
"documentAnnot",
"->",
"repositoryClass",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"documentAnnot",
"->",
"writeConcern",
")",
")",
"{",
"$",
"class",
"->",
"setWriteConcern",
"(",
"$",
"documentAnnot",
"->",
"writeConcern",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"documentAnnot",
"->",
"indexes",
")",
")",
"{",
"foreach",
"(",
"$",
"documentAnnot",
"->",
"indexes",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"addIndex",
"(",
"$",
"class",
",",
"$",
"index",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"documentAnnot",
"->",
"readOnly",
")",
")",
"{",
"$",
"class",
"->",
"markReadOnly",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"reflClass",
"->",
"getProperties",
"(",
")",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"(",
"$",
"class",
"->",
"isMappedSuperclass",
"&&",
"!",
"$",
"property",
"->",
"isPrivate",
"(",
")",
")",
"||",
"(",
"$",
"class",
"->",
"isInheritedField",
"(",
"$",
"property",
"->",
"name",
")",
"&&",
"$",
"property",
"->",
"getDeclaringClass",
"(",
")",
"->",
"name",
"!==",
"$",
"class",
"->",
"name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"indexes",
"=",
"[",
"]",
";",
"$",
"mapping",
"=",
"[",
"'fieldName'",
"=>",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
";",
"$",
"fieldAnnot",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"reader",
"->",
"getPropertyAnnotations",
"(",
"$",
"property",
")",
"as",
"$",
"annot",
")",
"{",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"AbstractField",
")",
"{",
"$",
"fieldAnnot",
"=",
"$",
"annot",
";",
"if",
"(",
"$",
"annot",
"->",
"isDeprecated",
"(",
")",
")",
"{",
"@",
"trigger_error",
"(",
"$",
"annot",
"->",
"getDeprecationMessage",
"(",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"}",
"}",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"AbstractIndex",
")",
"{",
"$",
"indexes",
"[",
"]",
"=",
"$",
"annot",
";",
"}",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"Indexes",
")",
"{",
"// Setting the type to mixed is a workaround until https://github.com/doctrine/annotations/pull/209 is released.",
"/** @var mixed $value */",
"$",
"value",
"=",
"$",
"annot",
"->",
"value",
";",
"foreach",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"$",
"value",
":",
"[",
"$",
"value",
"]",
"as",
"$",
"index",
")",
"{",
"$",
"indexes",
"[",
"]",
"=",
"$",
"index",
";",
"}",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"AlsoLoad",
")",
"{",
"$",
"mapping",
"[",
"'alsoLoadFields'",
"]",
"=",
"(",
"array",
")",
"$",
"annot",
"->",
"value",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"Version",
")",
"{",
"$",
"mapping",
"[",
"'version'",
"]",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"Lock",
")",
"{",
"$",
"mapping",
"[",
"'lock'",
"]",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"fieldAnnot",
")",
"{",
"$",
"mapping",
"=",
"array_replace",
"(",
"$",
"mapping",
",",
"(",
"array",
")",
"$",
"fieldAnnot",
")",
";",
"$",
"class",
"->",
"mapField",
"(",
"$",
"mapping",
")",
";",
"}",
"if",
"(",
"!",
"$",
"indexes",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"indexes",
"as",
"$",
"index",
")",
"{",
"$",
"name",
"=",
"$",
"mapping",
"[",
"'name'",
"]",
"??",
"$",
"mapping",
"[",
"'fieldName'",
"]",
";",
"$",
"keys",
"=",
"[",
"$",
"name",
"=>",
"$",
"index",
"->",
"order",
"?",
":",
"'asc'",
"]",
";",
"$",
"this",
"->",
"addIndex",
"(",
"$",
"class",
",",
"$",
"index",
",",
"$",
"keys",
")",
";",
"}",
"}",
"// Set shard key after all fields to ensure we mapped all its keys",
"if",
"(",
"isset",
"(",
"$",
"classAnnotations",
"[",
"'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ShardKey'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setShardKey",
"(",
"$",
"class",
",",
"$",
"classAnnotations",
"[",
"'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\ShardKey'",
"]",
")",
";",
"}",
"/** @var ReflectionMethod $method */",
"foreach",
"(",
"$",
"reflClass",
"->",
"getMethods",
"(",
"ReflectionMethod",
"::",
"IS_PUBLIC",
")",
"as",
"$",
"method",
")",
"{",
"/* Filter for the declaring class only. Callbacks from parent\n * classes will already be registered.\n */",
"if",
"(",
"$",
"method",
"->",
"getDeclaringClass",
"(",
")",
"->",
"name",
"!==",
"$",
"reflClass",
"->",
"name",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"reader",
"->",
"getMethodAnnotations",
"(",
"$",
"method",
")",
"as",
"$",
"annot",
")",
"{",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"AlsoLoad",
")",
"{",
"$",
"class",
"->",
"registerAlsoLoadMethod",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"$",
"annot",
"->",
"value",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"classAnnotations",
"[",
"ODM",
"\\",
"HasLifecycleCallbacks",
"::",
"class",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PrePersist",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"prePersist",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PostPersist",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"postPersist",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PreUpdate",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"preUpdate",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PostUpdate",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"postUpdate",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PreRemove",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"preRemove",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PostRemove",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"postRemove",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PreLoad",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"preLoad",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PostLoad",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"postLoad",
")",
";",
"}",
"elseif",
"(",
"$",
"annot",
"instanceof",
"ODM",
"\\",
"PreFlush",
")",
"{",
"$",
"class",
"->",
"addLifecycleCallback",
"(",
"$",
"method",
"->",
"getName",
"(",
")",
",",
"Events",
"::",
"preFlush",
")",
";",
"}",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php#L46-L234 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.addFields | public function addFields() : Stage\AddFields
{
$stage = new Stage\AddFields($this);
$this->addStage($stage);
return $stage;
} | php | public function addFields() : Stage\AddFields
{
$stage = new Stage\AddFields($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"addFields",
"(",
")",
":",
"Stage",
"\\",
"AddFields",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"AddFields",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Adds new fields to documents. $addFields outputs documents that contain all
existing fields from the input documents and newly added fields.
The $addFields stage is equivalent to a $project stage that explicitly specifies
all existing fields in the input documents and adds the new fields.
If the name of the new field is the same as an existing field name (including _id),
$addFields overwrites the existing value of that field with the value of the
specified expression.
@see http://docs.mongodb.com/manual/reference/operator/aggregation/addFields/ | [
"Adds",
"new",
"fields",
"to",
"documents",
".",
"$addFields",
"outputs",
"documents",
"that",
"contain",
"all",
"existing",
"fields",
"from",
"the",
"input",
"documents",
"and",
"newly",
"added",
"fields",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L80-L86 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.bucket | public function bucket() : Stage\Bucket
{
$stage = new Stage\Bucket($this, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | php | public function bucket() : Stage\Bucket
{
$stage = new Stage\Bucket($this, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"bucket",
"(",
")",
":",
"Stage",
"\\",
"Bucket",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Bucket",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"class",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Categorizes incoming documents into groups, called buckets, based on a
specified expression and bucket boundaries.
Each bucket is represented as a document in the output. The document for
each bucket contains an _id field, whose value specifies the inclusive
lower bound of the bucket and a count field that contains the number of
documents in the bucket. The count field is included by default when the
output is not specified.
@see https://docs.mongodb.com/manual/reference/operator/aggregation/bucket/ | [
"Categorizes",
"incoming",
"documents",
"into",
"groups",
"called",
"buckets",
"based",
"on",
"a",
"specified",
"expression",
"and",
"bucket",
"boundaries",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L100-L106 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.bucketAuto | public function bucketAuto() : Stage\BucketAuto
{
$stage = new Stage\BucketAuto($this, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | php | public function bucketAuto() : Stage\BucketAuto
{
$stage = new Stage\BucketAuto($this, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"bucketAuto",
"(",
")",
":",
"Stage",
"\\",
"BucketAuto",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"BucketAuto",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"class",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Categorizes incoming documents into a specific number of groups, called
buckets, based on a specified expression.
Bucket boundaries are automatically determined in an attempt to evenly
distribute the documents into the specified number of buckets. Each
bucket is represented as a document in the output. The document for each
bucket contains an _id field, whose value specifies the inclusive lower
bound and the exclusive upper bound for the bucket, and a count field
that contains the number of documents in the bucket. The count field is
included by default when the output is not specified.
@see https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/ | [
"Categorizes",
"incoming",
"documents",
"into",
"a",
"specific",
"number",
"of",
"groups",
"called",
"buckets",
"based",
"on",
"a",
"specified",
"expression",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L122-L128 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.collStats | public function collStats() : Stage\CollStats
{
$stage = new Stage\CollStats($this);
$this->addStage($stage);
return $stage;
} | php | public function collStats() : Stage\CollStats
{
$stage = new Stage\CollStats($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"collStats",
"(",
")",
":",
"Stage",
"\\",
"CollStats",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"CollStats",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Returns statistics regarding a collection or view.
$collStats must be the first stage in an aggregation pipeline, or else
the pipeline returns an error.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/collStats/ | [
"Returns",
"statistics",
"regarding",
"a",
"collection",
"or",
"view",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L138-L144 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.count | public function count(string $fieldName) : Stage\Count
{
$stage = new Stage\Count($this, $fieldName);
$this->addStage($stage);
return $stage;
} | php | public function count(string $fieldName) : Stage\Count
{
$stage = new Stage\Count($this, $fieldName);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"count",
"(",
"string",
"$",
"fieldName",
")",
":",
"Stage",
"\\",
"Count",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Count",
"(",
"$",
"this",
",",
"$",
"fieldName",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Returns a document that contains a count of the number of documents input
to the stage.
@see https://docs.mongodb.com/manual/reference/operator/aggregation/count/ | [
"Returns",
"a",
"document",
"that",
"contains",
"a",
"count",
"of",
"the",
"number",
"of",
"documents",
"input",
"to",
"the",
"stage",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L152-L158 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.execute | public function execute(array $options = []) : Iterator
{
// Force cursor to be used
$options = array_merge($options, ['cursor' => true]);
$cursor = $this->collection->aggregate($this->getPipeline(), $options);
assert($cursor instanceof Cursor);
return $this->prepareIterator($cursor);
} | php | public function execute(array $options = []) : Iterator
{
$options = array_merge($options, ['cursor' => true]);
$cursor = $this->collection->aggregate($this->getPipeline(), $options);
assert($cursor instanceof Cursor);
return $this->prepareIterator($cursor);
} | [
"public",
"function",
"execute",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"Iterator",
"{",
"// Force cursor to be used",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"options",
",",
"[",
"'cursor'",
"=>",
"true",
"]",
")",
";",
"$",
"cursor",
"=",
"$",
"this",
"->",
"collection",
"->",
"aggregate",
"(",
"$",
"this",
"->",
"getPipeline",
"(",
")",
",",
"$",
"options",
")",
";",
"assert",
"(",
"$",
"cursor",
"instanceof",
"Cursor",
")",
";",
"return",
"$",
"this",
"->",
"prepareIterator",
"(",
"$",
"cursor",
")",
";",
"}"
] | Executes the aggregation pipeline | [
"Executes",
"the",
"aggregation",
"pipeline"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L163-L172 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.facet | public function facet() : Stage\Facet
{
$stage = new Stage\Facet($this);
$this->addStage($stage);
return $stage;
} | php | public function facet() : Stage\Facet
{
$stage = new Stage\Facet($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"facet",
"(",
")",
":",
"Stage",
"\\",
"Facet",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Facet",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Processes multiple aggregation pipelines within a single stage on the
same set of input documents.
Each sub-pipeline has its own field in the output document where its
results are stored as an array of documents. | [
"Processes",
"multiple",
"aggregation",
"pipelines",
"within",
"a",
"single",
"stage",
"on",
"the",
"same",
"set",
"of",
"input",
"documents",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L186-L192 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.geoNear | public function geoNear($x, $y = null) : Stage\GeoNear
{
$stage = new Stage\GeoNear($this, $x, $y);
$this->addStage($stage);
return $stage;
} | php | public function geoNear($x, $y = null) : Stage\GeoNear
{
$stage = new Stage\GeoNear($this, $x, $y);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"geoNear",
"(",
"$",
"x",
",",
"$",
"y",
"=",
"null",
")",
":",
"Stage",
"\\",
"GeoNear",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"GeoNear",
"(",
"$",
"this",
",",
"$",
"x",
",",
"$",
"y",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Outputs documents in order of nearest to farthest from a specified point.
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.
You can only use this as the first stage of a pipeline.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/geoNear/
@param float|array|Point $x
@param float $y | [
"Outputs",
"documents",
"in",
"order",
"of",
"nearest",
"to",
"farthest",
"from",
"a",
"specified",
"point",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L209-L215 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.getPipeline | public function getPipeline() : array
{
$pipeline = array_map(
static function (Stage $stage) {
return $stage->getExpression();
},
$this->stages
);
if ($this->getStage(0) instanceof Stage\GeoNear) {
$pipeline[0]['$geoNear']['query'] = $this->applyFilters($pipeline[0]['$geoNear']['query']);
} elseif ($this->getStage(0) instanceof Stage\IndexStats) {
// Don't apply any filters when using an IndexStats stage: since it
// needs to be the first pipeline stage, prepending a match stage
// with discriminator information will not work
return $pipeline;
} else {
$matchExpression = $this->applyFilters([]);
if ($matchExpression !== []) {
array_unshift($pipeline, ['$match' => $matchExpression]);
}
}
return $pipeline;
} | php | public function getPipeline() : array
{
$pipeline = array_map(
static function (Stage $stage) {
return $stage->getExpression();
},
$this->stages
);
if ($this->getStage(0) instanceof Stage\GeoNear) {
$pipeline[0]['$geoNear']['query'] = $this->applyFilters($pipeline[0]['$geoNear']['query']);
} elseif ($this->getStage(0) instanceof Stage\IndexStats) {
return $pipeline;
} else {
$matchExpression = $this->applyFilters([]);
if ($matchExpression !== []) {
array_unshift($pipeline, ['$match' => $matchExpression]);
}
}
return $pipeline;
} | [
"public",
"function",
"getPipeline",
"(",
")",
":",
"array",
"{",
"$",
"pipeline",
"=",
"array_map",
"(",
"static",
"function",
"(",
"Stage",
"$",
"stage",
")",
"{",
"return",
"$",
"stage",
"->",
"getExpression",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"stages",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getStage",
"(",
"0",
")",
"instanceof",
"Stage",
"\\",
"GeoNear",
")",
"{",
"$",
"pipeline",
"[",
"0",
"]",
"[",
"'$geoNear'",
"]",
"[",
"'query'",
"]",
"=",
"$",
"this",
"->",
"applyFilters",
"(",
"$",
"pipeline",
"[",
"0",
"]",
"[",
"'$geoNear'",
"]",
"[",
"'query'",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getStage",
"(",
"0",
")",
"instanceof",
"Stage",
"\\",
"IndexStats",
")",
"{",
"// Don't apply any filters when using an IndexStats stage: since it",
"// needs to be the first pipeline stage, prepending a match stage",
"// with discriminator information will not work",
"return",
"$",
"pipeline",
";",
"}",
"else",
"{",
"$",
"matchExpression",
"=",
"$",
"this",
"->",
"applyFilters",
"(",
"[",
"]",
")",
";",
"if",
"(",
"$",
"matchExpression",
"!==",
"[",
"]",
")",
"{",
"array_unshift",
"(",
"$",
"pipeline",
",",
"[",
"'$match'",
"=>",
"$",
"matchExpression",
"]",
")",
";",
"}",
"}",
"return",
"$",
"pipeline",
";",
"}"
] | Returns the assembled aggregation pipeline
For pipelines where the first stage is a $geoNear stage, it will apply
the document filters and discriminator queries to the query portion of
the geoNear operation. For all other pipelines, it prepends a $match stage
containing the required query. | [
"Returns",
"the",
"assembled",
"aggregation",
"pipeline"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L225-L250 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.getStage | public function getStage(int $index) : Stage
{
if (! isset($this->stages[$index])) {
throw new OutOfRangeException(sprintf('Could not find stage with index %d.', $index));
}
return $this->stages[$index];
} | php | public function getStage(int $index) : Stage
{
if (! isset($this->stages[$index])) {
throw new OutOfRangeException(sprintf('Could not find stage with index %d.', $index));
}
return $this->stages[$index];
} | [
"public",
"function",
"getStage",
"(",
"int",
"$",
"index",
")",
":",
"Stage",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"stages",
"[",
"$",
"index",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfRangeException",
"(",
"sprintf",
"(",
"'Could not find stage with index %d.'",
",",
"$",
"index",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"stages",
"[",
"$",
"index",
"]",
";",
"}"
] | Returns a certain stage from the pipeline | [
"Returns",
"a",
"certain",
"stage",
"from",
"the",
"pipeline"
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L255-L262 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.graphLookup | public function graphLookup(string $from) : Stage\GraphLookup
{
$stage = new Stage\GraphLookup($this, $from, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | php | public function graphLookup(string $from) : Stage\GraphLookup
{
$stage = new Stage\GraphLookup($this, $from, $this->dm, $this->class);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"graphLookup",
"(",
"string",
"$",
"from",
")",
":",
"Stage",
"\\",
"GraphLookup",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"GraphLookup",
"(",
"$",
"this",
",",
"$",
"from",
",",
"$",
"this",
"->",
"dm",
",",
"$",
"this",
"->",
"class",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Performs a recursive search on a collection, with options for restricting
the search by recursion depth and query filter.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/graphLookup/
@param string $from Target collection for the $graphLookup operation to
search, recursively matching the connectFromField to the connectToField. | [
"Performs",
"a",
"recursive",
"search",
"on",
"a",
"collection",
"with",
"options",
"for",
"restricting",
"the",
"search",
"by",
"recursion",
"depth",
"and",
"query",
"filter",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L273-L279 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.group | public function group() : Stage\Group
{
$stage = new Stage\Group($this);
$this->addStage($stage);
return $stage;
} | php | public function group() : Stage\Group
{
$stage = new Stage\Group($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"group",
"(",
")",
":",
"Stage",
"\\",
"Group",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Group",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Groups documents by some specified expression and outputs to the next
stage a document for each distinct grouping.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/group/ | [
"Groups",
"documents",
"by",
"some",
"specified",
"expression",
"and",
"outputs",
"to",
"the",
"next",
"stage",
"a",
"document",
"for",
"each",
"distinct",
"grouping",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L287-L293 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.indexStats | public function indexStats() : Stage\IndexStats
{
$stage = new Stage\IndexStats($this);
$this->addStage($stage);
return $stage;
} | php | public function indexStats() : Stage\IndexStats
{
$stage = new Stage\IndexStats($this);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"indexStats",
"(",
")",
":",
"Stage",
"\\",
"IndexStats",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"IndexStats",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Returns statistics regarding the use of each index for the collection.
@see https://docs.mongodb.org/manual/reference/operator/aggregation/indexStats/ | [
"Returns",
"statistics",
"regarding",
"the",
"use",
"of",
"each",
"index",
"for",
"the",
"collection",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L310-L316 |
doctrine/mongodb-odm | lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php | Builder.limit | public function limit(int $limit) : Stage\Limit
{
$stage = new Stage\Limit($this, $limit);
$this->addStage($stage);
return $stage;
} | php | public function limit(int $limit) : Stage\Limit
{
$stage = new Stage\Limit($this, $limit);
$this->addStage($stage);
return $stage;
} | [
"public",
"function",
"limit",
"(",
"int",
"$",
"limit",
")",
":",
"Stage",
"\\",
"Limit",
"{",
"$",
"stage",
"=",
"new",
"Stage",
"\\",
"Limit",
"(",
"$",
"this",
",",
"$",
"limit",
")",
";",
"$",
"this",
"->",
"addStage",
"(",
"$",
"stage",
")",
";",
"return",
"$",
"stage",
";",
"}"
] | Limits the number of documents passed to the next stage in the pipeline.
@see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/ | [
"Limits",
"the",
"number",
"of",
"documents",
"passed",
"to",
"the",
"next",
"stage",
"in",
"the",
"pipeline",
"."
] | train | https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php#L323-L329 |