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/Aggregation/Stage/Operator.php
Operator.range
public function range($start, $end, $step = 1) : self { $this->expr->range($start, $end, $step); return $this; }
php
public function range($start, $end, $step = 1) : self { $this->expr->range($start, $end, $step); return $this; }
[ "public", "function", "range", "(", "$", "start", ",", "$", "end", ",", "$", "step", "=", "1", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "range", "(", "$", "start", ",", "$", "end", ",", "$", "step", ")", ";", "return", "$", "this", ";", "}" ]
Returns an array whose elements are a generated sequence of numbers. $range generates the sequence from the specified starting number by successively incrementing the starting number by the specified step value up to but not including the end point. @see https://docs.mongodb.com/manual/reference/operator/aggregation/range/ @see Expr::range @param mixed|Expr $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. @param mixed|Expr $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. @param mixed|Expr $step Optional. An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1.
[ "Returns", "an", "array", "whose", "elements", "are", "a", "generated", "sequence", "of", "numbers", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L999-L1004
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.setDifference
public function setDifference($expression1, $expression2) : self { $this->expr->setDifference($expression1, $expression2); return $this; }
php
public function setDifference($expression1, $expression2) : self { $this->expr->setDifference($expression1, $expression2); return $this; }
[ "public", "function", "setDifference", "(", "$", "expression1", ",", "$", "expression2", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "setDifference", "(", "$", "expression1", ",", "$", "expression2", ")", ";", "return", "$", "this", ";", "}" ]
Takes two sets and returns an array containing the elements that only exist in the first set. The arguments can be any valid expression as long as they each resolve to an array. @see http://docs.mongodb.org/manual/reference/operator/aggregation/setDifference/ @see Expr::setDifference @param mixed|Expr $expression1 @param mixed|Expr $expression2
[ "Takes", "two", "sets", "and", "returns", "an", "array", "containing", "the", "elements", "that", "only", "exist", "in", "the", "first", "set", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1070-L1075
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.setEquals
public function setEquals($expression1, $expression2, ...$expressions) : self { $this->expr->setEquals(...func_get_args()); return $this; }
php
public function setEquals($expression1, $expression2, ...$expressions) : self { $this->expr->setEquals(...func_get_args()); return $this; }
[ "public", "function", "setEquals", "(", "$", "expression1", ",", "$", "expression2", ",", "...", "$", "expressions", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "setEquals", "(", "...", "func_get_args", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Compares two or more arrays and returns true if they have the same distinct elements and false otherwise. The arguments can be any valid expression as long as they each resolve to an array. @see http://docs.mongodb.org/manual/reference/operator/aggregation/setEquals/ @see Expr::setEquals @param mixed|Expr $expression1 @param mixed|Expr $expression2 @param mixed|Expr ...$expressions Additional sets @return $this
[ "Compares", "two", "or", "more", "arrays", "and", "returns", "true", "if", "they", "have", "the", "same", "distinct", "elements", "and", "false", "otherwise", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1092-L1097
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.setIntersection
public function setIntersection($expression1, $expression2, ...$expressions) : self { $this->expr->setIntersection(...func_get_args()); return $this; }
php
public function setIntersection($expression1, $expression2, ...$expressions) : self { $this->expr->setIntersection(...func_get_args()); return $this; }
[ "public", "function", "setIntersection", "(", "$", "expression1", ",", "$", "expression2", ",", "...", "$", "expressions", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "setIntersection", "(", "...", "func_get_args", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Takes two or more arrays and returns an array that contains the elements that appear in every input array. The arguments can be any valid expression as long as they each resolve to an array. @see http://docs.mongodb.org/manual/reference/operator/aggregation/setIntersection/ @see Expr::setIntersection @param mixed|Expr $expression1 @param mixed|Expr $expression2 @param mixed|Expr ...$expressions Additional sets
[ "Takes", "two", "or", "more", "arrays", "and", "returns", "an", "array", "that", "contains", "the", "elements", "that", "appear", "in", "every", "input", "array", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1112-L1117
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.setIsSubset
public function setIsSubset($expression1, $expression2) : self { $this->expr->setIsSubset($expression1, $expression2); return $this; }
php
public function setIsSubset($expression1, $expression2) : self { $this->expr->setIsSubset($expression1, $expression2); return $this; }
[ "public", "function", "setIsSubset", "(", "$", "expression1", ",", "$", "expression2", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "setIsSubset", "(", "$", "expression1", ",", "$", "expression2", ")", ";", "return", "$", "this", ";", "}" ]
Takes two arrays and returns true when the first array is a subset of the second, including when the first array equals the second array, and false otherwise. The arguments can be any valid expression as long as they each resolve to an array. @see http://docs.mongodb.org/manual/reference/operator/aggregation/setIsSubset/ @see Expr::setIsSubset @param mixed|Expr $expression1 @param mixed|Expr $expression2
[ "Takes", "two", "arrays", "and", "returns", "true", "when", "the", "first", "array", "is", "a", "subset", "of", "the", "second", "including", "when", "the", "first", "array", "equals", "the", "second", "array", "and", "false", "otherwise", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1132-L1137
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.setUnion
public function setUnion($expression1, $expression2, ...$expressions) : self { $this->expr->setUnion(...func_get_args()); return $this; }
php
public function setUnion($expression1, $expression2, ...$expressions) : self { $this->expr->setUnion(...func_get_args()); return $this; }
[ "public", "function", "setUnion", "(", "$", "expression1", ",", "$", "expression2", ",", "...", "$", "expressions", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "setUnion", "(", "...", "func_get_args", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Takes two or more arrays and returns an array containing the elements that appear in any input array. The arguments can be any valid expression as long as they each resolve to an array. @see http://docs.mongodb.org/manual/reference/operator/aggregation/setUnion/ @see Expr::setUnion @param mixed|Expr $expression1 @param mixed|Expr $expression2 @param mixed|Expr ...$expressions Additional sets
[ "Takes", "two", "or", "more", "arrays", "and", "returns", "an", "array", "containing", "the", "elements", "that", "appear", "in", "any", "input", "array", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1152-L1157
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.split
public function split($string, $delimiter) : self { $this->expr->split($string, $delimiter); return $this; }
php
public function split($string, $delimiter) : self { $this->expr->split($string, $delimiter); return $this; }
[ "public", "function", "split", "(", "$", "string", ",", "$", "delimiter", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "split", "(", "$", "string", ",", "$", "delimiter", ")", ";", "return", "$", "this", ";", "}" ]
Divides a string into an array of substrings based on a delimiter. $split removes the delimiter and returns the resulting substrings as elements of an array. If the delimiter is not found in the string, $split returns the original string as the only element of an array. @see https://docs.mongodb.com/manual/reference/operator/aggregation/split/ @param mixed|Expr $string The string to be split. Can be any valid expression as long as it resolves to a string. @param mixed|Expr $delimiter The delimiter to use when splitting the string expression. Can be any valid expression as long as it resolves to a string.
[ "Divides", "a", "string", "into", "an", "array", "of", "substrings", "based", "on", "a", "delimiter", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1205-L1210
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.strcasecmp
public function strcasecmp($expression1, $expression2) : self { $this->expr->strcasecmp($expression1, $expression2); return $this; }
php
public function strcasecmp($expression1, $expression2) : self { $this->expr->strcasecmp($expression1, $expression2); return $this; }
[ "public", "function", "strcasecmp", "(", "$", "expression1", ",", "$", "expression2", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "strcasecmp", "(", "$", "expression1", ",", "$", "expression2", ")", ";", "return", "$", "this", ";", "}" ]
Performs case-insensitive comparison of two strings. Returns 1 if first string is “greater than” the second string. 0 if the two strings are equal. -1 if the first string is “less than” the second string. The arguments can be any valid expression as long as they resolve to strings. @see http://docs.mongodb.org/manual/reference/operator/aggregation/strcasecmp/ @see Expr::strcasecmp @param mixed|Expr $expression1 @param mixed|Expr $expression2
[ "Performs", "case", "-", "insensitive", "comparison", "of", "two", "strings", ".", "Returns", "1", "if", "first", "string", "is", "“greater", "than”", "the", "second", "string", ".", "0", "if", "the", "two", "strings", "are", "equal", ".", "-", "1", "if", "the", "first", "string", "is", "“less", "than”", "the", "second", "string", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1245-L1250
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.substr
public function substr($string, $start, $length) : self { $this->expr->substr($string, $start, $length); return $this; }
php
public function substr($string, $start, $length) : self { $this->expr->substr($string, $start, $length); return $this; }
[ "public", "function", "substr", "(", "$", "string", ",", "$", "start", ",", "$", "length", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "substr", "(", "$", "string", ",", "$", "start", ",", "$", "length", ")", ";", "return", "$", "this", ";", "}" ]
Returns a substring of a string, starting at a specified index position and including the specified number of characters. The index is zero-based. The arguments can be any valid expression as long as long as the first argument resolves to a string, and the second and third arguments resolve to integers. @see http://docs.mongodb.org/manual/reference/operator/aggregation/substr/ @see Expr::substr @param mixed|Expr $string @param mixed|Expr $start @param mixed|Expr $length
[ "Returns", "a", "substring", "of", "a", "string", "starting", "at", "a", "specified", "index", "position", "and", "including", "the", "specified", "number", "of", "characters", ".", "The", "index", "is", "zero", "-", "based", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1293-L1298
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.subtract
public function subtract($expression1, $expression2) : self { $this->expr->subtract($expression1, $expression2); return $this; }
php
public function subtract($expression1, $expression2) : self { $this->expr->subtract($expression1, $expression2); return $this; }
[ "public", "function", "subtract", "(", "$", "expression1", ",", "$", "expression2", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "subtract", "(", "$", "expression1", ",", "$", "expression2", ")", ";", "return", "$", "this", ";", "}" ]
Subtracts two numbers to return the difference. The second argument is subtracted from the first argument. The arguments can be any valid expression as long as they resolve to numbers and/or dates. @see http://docs.mongodb.org/manual/reference/operator/aggregation/subtract/ @see Expr::subtract @param mixed|Expr $expression1 @param mixed|Expr $expression2
[ "Subtracts", "two", "numbers", "to", "return", "the", "difference", ".", "The", "second", "argument", "is", "subtracted", "from", "the", "first", "argument", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1352-L1357
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php
Operator.zip
public function zip($inputs, ?bool $useLongestLength = null, $defaults = null) : self { $this->expr->zip($inputs, $useLongestLength, $defaults); return $this; }
php
public function zip($inputs, ?bool $useLongestLength = null, $defaults = null) : self { $this->expr->zip($inputs, $useLongestLength, $defaults); return $this; }
[ "public", "function", "zip", "(", "$", "inputs", ",", "?", "bool", "$", "useLongestLength", "=", "null", ",", "$", "defaults", "=", "null", ")", ":", "self", "{", "$", "this", "->", "expr", "->", "zip", "(", "$", "inputs", ",", "$", "useLongestLength", ",", "$", "defaults", ")", ";", "return", "$", "this", ";", "}" ]
Transposes an array of input arrays so that the first element of the output array would be an array containing, the first element of the first input array, the first element of the second input array, etc. @see https://docs.mongodb.com/manual/reference/operator/aggregation/zip/ @see Expr::zip @param mixed|Expr $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. @param bool|null $useLongestLength A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. @param mixed|Expr|null $defaults An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error.
[ "Transposes", "an", "array", "of", "input", "arrays", "so", "that", "the", "first", "element", "of", "the", "output", "array", "would", "be", "an", "array", "containing", "the", "first", "element", "of", "the", "first", "input", "array", "the", "first", "element", "of", "the", "second", "input", "array", "etc", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php#L1473-L1478
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php
Facet.pipeline
public function pipeline($builder) : self { if (! $this->field) { throw new LogicException(__METHOD__ . ' requires you set a current field using field().'); } if ($builder instanceof Stage) { $builder = $builder->builder; } if (! $builder instanceof Builder) { throw new InvalidArgumentException(__METHOD__ . ' expects either an aggregation builder or an aggregation stage.'); } $this->pipelines[$this->field] = $builder; return $this; }
php
public function pipeline($builder) : self { if (! $this->field) { throw new LogicException(__METHOD__ . ' requires you set a current field using field().'); } if ($builder instanceof Stage) { $builder = $builder->builder; } if (! $builder instanceof Builder) { throw new InvalidArgumentException(__METHOD__ . ' expects either an aggregation builder or an aggregation stage.'); } $this->pipelines[$this->field] = $builder; return $this; }
[ "public", "function", "pipeline", "(", "$", "builder", ")", ":", "self", "{", "if", "(", "!", "$", "this", "->", "field", ")", "{", "throw", "new", "LogicException", "(", "__METHOD__", ".", "' requires you set a current field using field().'", ")", ";", "}", "if", "(", "$", "builder", "instanceof", "Stage", ")", "{", "$", "builder", "=", "$", "builder", "->", "builder", ";", "}", "if", "(", "!", "$", "builder", "instanceof", "Builder", ")", "{", "throw", "new", "InvalidArgumentException", "(", "__METHOD__", ".", "' expects either an aggregation builder or an aggregation stage.'", ")", ";", "}", "$", "this", "->", "pipelines", "[", "$", "this", "->", "field", "]", "=", "$", "builder", ";", "return", "$", "this", ";", "}" ]
Use the given pipeline for the current field. @param Builder|Stage $builder
[ "Use", "the", "given", "pipeline", "for", "the", "current", "field", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php#L50-L66
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/CriteriaMerger.php
CriteriaMerger.merge
public function merge(...$criterias) : array { $nonEmptyCriterias = array_values(array_filter($criterias, static function (array $criteria) { return ! empty($criteria); })); switch (count($nonEmptyCriterias)) { case 0: return []; case 1: return $nonEmptyCriterias[0]; default: return ['$and' => $nonEmptyCriterias]; } }
php
public function merge(...$criterias) : array { $nonEmptyCriterias = array_values(array_filter($criterias, static function (array $criteria) { return ! empty($criteria); })); switch (count($nonEmptyCriterias)) { case 0: return []; case 1: return $nonEmptyCriterias[0]; default: return ['$and' => $nonEmptyCriterias]; } }
[ "public", "function", "merge", "(", "...", "$", "criterias", ")", ":", "array", "{", "$", "nonEmptyCriterias", "=", "array_values", "(", "array_filter", "(", "$", "criterias", ",", "static", "function", "(", "array", "$", "criteria", ")", "{", "return", "!", "empty", "(", "$", "criteria", ")", ";", "}", ")", ")", ";", "switch", "(", "count", "(", "$", "nonEmptyCriterias", ")", ")", "{", "case", "0", ":", "return", "[", "]", ";", "case", "1", ":", "return", "$", "nonEmptyCriterias", "[", "0", "]", ";", "default", ":", "return", "[", "'$and'", "=>", "$", "nonEmptyCriterias", "]", ";", "}", "}" ]
Combines any number of criteria arrays as clauses of an "$and" query. @param array ...$criterias Any number of query criteria arrays
[ "Combines", "any", "number", "of", "criteria", "arrays", "as", "clauses", "of", "an", "$and", "query", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/CriteriaMerger.php#L25-L41
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Types/DateType.php
DateType.getDateTime
public static function getDateTime($value) : DateTimeInterface { $datetime = false; $exception = null; if ($value instanceof DateTimeInterface) { return $value; } elseif ($value instanceof UTCDateTime) { $datetime = $value->toDateTime(); $datetime->setTimezone(new DateTimeZone(date_default_timezone_get())); } elseif (is_numeric($value)) { $value = (float) $value; $seconds = (int) $value; $microseconds = abs(round($value - $seconds, 6)); $microseconds *= 1000000; $datetime = static::craftDateTime($seconds, (int) $microseconds); } elseif (is_string($value)) { try { $datetime = new DateTime($value); } catch (Throwable $e) { $exception = $e; } } if ($datetime === false) { throw new InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"' . $value . '"' : gettype($value)), 0, $exception); } return $datetime; }
php
public static function getDateTime($value) : DateTimeInterface { $datetime = false; $exception = null; if ($value instanceof DateTimeInterface) { return $value; } elseif ($value instanceof UTCDateTime) { $datetime = $value->toDateTime(); $datetime->setTimezone(new DateTimeZone(date_default_timezone_get())); } elseif (is_numeric($value)) { $value = (float) $value; $seconds = (int) $value; $microseconds = abs(round($value - $seconds, 6)); $microseconds *= 1000000; $datetime = static::craftDateTime($seconds, (int) $microseconds); } elseif (is_string($value)) { try { $datetime = new DateTime($value); } catch (Throwable $e) { $exception = $e; } } if ($datetime === false) { throw new InvalidArgumentException(sprintf('Could not convert %s to a date value', is_scalar($value) ? '"' . $value . '"' : gettype($value)), 0, $exception); } return $datetime; }
[ "public", "static", "function", "getDateTime", "(", "$", "value", ")", ":", "DateTimeInterface", "{", "$", "datetime", "=", "false", ";", "$", "exception", "=", "null", ";", "if", "(", "$", "value", "instanceof", "DateTimeInterface", ")", "{", "return", "$", "value", ";", "}", "elseif", "(", "$", "value", "instanceof", "UTCDateTime", ")", "{", "$", "datetime", "=", "$", "value", "->", "toDateTime", "(", ")", ";", "$", "datetime", "->", "setTimezone", "(", "new", "DateTimeZone", "(", "date_default_timezone_get", "(", ")", ")", ")", ";", "}", "elseif", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "$", "value", "=", "(", "float", ")", "$", "value", ";", "$", "seconds", "=", "(", "int", ")", "$", "value", ";", "$", "microseconds", "=", "abs", "(", "round", "(", "$", "value", "-", "$", "seconds", ",", "6", ")", ")", ";", "$", "microseconds", "*=", "1000000", ";", "$", "datetime", "=", "static", "::", "craftDateTime", "(", "$", "seconds", ",", "(", "int", ")", "$", "microseconds", ")", ";", "}", "elseif", "(", "is_string", "(", "$", "value", ")", ")", "{", "try", "{", "$", "datetime", "=", "new", "DateTime", "(", "$", "value", ")", ";", "}", "catch", "(", "Throwable", "$", "e", ")", "{", "$", "exception", "=", "$", "e", ";", "}", "}", "if", "(", "$", "datetime", "===", "false", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Could not convert %s to a date value'", ",", "is_scalar", "(", "$", "value", ")", "?", "'\"'", ".", "$", "value", ".", "'\"'", ":", "gettype", "(", "$", "value", ")", ")", ",", "0", ",", "$", "exception", ")", ";", "}", "return", "$", "datetime", ";", "}" ]
Converts a value to a DateTime. Supports microseconds @param mixed $value \DateTimeInterface|\MongoDB\BSON\UTCDateTime|int|float @throws InvalidArgumentException If $value is invalid.
[ "Converts", "a", "value", "to", "a", "DateTime", ".", "Supports", "microseconds" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Types/DateType.php#L37-L67
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.setDocumentManager
public function setDocumentManager(DocumentManager $dm) { $this->dm = $dm; $this->uow = $dm->getUnitOfWork(); }
php
public function setDocumentManager(DocumentManager $dm) { $this->dm = $dm; $this->uow = $dm->getUnitOfWork(); }
[ "public", "function", "setDocumentManager", "(", "DocumentManager", "$", "dm", ")", "{", "$", "this", "->", "dm", "=", "$", "dm", ";", "$", "this", "->", "uow", "=", "$", "dm", "->", "getUnitOfWork", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L95-L99
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.changed
private function changed() { if ($this->isDirty) { return; } $this->isDirty = true; if (! $this->needsSchedulingForSynchronization() || $this->owner === null) { return; } $this->uow->scheduleForSynchronization($this->owner); }
php
private function changed() { if ($this->isDirty) { return; } $this->isDirty = true; if (! $this->needsSchedulingForSynchronization() || $this->owner === null) { return; } $this->uow->scheduleForSynchronization($this->owner); }
[ "private", "function", "changed", "(", ")", "{", "if", "(", "$", "this", "->", "isDirty", ")", "{", "return", ";", "}", "$", "this", "->", "isDirty", "=", "true", ";", "if", "(", "!", "$", "this", "->", "needsSchedulingForSynchronization", "(", ")", "||", "$", "this", "->", "owner", "===", "null", ")", "{", "return", ";", "}", "$", "this", "->", "uow", "->", "scheduleForSynchronization", "(", "$", "this", "->", "owner", ")", ";", "}" ]
Marks this collection as changed/dirty.
[ "Marks", "this", "collection", "as", "changed", "/", "dirty", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L166-L179
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.isDirty
public function isDirty() { if ($this->isDirty) { return true; } if (! $this->initialized && count($this->coll)) { // not initialized collection with added elements return true; } if ($this->initialized) { // if initialized let's check with last known snapshot return $this->coll->toArray() !== $this->snapshot; } return false; }
php
public function isDirty() { if ($this->isDirty) { return true; } if (! $this->initialized && count($this->coll)) { return true; } if ($this->initialized) { return $this->coll->toArray() !== $this->snapshot; } return false; }
[ "public", "function", "isDirty", "(", ")", "{", "if", "(", "$", "this", "->", "isDirty", ")", "{", "return", "true", ";", "}", "if", "(", "!", "$", "this", "->", "initialized", "&&", "count", "(", "$", "this", "->", "coll", ")", ")", "{", "// not initialized collection with added elements", "return", "true", ";", "}", "if", "(", "$", "this", "->", "initialized", ")", "{", "// if initialized let's check with last known snapshot", "return", "$", "this", "->", "coll", "->", "toArray", "(", ")", "!==", "$", "this", "->", "snapshot", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L182-L196
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.setOwner
public function setOwner(object $document, array $mapping) { $this->owner = $document; $this->mapping = $mapping; }
php
public function setOwner(object $document, array $mapping) { $this->owner = $document; $this->mapping = $mapping; }
[ "public", "function", "setOwner", "(", "object", "$", "document", ",", "array", "$", "mapping", ")", "{", "$", "this", "->", "owner", "=", "$", "document", ";", "$", "this", "->", "mapping", "=", "$", "mapping", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L205-L209
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.clearSnapshot
public function clearSnapshot() { $this->snapshot = []; $this->isDirty = $this->coll->count() ? true : false; }
php
public function clearSnapshot() { $this->snapshot = []; $this->isDirty = $this->coll->count() ? true : false; }
[ "public", "function", "clearSnapshot", "(", ")", "{", "$", "this", "->", "snapshot", "=", "[", "]", ";", "$", "this", "->", "isDirty", "=", "$", "this", "->", "coll", "->", "count", "(", ")", "?", "true", ":", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L226-L230
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.getDeleteDiff
public function getDeleteDiff() { return array_udiff_assoc( $this->snapshot, $this->coll->toArray(), static function ($a, $b) { return $a === $b ? 0 : 1; } ); }
php
public function getDeleteDiff() { return array_udiff_assoc( $this->snapshot, $this->coll->toArray(), static function ($a, $b) { return $a === $b ? 0 : 1; } ); }
[ "public", "function", "getDeleteDiff", "(", ")", "{", "return", "array_udiff_assoc", "(", "$", "this", "->", "snapshot", ",", "$", "this", "->", "coll", "->", "toArray", "(", ")", ",", "static", "function", "(", "$", "a", ",", "$", "b", ")", "{", "return", "$", "a", "===", "$", "b", "?", "0", ":", "1", ";", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L239-L248
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.getTypeClass
public function getTypeClass() { if ($this->dm === null) { throw new MongoDBException('No DocumentManager is associated with this PersistentCollection, please set one using setDocumentManager method.'); } if (empty($this->mapping)) { throw new MongoDBException('No mapping is associated with this PersistentCollection, please set one using setOwner method.'); } if (empty($this->mapping['targetDocument'])) { throw new MongoDBException('Specifying targetDocument is required for the ClassMetadata to be obtained.'); } return $this->dm->getClassMetadata($this->mapping['targetDocument']); }
php
public function getTypeClass() { if ($this->dm === null) { throw new MongoDBException('No DocumentManager is associated with this PersistentCollection, please set one using setDocumentManager method.'); } if (empty($this->mapping)) { throw new MongoDBException('No mapping is associated with this PersistentCollection, please set one using setOwner method.'); } if (empty($this->mapping['targetDocument'])) { throw new MongoDBException('Specifying targetDocument is required for the ClassMetadata to be obtained.'); } return $this->dm->getClassMetadata($this->mapping['targetDocument']); }
[ "public", "function", "getTypeClass", "(", ")", "{", "if", "(", "$", "this", "->", "dm", "===", "null", ")", "{", "throw", "new", "MongoDBException", "(", "'No DocumentManager is associated with this PersistentCollection, please set one using setDocumentManager method.'", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "mapping", ")", ")", "{", "throw", "new", "MongoDBException", "(", "'No mapping is associated with this PersistentCollection, please set one using setOwner method.'", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "mapping", "[", "'targetDocument'", "]", ")", ")", "{", "throw", "new", "MongoDBException", "(", "'Specifying targetDocument is required for the ClassMetadata to be obtained.'", ")", ";", "}", "return", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "this", "->", "mapping", "[", "'targetDocument'", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L305-L320
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.removeElement
public function removeElement($element) { $this->initialize(); $removed = $this->coll->removeElement($element); if (! $removed) { return $removed; } $this->changed(); return $removed; }
php
public function removeElement($element) { $this->initialize(); $removed = $this->coll->removeElement($element); if (! $removed) { return $removed; } $this->changed(); return $removed; }
[ "public", "function", "removeElement", "(", "$", "element", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "$", "removed", "=", "$", "this", "->", "coll", "->", "removeElement", "(", "$", "element", ")", ";", "if", "(", "!", "$", "removed", ")", "{", "return", "$", "removed", ";", "}", "$", "this", "->", "changed", "(", ")", ";", "return", "$", "removed", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L359-L371
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.slice
public function slice($offset, $length = null) { $this->initialize(); return $this->coll->slice($offset, $length); }
php
public function slice($offset, $length = null) { $this->initialize(); return $this->coll->slice($offset, $length); }
[ "public", "function", "slice", "(", "$", "offset", ",", "$", "length", "=", "null", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "return", "$", "this", "->", "coll", "->", "slice", "(", "$", "offset", ",", "$", "length", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L562-L566
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.doAdd
private function doAdd($value, $arrayAccess) { /* Initialize the collection before calling add() so this append operation * uses the appropriate key. Otherwise, we risk overwriting original data * when $newObjects are re-added in a later call to initialize(). */ if (isset($this->mapping['strategy']) && CollectionHelper::isHash($this->mapping['strategy'])) { $this->initialize(); } $arrayAccess ? $this->coll->offsetSet(null, $value) : $this->coll->add($value); $this->changed(); if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) { $this->uow->unscheduleOrphanRemoval($value); } return true; }
php
private function doAdd($value, $arrayAccess) { if (isset($this->mapping['strategy']) && CollectionHelper::isHash($this->mapping['strategy'])) { $this->initialize(); } $arrayAccess ? $this->coll->offsetSet(null, $value) : $this->coll->add($value); $this->changed(); if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) { $this->uow->unscheduleOrphanRemoval($value); } return true; }
[ "private", "function", "doAdd", "(", "$", "value", ",", "$", "arrayAccess", ")", "{", "/* Initialize the collection before calling add() so this append operation\n * uses the appropriate key. Otherwise, we risk overwriting original data\n * when $newObjects are re-added in a later call to initialize().\n */", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "'strategy'", "]", ")", "&&", "CollectionHelper", "::", "isHash", "(", "$", "this", "->", "mapping", "[", "'strategy'", "]", ")", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "}", "$", "arrayAccess", "?", "$", "this", "->", "coll", "->", "offsetSet", "(", "null", ",", "$", "value", ")", ":", "$", "this", "->", "coll", "->", "add", "(", "$", "value", ")", ";", "$", "this", "->", "changed", "(", ")", ";", "if", "(", "$", "this", "->", "uow", "!==", "null", "&&", "$", "this", "->", "isOrphanRemovalEnabled", "(", ")", "&&", "$", "value", "!==", "null", ")", "{", "$", "this", "->", "uow", "->", "unscheduleOrphanRemoval", "(", "$", "value", ")", ";", "}", "return", "true", ";", "}" ]
Actual logic for adding an element to the collection. @param mixed $value @param bool $arrayAccess @return bool
[ "Actual", "logic", "for", "adding", "an", "element", "to", "the", "collection", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L683-L700
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.doRemove
private function doRemove($offset, $arrayAccess) { $this->initialize(); if ($arrayAccess) { $this->coll->offsetUnset($offset); $removed = true; } else { $removed = $this->coll->remove($offset); } if (! $removed && ! $arrayAccess) { return $removed; } $this->changed(); return $removed; }
php
private function doRemove($offset, $arrayAccess) { $this->initialize(); if ($arrayAccess) { $this->coll->offsetUnset($offset); $removed = true; } else { $removed = $this->coll->remove($offset); } if (! $removed && ! $arrayAccess) { return $removed; } $this->changed(); return $removed; }
[ "private", "function", "doRemove", "(", "$", "offset", ",", "$", "arrayAccess", ")", "{", "$", "this", "->", "initialize", "(", ")", ";", "if", "(", "$", "arrayAccess", ")", "{", "$", "this", "->", "coll", "->", "offsetUnset", "(", "$", "offset", ")", ";", "$", "removed", "=", "true", ";", "}", "else", "{", "$", "removed", "=", "$", "this", "->", "coll", "->", "remove", "(", "$", "offset", ")", ";", "}", "if", "(", "!", "$", "removed", "&&", "!", "$", "arrayAccess", ")", "{", "return", "$", "removed", ";", "}", "$", "this", "->", "changed", "(", ")", ";", "return", "$", "removed", ";", "}" ]
Actual logic for removing element by its key. @param mixed $offset @param bool $arrayAccess @return bool
[ "Actual", "logic", "for", "removing", "element", "by", "its", "key", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L710-L727
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.doSet
private function doSet($offset, $value, $arrayAccess) { $arrayAccess ? $this->coll->offsetSet($offset, $value) : $this->coll->set($offset, $value); // Handle orphanRemoval if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) { $this->uow->unscheduleOrphanRemoval($value); } $this->changed(); }
php
private function doSet($offset, $value, $arrayAccess) { $arrayAccess ? $this->coll->offsetSet($offset, $value) : $this->coll->set($offset, $value); if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) { $this->uow->unscheduleOrphanRemoval($value); } $this->changed(); }
[ "private", "function", "doSet", "(", "$", "offset", ",", "$", "value", ",", "$", "arrayAccess", ")", "{", "$", "arrayAccess", "?", "$", "this", "->", "coll", "->", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", ":", "$", "this", "->", "coll", "->", "set", "(", "$", "offset", ",", "$", "value", ")", ";", "// Handle orphanRemoval", "if", "(", "$", "this", "->", "uow", "!==", "null", "&&", "$", "this", "->", "isOrphanRemovalEnabled", "(", ")", "&&", "$", "value", "!==", "null", ")", "{", "$", "this", "->", "uow", "->", "unscheduleOrphanRemoval", "(", "$", "value", ")", ";", "}", "$", "this", "->", "changed", "(", ")", ";", "}" ]
Actual logic for setting an element in the collection. @param mixed $offset @param mixed $value @param bool $arrayAccess
[ "Actual", "logic", "for", "setting", "an", "element", "in", "the", "collection", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L736-L746
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.isOrphanRemovalEnabled
private function isOrphanRemovalEnabled() { if ($this->mapping === null) { return false; } if (isset($this->mapping['embedded'])) { return true; } if (isset($this->mapping['reference']) && $this->mapping['isOwningSide'] && $this->mapping['orphanRemoval']) { return true; } return false; }
php
private function isOrphanRemovalEnabled() { if ($this->mapping === null) { return false; } if (isset($this->mapping['embedded'])) { return true; } if (isset($this->mapping['reference']) && $this->mapping['isOwningSide'] && $this->mapping['orphanRemoval']) { return true; } return false; }
[ "private", "function", "isOrphanRemovalEnabled", "(", ")", "{", "if", "(", "$", "this", "->", "mapping", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "'embedded'", "]", ")", ")", "{", "return", "true", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "'reference'", "]", ")", "&&", "$", "this", "->", "mapping", "[", "'isOwningSide'", "]", "&&", "$", "this", "->", "mapping", "[", "'orphanRemoval'", "]", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns whether or not this collection has orphan removal enabled. Embedded documents are automatically considered as "orphan removal enabled" because they might have references that require to trigger cascade remove operations. @return bool
[ "Returns", "whether", "or", "not", "this", "collection", "has", "orphan", "removal", "enabled", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L756-L771
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
PersistentCollectionTrait.needsSchedulingForSynchronization
private function needsSchedulingForSynchronization() { return $this->owner && $this->dm && ! empty($this->mapping['isOwningSide']) && $this->dm->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify(); }
php
private function needsSchedulingForSynchronization() { return $this->owner && $this->dm && ! empty($this->mapping['isOwningSide']) && $this->dm->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify(); }
[ "private", "function", "needsSchedulingForSynchronization", "(", ")", "{", "return", "$", "this", "->", "owner", "&&", "$", "this", "->", "dm", "&&", "!", "empty", "(", "$", "this", "->", "mapping", "[", "'isOwningSide'", "]", ")", "&&", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "this", "->", "owner", ")", ")", "->", "isChangeTrackingNotify", "(", ")", ";", "}" ]
Checks whether collection owner needs to be scheduled for dirty change in case the collection is modified. @return bool
[ "Checks", "whether", "collection", "owner", "needs", "to", "be", "scheduled", "for", "dirty", "change", "in", "case", "the", "collection", "is", "modified", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php#L778-L782
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.debug
public function debug(?string $name = null) { return $name !== null ? $this->query[$name] : $this->query; }
php
public function debug(?string $name = null) { return $name !== null ? $this->query[$name] : $this->query; }
[ "public", "function", "debug", "(", "?", "string", "$", "name", "=", "null", ")", "{", "return", "$", "name", "!==", "null", "?", "$", "this", "->", "query", "[", "$", "name", "]", ":", "$", "this", "->", "query", ";", "}" ]
Return an array of information about the query structure for debugging. The $name parameter may be used to return a specific key from the internal $query array property. If omitted, the entire array will be returned.
[ "Return", "an", "array", "of", "information", "about", "the", "query", "structure", "for", "debugging", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L167-L170
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.execute
public function execute() { $results = $this->runQuery(); if (! $this->hydrate) { return $results; } $uow = $this->dm->getUnitOfWork(); /* If a single document is returned from a findAndModify command and it * includes the identifier field, attempt hydration. */ if (($this->query['type'] === self::TYPE_FIND_AND_UPDATE || $this->query['type'] === self::TYPE_FIND_AND_REMOVE) && is_array($results) && isset($results['_id'])) { $results = $uow->getOrCreateDocument($this->class->name, $results, $this->unitOfWorkHints); if (! empty($this->primers)) { $referencePrimer = new ReferencePrimer($this->dm, $uow); foreach ($this->primers as $fieldName => $primer) { $primer = is_callable($primer) ? $primer : null; $referencePrimer->primeReferences($this->class, [$results], $fieldName, $this->unitOfWorkHints, $primer); } } } return $results; }
php
public function execute() { $results = $this->runQuery(); if (! $this->hydrate) { return $results; } $uow = $this->dm->getUnitOfWork(); if (($this->query['type'] === self::TYPE_FIND_AND_UPDATE || $this->query['type'] === self::TYPE_FIND_AND_REMOVE) && is_array($results) && isset($results['_id'])) { $results = $uow->getOrCreateDocument($this->class->name, $results, $this->unitOfWorkHints); if (! empty($this->primers)) { $referencePrimer = new ReferencePrimer($this->dm, $uow); foreach ($this->primers as $fieldName => $primer) { $primer = is_callable($primer) ? $primer : null; $referencePrimer->primeReferences($this->class, [$results], $fieldName, $this->unitOfWorkHints, $primer); } } } return $results; }
[ "public", "function", "execute", "(", ")", "{", "$", "results", "=", "$", "this", "->", "runQuery", "(", ")", ";", "if", "(", "!", "$", "this", "->", "hydrate", ")", "{", "return", "$", "results", ";", "}", "$", "uow", "=", "$", "this", "->", "dm", "->", "getUnitOfWork", "(", ")", ";", "/* If a single document is returned from a findAndModify command and it\n * includes the identifier field, attempt hydration.\n */", "if", "(", "(", "$", "this", "->", "query", "[", "'type'", "]", "===", "self", "::", "TYPE_FIND_AND_UPDATE", "||", "$", "this", "->", "query", "[", "'type'", "]", "===", "self", "::", "TYPE_FIND_AND_REMOVE", ")", "&&", "is_array", "(", "$", "results", ")", "&&", "isset", "(", "$", "results", "[", "'_id'", "]", ")", ")", "{", "$", "results", "=", "$", "uow", "->", "getOrCreateDocument", "(", "$", "this", "->", "class", "->", "name", ",", "$", "results", ",", "$", "this", "->", "unitOfWorkHints", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "primers", ")", ")", "{", "$", "referencePrimer", "=", "new", "ReferencePrimer", "(", "$", "this", "->", "dm", ",", "$", "uow", ")", ";", "foreach", "(", "$", "this", "->", "primers", "as", "$", "fieldName", "=>", "$", "primer", ")", "{", "$", "primer", "=", "is_callable", "(", "$", "primer", ")", "?", "$", "primer", ":", "null", ";", "$", "referencePrimer", "->", "primeReferences", "(", "$", "this", "->", "class", ",", "[", "$", "results", "]", ",", "$", "fieldName", ",", "$", "this", "->", "unitOfWorkHints", ",", "$", "primer", ")", ";", "}", "}", "}", "return", "$", "results", ";", "}" ]
Execute the query and returns the results. @return Iterator|UpdateResult|InsertOneResult|DeleteResult|array|object|int|null @throws MongoDBException
[ "Execute", "the", "query", "and", "returns", "the", "results", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L179-L208
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.getIterator
public function getIterator() : Iterator { switch ($this->query['type']) { case self::TYPE_FIND: case self::TYPE_DISTINCT: break; default: throw new BadMethodCallException('Iterator would not be returned for query type: ' . $this->query['type']); } if ($this->iterator === null) { $result = $this->execute(); if (! $result instanceof Iterator) { throw new UnexpectedValueException('Iterator was not returned for query type: ' . $this->query['type']); } $this->iterator = $result; } return $this->iterator; }
php
public function getIterator() : Iterator { switch ($this->query['type']) { case self::TYPE_FIND: case self::TYPE_DISTINCT: break; default: throw new BadMethodCallException('Iterator would not be returned for query type: ' . $this->query['type']); } if ($this->iterator === null) { $result = $this->execute(); if (! $result instanceof Iterator) { throw new UnexpectedValueException('Iterator was not returned for query type: ' . $this->query['type']); } $this->iterator = $result; } return $this->iterator; }
[ "public", "function", "getIterator", "(", ")", ":", "Iterator", "{", "switch", "(", "$", "this", "->", "query", "[", "'type'", "]", ")", "{", "case", "self", "::", "TYPE_FIND", ":", "case", "self", "::", "TYPE_DISTINCT", ":", "break", ";", "default", ":", "throw", "new", "BadMethodCallException", "(", "'Iterator would not be returned for query type: '", ".", "$", "this", "->", "query", "[", "'type'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "iterator", "===", "null", ")", "{", "$", "result", "=", "$", "this", "->", "execute", "(", ")", ";", "if", "(", "!", "$", "result", "instanceof", "Iterator", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'Iterator was not returned for query type: '", ".", "$", "this", "->", "query", "[", "'type'", "]", ")", ";", "}", "$", "this", "->", "iterator", "=", "$", "result", ";", "}", "return", "$", "this", "->", "iterator", ";", "}" ]
Execute the query and return its result, which must be an Iterator. If the query type is not expected to return an Iterator, BadMethodCallException will be thrown before executing the query. Otherwise, the query will be executed and UnexpectedValueException will be thrown if {@link Query::execute()} does not return an Iterator. @see http://php.net/manual/en/iteratoraggregate.getiterator.php @throws BadMethodCallException If the query type would not return an Iterator. @throws UnexpectedValueException If the query did not return an Iterator. @throws MongoDBException
[ "Execute", "the", "query", "and", "return", "its", "result", "which", "must", "be", "an", "Iterator", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L237-L257
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.getQueryOptions
private function getQueryOptions(string ...$keys) : array { return array_filter( array_intersect_key($this->query, array_flip($keys)), static function ($value) { return $value !== null; } ); }
php
private function getQueryOptions(string ...$keys) : array { return array_filter( array_intersect_key($this->query, array_flip($keys)), static function ($value) { return $value !== null; } ); }
[ "private", "function", "getQueryOptions", "(", "string", "...", "$", "keys", ")", ":", "array", "{", "return", "array_filter", "(", "array_intersect_key", "(", "$", "this", "->", "query", ",", "array_flip", "(", "$", "keys", ")", ")", ",", "static", "function", "(", "$", "value", ")", "{", "return", "$", "value", "!==", "null", ";", "}", ")", ";", "}" ]
Returns an array containing the specified keys and their values from the query array, provided they exist and are not null.
[ "Returns", "an", "array", "containing", "the", "specified", "keys", "and", "their", "values", "from", "the", "query", "array", "provided", "they", "exist", "and", "are", "not", "null", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L331-L339
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.makeIterator
private function makeIterator(Traversable $cursor) : Iterator { if ($this->hydrate) { $cursor = new HydratingIterator($cursor, $this->dm->getUnitOfWork(), $this->class, $this->unitOfWorkHints); } $cursor = new CachingIterator($cursor); if (! empty($this->primers)) { $referencePrimer = new ReferencePrimer($this->dm, $this->dm->getUnitOfWork()); $cursor = new PrimingIterator($cursor, $this->class, $referencePrimer, $this->primers, $this->unitOfWorkHints); } return $cursor; }
php
private function makeIterator(Traversable $cursor) : Iterator { if ($this->hydrate) { $cursor = new HydratingIterator($cursor, $this->dm->getUnitOfWork(), $this->class, $this->unitOfWorkHints); } $cursor = new CachingIterator($cursor); if (! empty($this->primers)) { $referencePrimer = new ReferencePrimer($this->dm, $this->dm->getUnitOfWork()); $cursor = new PrimingIterator($cursor, $this->class, $referencePrimer, $this->primers, $this->unitOfWorkHints); } return $cursor; }
[ "private", "function", "makeIterator", "(", "Traversable", "$", "cursor", ")", ":", "Iterator", "{", "if", "(", "$", "this", "->", "hydrate", ")", "{", "$", "cursor", "=", "new", "HydratingIterator", "(", "$", "cursor", ",", "$", "this", "->", "dm", "->", "getUnitOfWork", "(", ")", ",", "$", "this", "->", "class", ",", "$", "this", "->", "unitOfWorkHints", ")", ";", "}", "$", "cursor", "=", "new", "CachingIterator", "(", "$", "cursor", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "primers", ")", ")", "{", "$", "referencePrimer", "=", "new", "ReferencePrimer", "(", "$", "this", "->", "dm", ",", "$", "this", "->", "dm", "->", "getUnitOfWork", "(", ")", ")", ";", "$", "cursor", "=", "new", "PrimingIterator", "(", "$", "cursor", ",", "$", "this", "->", "class", ",", "$", "referencePrimer", ",", "$", "this", "->", "primers", ",", "$", "this", "->", "unitOfWorkHints", ")", ";", "}", "return", "$", "cursor", ";", "}" ]
Decorate the cursor with caching, hydration, and priming behavior. Note: while this method could strictly take a MongoDB\Driver\Cursor, we accept Traversable for testing purposes since Cursor cannot be mocked. HydratingIterator and CachingIterator both expect a Traversable so this should not have any adverse effects.
[ "Decorate", "the", "cursor", "with", "caching", "hydration", "and", "priming", "behavior", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L349-L363
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.renameQueryOptions
private function renameQueryOptions(array $options, array $rename) : array { if (empty($options)) { return $options; } $options = array_combine( array_map( static function ($key) use ($rename) { return $rename[$key] ?? $key; }, array_keys($options) ), array_values($options) ); // Necessary because of https://github.com/phpstan/phpstan/issues/1580 assert($options !== false); return $options; }
php
private function renameQueryOptions(array $options, array $rename) : array { if (empty($options)) { return $options; } $options = array_combine( array_map( static function ($key) use ($rename) { return $rename[$key] ?? $key; }, array_keys($options) ), array_values($options) ); assert($options !== false); return $options; }
[ "private", "function", "renameQueryOptions", "(", "array", "$", "options", ",", "array", "$", "rename", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "options", ")", ")", "{", "return", "$", "options", ";", "}", "$", "options", "=", "array_combine", "(", "array_map", "(", "static", "function", "(", "$", "key", ")", "use", "(", "$", "rename", ")", "{", "return", "$", "rename", "[", "$", "key", "]", "??", "$", "key", ";", "}", ",", "array_keys", "(", "$", "options", ")", ")", ",", "array_values", "(", "$", "options", ")", ")", ";", "// Necessary because of https://github.com/phpstan/phpstan/issues/1580", "assert", "(", "$", "options", "!==", "false", ")", ";", "return", "$", "options", ";", "}" ]
Returns an array with its keys renamed based on the translation map. @return array $rename Translation map (from => to) for renaming keys
[ "Returns", "an", "array", "with", "its", "keys", "renamed", "based", "on", "the", "translation", "map", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L370-L390
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/Query.php
Query.runQuery
private function runQuery() { $options = $this->options; switch ($this->query['type']) { case self::TYPE_FIND: $queryOptions = $this->getQueryOptions('select', 'sort', 'skip', 'limit', 'readPreference'); $queryOptions = $this->renameQueryOptions($queryOptions, ['select' => 'projection']); $cursor = $this->collection->find( $this->query['query'], array_merge($options, $queryOptions) ); return $this->makeIterator($cursor); case self::TYPE_FIND_AND_UPDATE: $queryOptions = $this->getQueryOptions('select', 'sort', 'upsert'); $queryOptions = $this->renameQueryOptions($queryOptions, ['select' => 'projection']); $queryOptions['returnDocument'] = $this->query['new'] ?? false ? FindOneAndUpdate::RETURN_DOCUMENT_AFTER : FindOneAndUpdate::RETURN_DOCUMENT_BEFORE; $operation = $this->isFirstKeyUpdateOperator() ? 'findOneAndUpdate' : 'findOneAndReplace'; return $this->collection->{$operation}( $this->query['query'], $this->query['newObj'], array_merge($options, $queryOptions) ); case self::TYPE_FIND_AND_REMOVE: $queryOptions = $this->getQueryOptions('select', 'sort'); $queryOptions = $this->renameQueryOptions($queryOptions, ['select' => 'projection']); return $this->collection->findOneAndDelete( $this->query['query'], array_merge($options, $queryOptions) ); case self::TYPE_INSERT: return $this->collection->insertOne($this->query['newObj'], $options); case self::TYPE_UPDATE: $multiple = $this->query['multiple'] ?? false; if ($this->isFirstKeyUpdateOperator()) { $operation = 'updateOne'; } else { if ($multiple) { throw new InvalidArgumentException('Combining the "multiple" option without using an update operator as first operation in a query is not supported.'); } $operation = 'replaceOne'; } if ($multiple) { return $this->collection->updateMany( $this->query['query'], $this->query['newObj'], array_merge($options, $this->getQueryOptions('upsert')) ); } return $this->collection->{$operation}( $this->query['query'], $this->query['newObj'], array_merge($options, $this->getQueryOptions('upsert')) ); case self::TYPE_REMOVE: return $this->collection->deleteMany($this->query['query'], $options); case self::TYPE_DISTINCT: $collection = $this->collection; $query = $this->query; return $collection->distinct( $query['distinct'], $query['query'], array_merge($options, $this->getQueryOptions('readPreference')) ); case self::TYPE_COUNT: $collection = $this->collection; $query = $this->query; return $collection->count( $query['query'], array_merge($options, $this->getQueryOptions('hint', 'limit', 'skip', 'readPreference')) ); default: throw new InvalidArgumentException('Invalid query type: ' . $this->query['type']); } }
php
private function runQuery() { $options = $this->options; switch ($this->query['type']) { case self::TYPE_FIND: $queryOptions = $this->getQueryOptions('select', 'sort', 'skip', 'limit', 'readPreference'); $queryOptions = $this->renameQueryOptions($queryOptions, ['select' => 'projection']); $cursor = $this->collection->find( $this->query['query'], array_merge($options, $queryOptions) ); return $this->makeIterator($cursor); case self::TYPE_FIND_AND_UPDATE: $queryOptions = $this->getQueryOptions('select', 'sort', 'upsert'); $queryOptions = $this->renameQueryOptions($queryOptions, ['select' => 'projection']); $queryOptions['returnDocument'] = $this->query['new'] ?? false ? FindOneAndUpdate::RETURN_DOCUMENT_AFTER : FindOneAndUpdate::RETURN_DOCUMENT_BEFORE; $operation = $this->isFirstKeyUpdateOperator() ? 'findOneAndUpdate' : 'findOneAndReplace'; return $this->collection->{$operation}( $this->query['query'], $this->query['newObj'], array_merge($options, $queryOptions) ); case self::TYPE_FIND_AND_REMOVE: $queryOptions = $this->getQueryOptions('select', 'sort'); $queryOptions = $this->renameQueryOptions($queryOptions, ['select' => 'projection']); return $this->collection->findOneAndDelete( $this->query['query'], array_merge($options, $queryOptions) ); case self::TYPE_INSERT: return $this->collection->insertOne($this->query['newObj'], $options); case self::TYPE_UPDATE: $multiple = $this->query['multiple'] ?? false; if ($this->isFirstKeyUpdateOperator()) { $operation = 'updateOne'; } else { if ($multiple) { throw new InvalidArgumentException('Combining the "multiple" option without using an update operator as first operation in a query is not supported.'); } $operation = 'replaceOne'; } if ($multiple) { return $this->collection->updateMany( $this->query['query'], $this->query['newObj'], array_merge($options, $this->getQueryOptions('upsert')) ); } return $this->collection->{$operation}( $this->query['query'], $this->query['newObj'], array_merge($options, $this->getQueryOptions('upsert')) ); case self::TYPE_REMOVE: return $this->collection->deleteMany($this->query['query'], $options); case self::TYPE_DISTINCT: $collection = $this->collection; $query = $this->query; return $collection->distinct( $query['distinct'], $query['query'], array_merge($options, $this->getQueryOptions('readPreference')) ); case self::TYPE_COUNT: $collection = $this->collection; $query = $this->query; return $collection->count( $query['query'], array_merge($options, $this->getQueryOptions('hint', 'limit', 'skip', 'readPreference')) ); default: throw new InvalidArgumentException('Invalid query type: ' . $this->query['type']); } }
[ "private", "function", "runQuery", "(", ")", "{", "$", "options", "=", "$", "this", "->", "options", ";", "switch", "(", "$", "this", "->", "query", "[", "'type'", "]", ")", "{", "case", "self", "::", "TYPE_FIND", ":", "$", "queryOptions", "=", "$", "this", "->", "getQueryOptions", "(", "'select'", ",", "'sort'", ",", "'skip'", ",", "'limit'", ",", "'readPreference'", ")", ";", "$", "queryOptions", "=", "$", "this", "->", "renameQueryOptions", "(", "$", "queryOptions", ",", "[", "'select'", "=>", "'projection'", "]", ")", ";", "$", "cursor", "=", "$", "this", "->", "collection", "->", "find", "(", "$", "this", "->", "query", "[", "'query'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "queryOptions", ")", ")", ";", "return", "$", "this", "->", "makeIterator", "(", "$", "cursor", ")", ";", "case", "self", "::", "TYPE_FIND_AND_UPDATE", ":", "$", "queryOptions", "=", "$", "this", "->", "getQueryOptions", "(", "'select'", ",", "'sort'", ",", "'upsert'", ")", ";", "$", "queryOptions", "=", "$", "this", "->", "renameQueryOptions", "(", "$", "queryOptions", ",", "[", "'select'", "=>", "'projection'", "]", ")", ";", "$", "queryOptions", "[", "'returnDocument'", "]", "=", "$", "this", "->", "query", "[", "'new'", "]", "??", "false", "?", "FindOneAndUpdate", "::", "RETURN_DOCUMENT_AFTER", ":", "FindOneAndUpdate", "::", "RETURN_DOCUMENT_BEFORE", ";", "$", "operation", "=", "$", "this", "->", "isFirstKeyUpdateOperator", "(", ")", "?", "'findOneAndUpdate'", ":", "'findOneAndReplace'", ";", "return", "$", "this", "->", "collection", "->", "{", "$", "operation", "}", "(", "$", "this", "->", "query", "[", "'query'", "]", ",", "$", "this", "->", "query", "[", "'newObj'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "queryOptions", ")", ")", ";", "case", "self", "::", "TYPE_FIND_AND_REMOVE", ":", "$", "queryOptions", "=", "$", "this", "->", "getQueryOptions", "(", "'select'", ",", "'sort'", ")", ";", "$", "queryOptions", "=", "$", "this", "->", "renameQueryOptions", "(", "$", "queryOptions", ",", "[", "'select'", "=>", "'projection'", "]", ")", ";", "return", "$", "this", "->", "collection", "->", "findOneAndDelete", "(", "$", "this", "->", "query", "[", "'query'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "queryOptions", ")", ")", ";", "case", "self", "::", "TYPE_INSERT", ":", "return", "$", "this", "->", "collection", "->", "insertOne", "(", "$", "this", "->", "query", "[", "'newObj'", "]", ",", "$", "options", ")", ";", "case", "self", "::", "TYPE_UPDATE", ":", "$", "multiple", "=", "$", "this", "->", "query", "[", "'multiple'", "]", "??", "false", ";", "if", "(", "$", "this", "->", "isFirstKeyUpdateOperator", "(", ")", ")", "{", "$", "operation", "=", "'updateOne'", ";", "}", "else", "{", "if", "(", "$", "multiple", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Combining the \"multiple\" option without using an update operator as first operation in a query is not supported.'", ")", ";", "}", "$", "operation", "=", "'replaceOne'", ";", "}", "if", "(", "$", "multiple", ")", "{", "return", "$", "this", "->", "collection", "->", "updateMany", "(", "$", "this", "->", "query", "[", "'query'", "]", ",", "$", "this", "->", "query", "[", "'newObj'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "this", "->", "getQueryOptions", "(", "'upsert'", ")", ")", ")", ";", "}", "return", "$", "this", "->", "collection", "->", "{", "$", "operation", "}", "(", "$", "this", "->", "query", "[", "'query'", "]", ",", "$", "this", "->", "query", "[", "'newObj'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "this", "->", "getQueryOptions", "(", "'upsert'", ")", ")", ")", ";", "case", "self", "::", "TYPE_REMOVE", ":", "return", "$", "this", "->", "collection", "->", "deleteMany", "(", "$", "this", "->", "query", "[", "'query'", "]", ",", "$", "options", ")", ";", "case", "self", "::", "TYPE_DISTINCT", ":", "$", "collection", "=", "$", "this", "->", "collection", ";", "$", "query", "=", "$", "this", "->", "query", ";", "return", "$", "collection", "->", "distinct", "(", "$", "query", "[", "'distinct'", "]", ",", "$", "query", "[", "'query'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "this", "->", "getQueryOptions", "(", "'readPreference'", ")", ")", ")", ";", "case", "self", "::", "TYPE_COUNT", ":", "$", "collection", "=", "$", "this", "->", "collection", ";", "$", "query", "=", "$", "this", "->", "query", ";", "return", "$", "collection", "->", "count", "(", "$", "query", "[", "'query'", "]", ",", "array_merge", "(", "$", "options", ",", "$", "this", "->", "getQueryOptions", "(", "'hint'", ",", "'limit'", ",", "'skip'", ",", "'readPreference'", ")", ")", ")", ";", "default", ":", "throw", "new", "InvalidArgumentException", "(", "'Invalid query type: '", ".", "$", "this", "->", "query", "[", "'type'", "]", ")", ";", "}", "}" ]
Execute the query and return its result. The return value will vary based on the query type. Commands with results (e.g. aggregate, inline mapReduce) may return an ArrayIterator. Other commands and operations may return a status array or a boolean, depending on the driver's write concern. Queries and some mapReduce commands will return an Iterator. @return Iterator|UpdateResult|InsertOneResult|DeleteResult|array|object|int|null
[ "Execute", "the", "query", "and", "return", "its", "result", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/Query.php#L403-L496
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php
QueryExpressionVisitor.walkComparison
public function walkComparison(Comparison $comparison) : Expr { switch ($comparison->getOperator()) { case Comparison::EQ: case Comparison::GT: case Comparison::GTE: case Comparison::IN: case Comparison::IS: case Comparison::LT: case Comparison::LTE: case Comparison::NEQ: case Comparison::NIN: $method = self::$operatorMethods[$comparison->getOperator()]; return $this->builder->expr() ->field($comparison->getField()) ->{$method}($this->walkValue($comparison->getValue())); case Comparison::CONTAINS: $value = $this->walkValue($comparison->getValue()); return $this->builder->expr() ->field($comparison->getField()) ->equals(new Regex($value, '')); default: throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator()); } }
php
public function walkComparison(Comparison $comparison) : Expr { switch ($comparison->getOperator()) { case Comparison::EQ: case Comparison::GT: case Comparison::GTE: case Comparison::IN: case Comparison::IS: case Comparison::LT: case Comparison::LTE: case Comparison::NEQ: case Comparison::NIN: $method = self::$operatorMethods[$comparison->getOperator()]; return $this->builder->expr() ->field($comparison->getField()) ->{$method}($this->walkValue($comparison->getValue())); case Comparison::CONTAINS: $value = $this->walkValue($comparison->getValue()); return $this->builder->expr() ->field($comparison->getField()) ->equals(new Regex($value, '')); default: throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator()); } }
[ "public", "function", "walkComparison", "(", "Comparison", "$", "comparison", ")", ":", "Expr", "{", "switch", "(", "$", "comparison", "->", "getOperator", "(", ")", ")", "{", "case", "Comparison", "::", "EQ", ":", "case", "Comparison", "::", "GT", ":", "case", "Comparison", "::", "GTE", ":", "case", "Comparison", "::", "IN", ":", "case", "Comparison", "::", "IS", ":", "case", "Comparison", "::", "LT", ":", "case", "Comparison", "::", "LTE", ":", "case", "Comparison", "::", "NEQ", ":", "case", "Comparison", "::", "NIN", ":", "$", "method", "=", "self", "::", "$", "operatorMethods", "[", "$", "comparison", "->", "getOperator", "(", ")", "]", ";", "return", "$", "this", "->", "builder", "->", "expr", "(", ")", "->", "field", "(", "$", "comparison", "->", "getField", "(", ")", ")", "->", "{", "$", "method", "}", "(", "$", "this", "->", "walkValue", "(", "$", "comparison", "->", "getValue", "(", ")", ")", ")", ";", "case", "Comparison", "::", "CONTAINS", ":", "$", "value", "=", "$", "this", "->", "walkValue", "(", "$", "comparison", "->", "getValue", "(", ")", ")", ";", "return", "$", "this", "->", "builder", "->", "expr", "(", ")", "->", "field", "(", "$", "comparison", "->", "getField", "(", ")", ")", "->", "equals", "(", "new", "Regex", "(", "$", "value", ",", "''", ")", ")", ";", "default", ":", "throw", "new", "RuntimeException", "(", "'Unknown comparison operator: '", ".", "$", "comparison", "->", "getOperator", "(", ")", ")", ";", "}", "}" ]
Converts a comparison expression into the target query language output. @see ExpressionVisitor::walkComparison()
[ "Converts", "a", "comparison", "expression", "into", "the", "target", "query", "language", "output", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php#L61-L89
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php
QueryExpressionVisitor.walkCompositeExpression
public function walkCompositeExpression(CompositeExpression $compositeExpr) : Expr { if (! isset(self::$compositeMethods[$compositeExpr->getType()])) { throw new RuntimeException('Unknown composite ' . $compositeExpr->getType()); } $method = self::$compositeMethods[$compositeExpr->getType()]; $expr = $this->builder->expr(); foreach ($compositeExpr->getExpressionList() as $child) { $expr->{$method}($this->dispatch($child)); } return $expr; }
php
public function walkCompositeExpression(CompositeExpression $compositeExpr) : Expr { if (! isset(self::$compositeMethods[$compositeExpr->getType()])) { throw new RuntimeException('Unknown composite ' . $compositeExpr->getType()); } $method = self::$compositeMethods[$compositeExpr->getType()]; $expr = $this->builder->expr(); foreach ($compositeExpr->getExpressionList() as $child) { $expr->{$method}($this->dispatch($child)); } return $expr; }
[ "public", "function", "walkCompositeExpression", "(", "CompositeExpression", "$", "compositeExpr", ")", ":", "Expr", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "compositeMethods", "[", "$", "compositeExpr", "->", "getType", "(", ")", "]", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'Unknown composite '", ".", "$", "compositeExpr", "->", "getType", "(", ")", ")", ";", "}", "$", "method", "=", "self", "::", "$", "compositeMethods", "[", "$", "compositeExpr", "->", "getType", "(", ")", "]", ";", "$", "expr", "=", "$", "this", "->", "builder", "->", "expr", "(", ")", ";", "foreach", "(", "$", "compositeExpr", "->", "getExpressionList", "(", ")", "as", "$", "child", ")", "{", "$", "expr", "->", "{", "$", "method", "}", "(", "$", "this", "->", "dispatch", "(", "$", "child", ")", ")", ";", "}", "return", "$", "expr", ";", "}" ]
Converts a composite expression into the target query language output. @see ExpressionVisitor::walkCompositeExpression()
[ "Converts", "a", "composite", "expression", "into", "the", "target", "query", "language", "output", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php#L96-L110
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php
Bucket.output
public function output() : Bucket\BucketOutput { if (! $this->output) { $this->output = new Bucket\BucketOutput($this->builder, $this); } assert($this->output instanceof Bucket\BucketOutput); return $this->output; }
php
public function output() : Bucket\BucketOutput { if (! $this->output) { $this->output = new Bucket\BucketOutput($this->builder, $this); } assert($this->output instanceof Bucket\BucketOutput); return $this->output; }
[ "public", "function", "output", "(", ")", ":", "Bucket", "\\", "BucketOutput", "{", "if", "(", "!", "$", "this", "->", "output", ")", "{", "$", "this", "->", "output", "=", "new", "Bucket", "\\", "BucketOutput", "(", "$", "this", "->", "builder", ",", "$", "this", ")", ";", "}", "assert", "(", "$", "this", "->", "output", "instanceof", "Bucket", "\\", "BucketOutput", ")", ";", "return", "$", "this", "->", "output", ";", "}" ]
A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions.
[ "A", "document", "that", "specifies", "the", "fields", "to", "include", "in", "the", "output", "documents", "in", "addition", "to", "the", "_id", "field", ".", "To", "specify", "the", "field", "to", "include", "you", "must", "use", "accumulator", "expressions", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php#L55-L63
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php
DocumentRepository.find
public function find($id, int $lockMode = LockMode::NONE, ?int $lockVersion = null) : ?object { if ($id === null) { return null; } /* TODO: What if the ID object has a field with the same name as the * class' mapped identifier field name? */ if (is_array($id)) { [$identifierFieldName] = $this->class->getIdentifierFieldNames(); if (isset($id[$identifierFieldName])) { $id = $id[$identifierFieldName]; } } // Check identity map first $document = $this->uow->tryGetById($id, $this->class); if ($document) { if ($lockMode !== LockMode::NONE) { $this->dm->lock($document, $lockMode, $lockVersion); } return $document; // Hit! } $criteria = ['_id' => $id]; if ($lockMode === LockMode::NONE) { return $this->getDocumentPersister()->load($criteria); } if ($lockMode === LockMode::OPTIMISTIC) { if (! $this->class->isVersioned) { throw LockException::notVersioned($this->documentName); } $document = $this->getDocumentPersister()->load($criteria); if ($document) { $this->uow->lock($document, $lockMode, $lockVersion); } return $document; } return $this->getDocumentPersister()->load($criteria, null, [], $lockMode); }
php
public function find($id, int $lockMode = LockMode::NONE, ?int $lockVersion = null) : ?object { if ($id === null) { return null; } if (is_array($id)) { [$identifierFieldName] = $this->class->getIdentifierFieldNames(); if (isset($id[$identifierFieldName])) { $id = $id[$identifierFieldName]; } } $document = $this->uow->tryGetById($id, $this->class); if ($document) { if ($lockMode !== LockMode::NONE) { $this->dm->lock($document, $lockMode, $lockVersion); } return $document; } $criteria = ['_id' => $id]; if ($lockMode === LockMode::NONE) { return $this->getDocumentPersister()->load($criteria); } if ($lockMode === LockMode::OPTIMISTIC) { if (! $this->class->isVersioned) { throw LockException::notVersioned($this->documentName); } $document = $this->getDocumentPersister()->load($criteria); if ($document) { $this->uow->lock($document, $lockMode, $lockVersion); } return $document; } return $this->getDocumentPersister()->load($criteria, null, [], $lockMode); }
[ "public", "function", "find", "(", "$", "id", ",", "int", "$", "lockMode", "=", "LockMode", "::", "NONE", ",", "?", "int", "$", "lockVersion", "=", "null", ")", ":", "?", "object", "{", "if", "(", "$", "id", "===", "null", ")", "{", "return", "null", ";", "}", "/* TODO: What if the ID object has a field with the same name as the\n * class' mapped identifier field name?\n */", "if", "(", "is_array", "(", "$", "id", ")", ")", "{", "[", "$", "identifierFieldName", "]", "=", "$", "this", "->", "class", "->", "getIdentifierFieldNames", "(", ")", ";", "if", "(", "isset", "(", "$", "id", "[", "$", "identifierFieldName", "]", ")", ")", "{", "$", "id", "=", "$", "id", "[", "$", "identifierFieldName", "]", ";", "}", "}", "// Check identity map first", "$", "document", "=", "$", "this", "->", "uow", "->", "tryGetById", "(", "$", "id", ",", "$", "this", "->", "class", ")", ";", "if", "(", "$", "document", ")", "{", "if", "(", "$", "lockMode", "!==", "LockMode", "::", "NONE", ")", "{", "$", "this", "->", "dm", "->", "lock", "(", "$", "document", ",", "$", "lockMode", ",", "$", "lockVersion", ")", ";", "}", "return", "$", "document", ";", "// Hit!", "}", "$", "criteria", "=", "[", "'_id'", "=>", "$", "id", "]", ";", "if", "(", "$", "lockMode", "===", "LockMode", "::", "NONE", ")", "{", "return", "$", "this", "->", "getDocumentPersister", "(", ")", "->", "load", "(", "$", "criteria", ")", ";", "}", "if", "(", "$", "lockMode", "===", "LockMode", "::", "OPTIMISTIC", ")", "{", "if", "(", "!", "$", "this", "->", "class", "->", "isVersioned", ")", "{", "throw", "LockException", "::", "notVersioned", "(", "$", "this", "->", "documentName", ")", ";", "}", "$", "document", "=", "$", "this", "->", "getDocumentPersister", "(", ")", "->", "load", "(", "$", "criteria", ")", ";", "if", "(", "$", "document", ")", "{", "$", "this", "->", "uow", "->", "lock", "(", "$", "document", ",", "$", "lockMode", ",", "$", "lockVersion", ")", ";", "}", "return", "$", "document", ";", "}", "return", "$", "this", "->", "getDocumentPersister", "(", ")", "->", "load", "(", "$", "criteria", ",", "null", ",", "[", "]", ",", "$", "lockMode", ")", ";", "}" ]
Finds a document matching the specified identifier. Optionally a lock mode and expected version may be specified. @param mixed $id Identifier. @throws MappingException @throws LockException
[ "Finds", "a", "document", "matching", "the", "specified", "identifier", ".", "Optionally", "a", "lock", "mode", "and", "expected", "version", "may", "be", "specified", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php#L96-L143
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php
DocumentRepository.findBy
public function findBy(array $criteria, ?array $sort = null, $limit = null, $skip = null) : array { return $this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip)->toArray(); }
php
public function findBy(array $criteria, ?array $sort = null, $limit = null, $skip = null) : array { return $this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip)->toArray(); }
[ "public", "function", "findBy", "(", "array", "$", "criteria", ",", "?", "array", "$", "sort", "=", "null", ",", "$", "limit", "=", "null", ",", "$", "skip", "=", "null", ")", ":", "array", "{", "return", "$", "this", "->", "getDocumentPersister", "(", ")", "->", "loadAll", "(", "$", "criteria", ",", "$", "sort", ",", "$", "limit", ",", "$", "skip", ")", "->", "toArray", "(", ")", ";", "}" ]
Finds documents by a set of criteria. @param int|null $limit @param int|null $skip
[ "Finds", "documents", "by", "a", "set", "of", "criteria", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php#L159-L162
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getPersistenceBuilder
public function getPersistenceBuilder() : PersistenceBuilder { if (! $this->persistenceBuilder) { $this->persistenceBuilder = new PersistenceBuilder($this->dm, $this); } return $this->persistenceBuilder; }
php
public function getPersistenceBuilder() : PersistenceBuilder { if (! $this->persistenceBuilder) { $this->persistenceBuilder = new PersistenceBuilder($this->dm, $this); } return $this->persistenceBuilder; }
[ "public", "function", "getPersistenceBuilder", "(", ")", ":", "PersistenceBuilder", "{", "if", "(", "!", "$", "this", "->", "persistenceBuilder", ")", "{", "$", "this", "->", "persistenceBuilder", "=", "new", "PersistenceBuilder", "(", "$", "this", "->", "dm", ",", "$", "this", ")", ";", "}", "return", "$", "this", "->", "persistenceBuilder", ";", "}" ]
Factory for returning new PersistenceBuilder instances used for preparing data into queries for insert persistence. @internal
[ "Factory", "for", "returning", "new", "PersistenceBuilder", "instances", "used", "for", "preparing", "data", "into", "queries", "for", "insert", "persistence", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L281-L287
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.setParentAssociation
public function setParentAssociation(object $document, array $mapping, ?object $parent, string $propertyPath) : void { $oid = spl_object_hash($document); $this->embeddedDocumentsRegistry[$oid] = $document; $this->parentAssociations[$oid] = [$mapping, $parent, $propertyPath]; }
php
public function setParentAssociation(object $document, array $mapping, ?object $parent, string $propertyPath) : void { $oid = spl_object_hash($document); $this->embeddedDocumentsRegistry[$oid] = $document; $this->parentAssociations[$oid] = [$mapping, $parent, $propertyPath]; }
[ "public", "function", "setParentAssociation", "(", "object", "$", "document", ",", "array", "$", "mapping", ",", "?", "object", "$", "parent", ",", "string", "$", "propertyPath", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "$", "this", "->", "embeddedDocumentsRegistry", "[", "$", "oid", "]", "=", "$", "document", ";", "$", "this", "->", "parentAssociations", "[", "$", "oid", "]", "=", "[", "$", "mapping", ",", "$", "parent", ",", "$", "propertyPath", "]", ";", "}" ]
Sets the parent association for a given embedded document. @internal
[ "Sets", "the", "parent", "association", "for", "a", "given", "embedded", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L294-L299
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getParentAssociation
public function getParentAssociation(object $document) : ?array { $oid = spl_object_hash($document); return $this->parentAssociations[$oid] ?? null; }
php
public function getParentAssociation(object $document) : ?array { $oid = spl_object_hash($document); return $this->parentAssociations[$oid] ?? null; }
[ "public", "function", "getParentAssociation", "(", "object", "$", "document", ")", ":", "?", "array", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "return", "$", "this", "->", "parentAssociations", "[", "$", "oid", "]", "??", "null", ";", "}" ]
Gets the parent association for a given embedded document. <code> list($mapping, $parent, $propertyPath) = $this->getParentAssociation($embeddedDocument); </code>
[ "Gets", "the", "parent", "association", "for", "a", "given", "embedded", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L308-L313
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getDocumentPersister
public function getDocumentPersister(string $documentName) : Persisters\DocumentPersister { if (! isset($this->persisters[$documentName])) { $class = $this->dm->getClassMetadata($documentName); $pb = $this->getPersistenceBuilder(); $this->persisters[$documentName] = new Persisters\DocumentPersister($pb, $this->dm, $this, $this->hydratorFactory, $class); } return $this->persisters[$documentName]; }
php
public function getDocumentPersister(string $documentName) : Persisters\DocumentPersister { if (! isset($this->persisters[$documentName])) { $class = $this->dm->getClassMetadata($documentName); $pb = $this->getPersistenceBuilder(); $this->persisters[$documentName] = new Persisters\DocumentPersister($pb, $this->dm, $this, $this->hydratorFactory, $class); } return $this->persisters[$documentName]; }
[ "public", "function", "getDocumentPersister", "(", "string", "$", "documentName", ")", ":", "Persisters", "\\", "DocumentPersister", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "persisters", "[", "$", "documentName", "]", ")", ")", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "documentName", ")", ";", "$", "pb", "=", "$", "this", "->", "getPersistenceBuilder", "(", ")", ";", "$", "this", "->", "persisters", "[", "$", "documentName", "]", "=", "new", "Persisters", "\\", "DocumentPersister", "(", "$", "pb", ",", "$", "this", "->", "dm", ",", "$", "this", ",", "$", "this", "->", "hydratorFactory", ",", "$", "class", ")", ";", "}", "return", "$", "this", "->", "persisters", "[", "$", "documentName", "]", ";", "}" ]
Get the document persister instance for the given document name
[ "Get", "the", "document", "persister", "instance", "for", "the", "given", "document", "name" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L318-L326
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getCollectionPersister
public function getCollectionPersister() : CollectionPersister { if (! isset($this->collectionPersister)) { $pb = $this->getPersistenceBuilder(); $this->collectionPersister = new Persisters\CollectionPersister($this->dm, $pb, $this); } return $this->collectionPersister; }
php
public function getCollectionPersister() : CollectionPersister { if (! isset($this->collectionPersister)) { $pb = $this->getPersistenceBuilder(); $this->collectionPersister = new Persisters\CollectionPersister($this->dm, $pb, $this); } return $this->collectionPersister; }
[ "public", "function", "getCollectionPersister", "(", ")", ":", "CollectionPersister", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "collectionPersister", ")", ")", "{", "$", "pb", "=", "$", "this", "->", "getPersistenceBuilder", "(", ")", ";", "$", "this", "->", "collectionPersister", "=", "new", "Persisters", "\\", "CollectionPersister", "(", "$", "this", "->", "dm", ",", "$", "pb", ",", "$", "this", ")", ";", "}", "return", "$", "this", "->", "collectionPersister", ";", "}" ]
Get the collection persister instance.
[ "Get", "the", "collection", "persister", "instance", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L331-L338
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.setDocumentPersister
public function setDocumentPersister(string $documentName, Persisters\DocumentPersister $persister) : void { $this->persisters[$documentName] = $persister; }
php
public function setDocumentPersister(string $documentName, Persisters\DocumentPersister $persister) : void { $this->persisters[$documentName] = $persister; }
[ "public", "function", "setDocumentPersister", "(", "string", "$", "documentName", ",", "Persisters", "\\", "DocumentPersister", "$", "persister", ")", ":", "void", "{", "$", "this", "->", "persisters", "[", "$", "documentName", "]", "=", "$", "persister", ";", "}" ]
Set the document persister instance to use for the given document name @internal
[ "Set", "the", "document", "persister", "instance", "to", "use", "for", "the", "given", "document", "name" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L345-L348
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.commit
public function commit(array $options = []) : void { // Raise preFlush if ($this->evm->hasListeners(Events::preFlush)) { $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm)); } // Compute changes done since last commit. $this->computeChangeSets(); if (! ($this->documentInsertions || $this->documentUpserts || $this->documentDeletions || $this->documentUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals) ) { return; // Nothing to do. } $this->commitsInProgress++; if ($this->commitsInProgress > 1) { throw MongoDBException::commitInProgress(); } try { if ($this->orphanRemovals) { foreach ($this->orphanRemovals as $removal) { $this->remove($removal); } } // Raise onFlush if ($this->evm->hasListeners(Events::onFlush)) { $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm)); } foreach ($this->getClassesForCommitAction($this->documentUpserts) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeUpserts($class, $documents, $options); } foreach ($this->getClassesForCommitAction($this->documentInsertions) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeInserts($class, $documents, $options); } foreach ($this->getClassesForCommitAction($this->documentUpdates) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeUpdates($class, $documents, $options); } foreach ($this->getClassesForCommitAction($this->documentDeletions, true) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeDeletions($class, $documents, $options); } // Raise postFlush if ($this->evm->hasListeners(Events::postFlush)) { $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm)); } // Clear up $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->documentChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForSynchronization = $this->orphanRemovals = $this->hasScheduledCollections = []; } finally { $this->commitsInProgress--; } }
php
public function commit(array $options = []) : void { if ($this->evm->hasListeners(Events::preFlush)) { $this->evm->dispatchEvent(Events::preFlush, new Event\PreFlushEventArgs($this->dm)); } $this->computeChangeSets(); if (! ($this->documentInsertions || $this->documentUpserts || $this->documentDeletions || $this->documentUpdates || $this->collectionUpdates || $this->collectionDeletions || $this->orphanRemovals) ) { return; } $this->commitsInProgress++; if ($this->commitsInProgress > 1) { throw MongoDBException::commitInProgress(); } try { if ($this->orphanRemovals) { foreach ($this->orphanRemovals as $removal) { $this->remove($removal); } } if ($this->evm->hasListeners(Events::onFlush)) { $this->evm->dispatchEvent(Events::onFlush, new Event\OnFlushEventArgs($this->dm)); } foreach ($this->getClassesForCommitAction($this->documentUpserts) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeUpserts($class, $documents, $options); } foreach ($this->getClassesForCommitAction($this->documentInsertions) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeInserts($class, $documents, $options); } foreach ($this->getClassesForCommitAction($this->documentUpdates) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeUpdates($class, $documents, $options); } foreach ($this->getClassesForCommitAction($this->documentDeletions, true) as $classAndDocuments) { [$class, $documents] = $classAndDocuments; $this->executeDeletions($class, $documents, $options); } if ($this->evm->hasListeners(Events::postFlush)) { $this->evm->dispatchEvent(Events::postFlush, new Event\PostFlushEventArgs($this->dm)); } $this->documentInsertions = $this->documentUpserts = $this->documentUpdates = $this->documentDeletions = $this->documentChangeSets = $this->collectionUpdates = $this->collectionDeletions = $this->visitedCollections = $this->scheduledForSynchronization = $this->orphanRemovals = $this->hasScheduledCollections = []; } finally { $this->commitsInProgress--; } }
[ "public", "function", "commit", "(", "array", "$", "options", "=", "[", "]", ")", ":", "void", "{", "// Raise preFlush", "if", "(", "$", "this", "->", "evm", "->", "hasListeners", "(", "Events", "::", "preFlush", ")", ")", "{", "$", "this", "->", "evm", "->", "dispatchEvent", "(", "Events", "::", "preFlush", ",", "new", "Event", "\\", "PreFlushEventArgs", "(", "$", "this", "->", "dm", ")", ")", ";", "}", "// Compute changes done since last commit.", "$", "this", "->", "computeChangeSets", "(", ")", ";", "if", "(", "!", "(", "$", "this", "->", "documentInsertions", "||", "$", "this", "->", "documentUpserts", "||", "$", "this", "->", "documentDeletions", "||", "$", "this", "->", "documentUpdates", "||", "$", "this", "->", "collectionUpdates", "||", "$", "this", "->", "collectionDeletions", "||", "$", "this", "->", "orphanRemovals", ")", ")", "{", "return", ";", "// Nothing to do.", "}", "$", "this", "->", "commitsInProgress", "++", ";", "if", "(", "$", "this", "->", "commitsInProgress", ">", "1", ")", "{", "throw", "MongoDBException", "::", "commitInProgress", "(", ")", ";", "}", "try", "{", "if", "(", "$", "this", "->", "orphanRemovals", ")", "{", "foreach", "(", "$", "this", "->", "orphanRemovals", "as", "$", "removal", ")", "{", "$", "this", "->", "remove", "(", "$", "removal", ")", ";", "}", "}", "// Raise onFlush", "if", "(", "$", "this", "->", "evm", "->", "hasListeners", "(", "Events", "::", "onFlush", ")", ")", "{", "$", "this", "->", "evm", "->", "dispatchEvent", "(", "Events", "::", "onFlush", ",", "new", "Event", "\\", "OnFlushEventArgs", "(", "$", "this", "->", "dm", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "getClassesForCommitAction", "(", "$", "this", "->", "documentUpserts", ")", "as", "$", "classAndDocuments", ")", "{", "[", "$", "class", ",", "$", "documents", "]", "=", "$", "classAndDocuments", ";", "$", "this", "->", "executeUpserts", "(", "$", "class", ",", "$", "documents", ",", "$", "options", ")", ";", "}", "foreach", "(", "$", "this", "->", "getClassesForCommitAction", "(", "$", "this", "->", "documentInsertions", ")", "as", "$", "classAndDocuments", ")", "{", "[", "$", "class", ",", "$", "documents", "]", "=", "$", "classAndDocuments", ";", "$", "this", "->", "executeInserts", "(", "$", "class", ",", "$", "documents", ",", "$", "options", ")", ";", "}", "foreach", "(", "$", "this", "->", "getClassesForCommitAction", "(", "$", "this", "->", "documentUpdates", ")", "as", "$", "classAndDocuments", ")", "{", "[", "$", "class", ",", "$", "documents", "]", "=", "$", "classAndDocuments", ";", "$", "this", "->", "executeUpdates", "(", "$", "class", ",", "$", "documents", ",", "$", "options", ")", ";", "}", "foreach", "(", "$", "this", "->", "getClassesForCommitAction", "(", "$", "this", "->", "documentDeletions", ",", "true", ")", "as", "$", "classAndDocuments", ")", "{", "[", "$", "class", ",", "$", "documents", "]", "=", "$", "classAndDocuments", ";", "$", "this", "->", "executeDeletions", "(", "$", "class", ",", "$", "documents", ",", "$", "options", ")", ";", "}", "// Raise postFlush", "if", "(", "$", "this", "->", "evm", "->", "hasListeners", "(", "Events", "::", "postFlush", ")", ")", "{", "$", "this", "->", "evm", "->", "dispatchEvent", "(", "Events", "::", "postFlush", ",", "new", "Event", "\\", "PostFlushEventArgs", "(", "$", "this", "->", "dm", ")", ")", ";", "}", "// Clear up", "$", "this", "->", "documentInsertions", "=", "$", "this", "->", "documentUpserts", "=", "$", "this", "->", "documentUpdates", "=", "$", "this", "->", "documentDeletions", "=", "$", "this", "->", "documentChangeSets", "=", "$", "this", "->", "collectionUpdates", "=", "$", "this", "->", "collectionDeletions", "=", "$", "this", "->", "visitedCollections", "=", "$", "this", "->", "scheduledForSynchronization", "=", "$", "this", "->", "orphanRemovals", "=", "$", "this", "->", "hasScheduledCollections", "=", "[", "]", ";", "}", "finally", "{", "$", "this", "->", "commitsInProgress", "--", ";", "}", "}" ]
Commits the UnitOfWork, executing all operations that have been postponed up to this point. The state of all managed documents will be synchronized with the database. The operations are executed in the following order: 1) All document insertions 2) All document updates 3) All document deletions @param array $options Array of options to be used with batchInsert(), update() and remove()
[ "Commits", "the", "UnitOfWork", "executing", "all", "operations", "that", "have", "been", "postponed", "up", "to", "this", "point", ".", "The", "state", "of", "all", "managed", "documents", "will", "be", "synchronized", "with", "the", "database", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L363-L440
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getClassesForCommitAction
private function getClassesForCommitAction(array $documents, bool $includeEmbedded = false) : array { if (empty($documents)) { return []; } $divided = []; $embeds = []; foreach ($documents as $oid => $d) { $className = get_class($d); if (isset($embeds[$className])) { continue; } if (isset($divided[$className])) { $divided[$className][1][$oid] = $d; continue; } $class = $this->dm->getClassMetadata($className); if ($class->isEmbeddedDocument && ! $includeEmbedded) { $embeds[$className] = true; continue; } if (empty($divided[$class->name])) { $divided[$class->name] = [$class, [$oid => $d]]; } else { $divided[$class->name][1][$oid] = $d; } } return $divided; }
php
private function getClassesForCommitAction(array $documents, bool $includeEmbedded = false) : array { if (empty($documents)) { return []; } $divided = []; $embeds = []; foreach ($documents as $oid => $d) { $className = get_class($d); if (isset($embeds[$className])) { continue; } if (isset($divided[$className])) { $divided[$className][1][$oid] = $d; continue; } $class = $this->dm->getClassMetadata($className); if ($class->isEmbeddedDocument && ! $includeEmbedded) { $embeds[$className] = true; continue; } if (empty($divided[$class->name])) { $divided[$class->name] = [$class, [$oid => $d]]; } else { $divided[$class->name][1][$oid] = $d; } } return $divided; }
[ "private", "function", "getClassesForCommitAction", "(", "array", "$", "documents", ",", "bool", "$", "includeEmbedded", "=", "false", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "documents", ")", ")", "{", "return", "[", "]", ";", "}", "$", "divided", "=", "[", "]", ";", "$", "embeds", "=", "[", "]", ";", "foreach", "(", "$", "documents", "as", "$", "oid", "=>", "$", "d", ")", "{", "$", "className", "=", "get_class", "(", "$", "d", ")", ";", "if", "(", "isset", "(", "$", "embeds", "[", "$", "className", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "isset", "(", "$", "divided", "[", "$", "className", "]", ")", ")", "{", "$", "divided", "[", "$", "className", "]", "[", "1", "]", "[", "$", "oid", "]", "=", "$", "d", ";", "continue", ";", "}", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "className", ")", ";", "if", "(", "$", "class", "->", "isEmbeddedDocument", "&&", "!", "$", "includeEmbedded", ")", "{", "$", "embeds", "[", "$", "className", "]", "=", "true", ";", "continue", ";", "}", "if", "(", "empty", "(", "$", "divided", "[", "$", "class", "->", "name", "]", ")", ")", "{", "$", "divided", "[", "$", "class", "->", "name", "]", "=", "[", "$", "class", ",", "[", "$", "oid", "=>", "$", "d", "]", "]", ";", "}", "else", "{", "$", "divided", "[", "$", "class", "->", "name", "]", "[", "1", "]", "[", "$", "oid", "]", "=", "$", "d", ";", "}", "}", "return", "$", "divided", ";", "}" ]
Groups a list of scheduled documents by their class.
[ "Groups", "a", "list", "of", "scheduled", "documents", "by", "their", "class", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L445-L473
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.computeScheduleInsertsChangeSets
private function computeScheduleInsertsChangeSets() : void { foreach ($this->documentInsertions as $document) { $class = $this->dm->getClassMetadata(get_class($document)); if ($class->isEmbeddedDocument) { continue; } $this->computeChangeSet($class, $document); } }
php
private function computeScheduleInsertsChangeSets() : void { foreach ($this->documentInsertions as $document) { $class = $this->dm->getClassMetadata(get_class($document)); if ($class->isEmbeddedDocument) { continue; } $this->computeChangeSet($class, $document); } }
[ "private", "function", "computeScheduleInsertsChangeSets", "(", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "documentInsertions", "as", "$", "document", ")", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "if", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "continue", ";", "}", "$", "this", "->", "computeChangeSet", "(", "$", "class", ",", "$", "document", ")", ";", "}", "}" ]
Compute changesets of all documents scheduled for insertion. Embedded documents will not be processed.
[ "Compute", "changesets", "of", "all", "documents", "scheduled", "for", "insertion", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L480-L490
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.computeScheduleUpsertsChangeSets
private function computeScheduleUpsertsChangeSets() : void { foreach ($this->documentUpserts as $document) { $class = $this->dm->getClassMetadata(get_class($document)); if ($class->isEmbeddedDocument) { continue; } $this->computeChangeSet($class, $document); } }
php
private function computeScheduleUpsertsChangeSets() : void { foreach ($this->documentUpserts as $document) { $class = $this->dm->getClassMetadata(get_class($document)); if ($class->isEmbeddedDocument) { continue; } $this->computeChangeSet($class, $document); } }
[ "private", "function", "computeScheduleUpsertsChangeSets", "(", ")", ":", "void", "{", "foreach", "(", "$", "this", "->", "documentUpserts", "as", "$", "document", ")", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "if", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "continue", ";", "}", "$", "this", "->", "computeChangeSet", "(", "$", "class", ",", "$", "document", ")", ";", "}", "}" ]
Compute changesets of all documents scheduled for upsert. Embedded documents will not be processed.
[ "Compute", "changesets", "of", "all", "documents", "scheduled", "for", "upsert", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L497-L507
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.setDocumentChangeSet
public function setDocumentChangeSet(object $document, array $changeset) : void { $this->documentChangeSets[spl_object_hash($document)] = $changeset; }
php
public function setDocumentChangeSet(object $document, array $changeset) : void { $this->documentChangeSets[spl_object_hash($document)] = $changeset; }
[ "public", "function", "setDocumentChangeSet", "(", "object", "$", "document", ",", "array", "$", "changeset", ")", ":", "void", "{", "$", "this", "->", "documentChangeSets", "[", "spl_object_hash", "(", "$", "document", ")", "]", "=", "$", "changeset", ";", "}" ]
Sets the changeset for a document. @internal
[ "Sets", "the", "changeset", "for", "a", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L526-L529
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getDocumentActualData
public function getDocumentActualData(object $document) : array { $class = $this->dm->getClassMetadata(get_class($document)); $actualData = []; foreach ($class->reflFields as $name => $refProp) { $mapping = $class->fieldMappings[$name]; // skip not saved fields if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) { continue; } $value = $refProp->getValue($document); if ((isset($mapping['association']) && $mapping['type'] === 'many') && $value !== null && ! ($value instanceof PersistentCollectionInterface)) { // If $actualData[$name] is not a Collection then use an ArrayCollection. if (! $value instanceof Collection) { $value = new ArrayCollection($value); } // Inject PersistentCollection $coll = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $mapping, $value); $coll->setOwner($document, $mapping); $coll->setDirty(! $value->isEmpty()); $class->reflFields[$name]->setValue($document, $coll); $actualData[$name] = $coll; } else { $actualData[$name] = $value; } } return $actualData; }
php
public function getDocumentActualData(object $document) : array { $class = $this->dm->getClassMetadata(get_class($document)); $actualData = []; foreach ($class->reflFields as $name => $refProp) { $mapping = $class->fieldMappings[$name]; if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) { continue; } $value = $refProp->getValue($document); if ((isset($mapping['association']) && $mapping['type'] === 'many') && $value !== null && ! ($value instanceof PersistentCollectionInterface)) { if (! $value instanceof Collection) { $value = new ArrayCollection($value); } $coll = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $mapping, $value); $coll->setOwner($document, $mapping); $coll->setDirty(! $value->isEmpty()); $class->reflFields[$name]->setValue($document, $coll); $actualData[$name] = $coll; } else { $actualData[$name] = $value; } } return $actualData; }
[ "public", "function", "getDocumentActualData", "(", "object", "$", "document", ")", ":", "array", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "actualData", "=", "[", "]", ";", "foreach", "(", "$", "class", "->", "reflFields", "as", "$", "name", "=>", "$", "refProp", ")", "{", "$", "mapping", "=", "$", "class", "->", "fieldMappings", "[", "$", "name", "]", ";", "// skip not saved fields", "if", "(", "isset", "(", "$", "mapping", "[", "'notSaved'", "]", ")", "&&", "$", "mapping", "[", "'notSaved'", "]", "===", "true", ")", "{", "continue", ";", "}", "$", "value", "=", "$", "refProp", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "(", "isset", "(", "$", "mapping", "[", "'association'", "]", ")", "&&", "$", "mapping", "[", "'type'", "]", "===", "'many'", ")", "&&", "$", "value", "!==", "null", "&&", "!", "(", "$", "value", "instanceof", "PersistentCollectionInterface", ")", ")", "{", "// If $actualData[$name] is not a Collection then use an ArrayCollection.", "if", "(", "!", "$", "value", "instanceof", "Collection", ")", "{", "$", "value", "=", "new", "ArrayCollection", "(", "$", "value", ")", ";", "}", "// Inject PersistentCollection", "$", "coll", "=", "$", "this", "->", "dm", "->", "getConfiguration", "(", ")", "->", "getPersistentCollectionFactory", "(", ")", "->", "create", "(", "$", "this", "->", "dm", ",", "$", "mapping", ",", "$", "value", ")", ";", "$", "coll", "->", "setOwner", "(", "$", "document", ",", "$", "mapping", ")", ";", "$", "coll", "->", "setDirty", "(", "!", "$", "value", "->", "isEmpty", "(", ")", ")", ";", "$", "class", "->", "reflFields", "[", "$", "name", "]", "->", "setValue", "(", "$", "document", ",", "$", "coll", ")", ";", "$", "actualData", "[", "$", "name", "]", "=", "$", "coll", ";", "}", "else", "{", "$", "actualData", "[", "$", "name", "]", "=", "$", "value", ";", "}", "}", "return", "$", "actualData", ";", "}" ]
Get a documents actual data, flattening all the objects to arrays. @internal @return array
[ "Get", "a", "documents", "actual", "data", "flattening", "all", "the", "objects", "to", "arrays", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L538-L567
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.computeOrRecomputeChangeSet
private function computeOrRecomputeChangeSet(ClassMetadata $class, object $document, bool $recompute = false) : void { $oid = spl_object_hash($document); $actualData = $this->getDocumentActualData($document); $isNewDocument = ! isset($this->originalDocumentData[$oid]); if ($isNewDocument) { // Document is either NEW or MANAGED but not yet fully persisted (only has an id). // These result in an INSERT. $this->originalDocumentData[$oid] = $actualData; $changeSet = []; foreach ($actualData as $propName => $actualValue) { /* At this PersistentCollection shouldn't be here, probably it * was cloned and its ownership must be fixed */ if ($actualValue instanceof PersistentCollectionInterface && $actualValue->getOwner() !== $document) { $actualData[$propName] = $this->fixPersistentCollectionOwnership($actualValue, $document, $class, $propName); $actualValue = $actualData[$propName]; } // ignore inverse side of reference relationship if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['isInverseSide']) { continue; } $changeSet[$propName] = [null, $actualValue]; } $this->documentChangeSets[$oid] = $changeSet; } else { if ($class->isReadOnly) { return; } // Document is "fully" MANAGED: it was already fully persisted before // and we have a copy of the original data $originalData = $this->originalDocumentData[$oid]; $isChangeTrackingNotify = $class->isChangeTrackingNotify(); if ($isChangeTrackingNotify && ! $recompute && isset($this->documentChangeSets[$oid])) { $changeSet = $this->documentChangeSets[$oid]; } else { $changeSet = []; } $gridFSMetadataProperty = null; if ($class->isFile) { try { $gridFSMetadata = $class->getFieldMappingByDbFieldName('metadata'); $gridFSMetadataProperty = $gridFSMetadata['fieldName']; } catch (MappingException $e) { } } foreach ($actualData as $propName => $actualValue) { // skip not saved fields if ((isset($class->fieldMappings[$propName]['notSaved']) && $class->fieldMappings[$propName]['notSaved'] === true) || ($class->isFile && $propName !== $gridFSMetadataProperty)) { continue; } $orgValue = $originalData[$propName] ?? null; // skip if value has not changed if ($orgValue === $actualValue) { if (! $actualValue instanceof PersistentCollectionInterface) { continue; } if (! $actualValue->isDirty() && ! $this->isCollectionScheduledForDeletion($actualValue)) { // consider dirty collections as changed as well continue; } } // if relationship is a embed-one, schedule orphan removal to trigger cascade remove operations if (isset($class->fieldMappings[$propName]['embedded']) && $class->fieldMappings[$propName]['type'] === 'one') { if ($orgValue !== null) { $this->scheduleOrphanRemoval($orgValue); } $changeSet[$propName] = [$orgValue, $actualValue]; continue; } // if owning side of reference-one relationship if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['type'] === 'one' && $class->fieldMappings[$propName]['isOwningSide']) { if ($orgValue !== null && $class->fieldMappings[$propName]['orphanRemoval']) { $this->scheduleOrphanRemoval($orgValue); } $changeSet[$propName] = [$orgValue, $actualValue]; continue; } if ($isChangeTrackingNotify) { continue; } // ignore inverse side of reference relationship if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['isInverseSide']) { continue; } // Persistent collection was exchanged with the "originally" // created one. This can only mean it was cloned and replaced // on another document. if ($actualValue instanceof PersistentCollectionInterface && $actualValue->getOwner() !== $document) { $actualValue = $this->fixPersistentCollectionOwnership($actualValue, $document, $class, $propName); } // if embed-many or reference-many relationship if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'many') { $changeSet[$propName] = [$orgValue, $actualValue]; /* If original collection was exchanged with a non-empty value * and $set will be issued, there is no need to $unset it first */ if ($actualValue && $actualValue->isDirty() && CollectionHelper::usesSet($class->fieldMappings[$propName]['strategy'])) { continue; } if ($orgValue !== $actualValue && $orgValue instanceof PersistentCollectionInterface) { $this->scheduleCollectionDeletion($orgValue); } continue; } // skip equivalent date values if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'date') { /** @var DateType $dateType */ $dateType = Type::getType('date'); $dbOrgValue = $dateType->convertToDatabaseValue($orgValue); $dbActualValue = $dateType->convertToDatabaseValue($actualValue); $orgTimestamp = $dbOrgValue instanceof UTCDateTime ? $dbOrgValue->toDateTime()->getTimestamp() : null; $actualTimestamp = $dbActualValue instanceof UTCDateTime ? $dbActualValue->toDateTime()->getTimestamp() : null; if ($orgTimestamp === $actualTimestamp) { continue; } } // regular field $changeSet[$propName] = [$orgValue, $actualValue]; } if ($changeSet) { $this->documentChangeSets[$oid] = isset($this->documentChangeSets[$oid]) ? $changeSet + $this->documentChangeSets[$oid] : $changeSet; $this->originalDocumentData[$oid] = $actualData; $this->scheduleForUpdate($document); } } // Look for changes in associations of the document $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return empty($assoc['notSaved']); } ); foreach ($associationMappings as $mapping) { $value = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($value === null) { continue; } $this->computeAssociationChanges($document, $mapping, $value); if (isset($mapping['reference'])) { continue; } $values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value->unwrap(); foreach ($values as $obj) { $oid2 = spl_object_hash($obj); if (isset($this->documentChangeSets[$oid2])) { if (empty($this->documentChangeSets[$oid][$mapping['fieldName']])) { // instance of $value is the same as it was previously otherwise there would be // change set already in place $this->documentChangeSets[$oid][$mapping['fieldName']] = [$value, $value]; } if (! $isNewDocument) { $this->scheduleForUpdate($document); } break; } } } }
php
private function computeOrRecomputeChangeSet(ClassMetadata $class, object $document, bool $recompute = false) : void { $oid = spl_object_hash($document); $actualData = $this->getDocumentActualData($document); $isNewDocument = ! isset($this->originalDocumentData[$oid]); if ($isNewDocument) { $this->originalDocumentData[$oid] = $actualData; $changeSet = []; foreach ($actualData as $propName => $actualValue) { if ($actualValue instanceof PersistentCollectionInterface && $actualValue->getOwner() !== $document) { $actualData[$propName] = $this->fixPersistentCollectionOwnership($actualValue, $document, $class, $propName); $actualValue = $actualData[$propName]; } if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['isInverseSide']) { continue; } $changeSet[$propName] = [null, $actualValue]; } $this->documentChangeSets[$oid] = $changeSet; } else { if ($class->isReadOnly) { return; } $originalData = $this->originalDocumentData[$oid]; $isChangeTrackingNotify = $class->isChangeTrackingNotify(); if ($isChangeTrackingNotify && ! $recompute && isset($this->documentChangeSets[$oid])) { $changeSet = $this->documentChangeSets[$oid]; } else { $changeSet = []; } $gridFSMetadataProperty = null; if ($class->isFile) { try { $gridFSMetadata = $class->getFieldMappingByDbFieldName('metadata'); $gridFSMetadataProperty = $gridFSMetadata['fieldName']; } catch (MappingException $e) { } } foreach ($actualData as $propName => $actualValue) { if ((isset($class->fieldMappings[$propName]['notSaved']) && $class->fieldMappings[$propName]['notSaved'] === true) || ($class->isFile && $propName !== $gridFSMetadataProperty)) { continue; } $orgValue = $originalData[$propName] ?? null; if ($orgValue === $actualValue) { if (! $actualValue instanceof PersistentCollectionInterface) { continue; } if (! $actualValue->isDirty() && ! $this->isCollectionScheduledForDeletion($actualValue)) { continue; } } if (isset($class->fieldMappings[$propName]['embedded']) && $class->fieldMappings[$propName]['type'] === 'one') { if ($orgValue !== null) { $this->scheduleOrphanRemoval($orgValue); } $changeSet[$propName] = [$orgValue, $actualValue]; continue; } if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['type'] === 'one' && $class->fieldMappings[$propName]['isOwningSide']) { if ($orgValue !== null && $class->fieldMappings[$propName]['orphanRemoval']) { $this->scheduleOrphanRemoval($orgValue); } $changeSet[$propName] = [$orgValue, $actualValue]; continue; } if ($isChangeTrackingNotify) { continue; } if (isset($class->fieldMappings[$propName]['reference']) && $class->fieldMappings[$propName]['isInverseSide']) { continue; } if ($actualValue instanceof PersistentCollectionInterface && $actualValue->getOwner() !== $document) { $actualValue = $this->fixPersistentCollectionOwnership($actualValue, $document, $class, $propName); } if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'many') { $changeSet[$propName] = [$orgValue, $actualValue]; if ($actualValue && $actualValue->isDirty() && CollectionHelper::usesSet($class->fieldMappings[$propName]['strategy'])) { continue; } if ($orgValue !== $actualValue && $orgValue instanceof PersistentCollectionInterface) { $this->scheduleCollectionDeletion($orgValue); } continue; } if (isset($class->fieldMappings[$propName]['type']) && $class->fieldMappings[$propName]['type'] === 'date') { $dateType = Type::getType('date'); $dbOrgValue = $dateType->convertToDatabaseValue($orgValue); $dbActualValue = $dateType->convertToDatabaseValue($actualValue); $orgTimestamp = $dbOrgValue instanceof UTCDateTime ? $dbOrgValue->toDateTime()->getTimestamp() : null; $actualTimestamp = $dbActualValue instanceof UTCDateTime ? $dbActualValue->toDateTime()->getTimestamp() : null; if ($orgTimestamp === $actualTimestamp) { continue; } } $changeSet[$propName] = [$orgValue, $actualValue]; } if ($changeSet) { $this->documentChangeSets[$oid] = isset($this->documentChangeSets[$oid]) ? $changeSet + $this->documentChangeSets[$oid] : $changeSet; $this->originalDocumentData[$oid] = $actualData; $this->scheduleForUpdate($document); } } $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return empty($assoc['notSaved']); } ); foreach ($associationMappings as $mapping) { $value = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($value === null) { continue; } $this->computeAssociationChanges($document, $mapping, $value); if (isset($mapping['reference'])) { continue; } $values = $mapping['type'] === ClassMetadata::ONE ? [$value] : $value->unwrap(); foreach ($values as $obj) { $oid2 = spl_object_hash($obj); if (isset($this->documentChangeSets[$oid2])) { if (empty($this->documentChangeSets[$oid][$mapping['fieldName']])) { $this->documentChangeSets[$oid][$mapping['fieldName']] = [$value, $value]; } if (! $isNewDocument) { $this->scheduleForUpdate($document); } break; } } } }
[ "private", "function", "computeOrRecomputeChangeSet", "(", "ClassMetadata", "$", "class", ",", "object", "$", "document", ",", "bool", "$", "recompute", "=", "false", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "$", "actualData", "=", "$", "this", "->", "getDocumentActualData", "(", "$", "document", ")", ";", "$", "isNewDocument", "=", "!", "isset", "(", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", ")", ";", "if", "(", "$", "isNewDocument", ")", "{", "// Document is either NEW or MANAGED but not yet fully persisted (only has an id).", "// These result in an INSERT.", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", "=", "$", "actualData", ";", "$", "changeSet", "=", "[", "]", ";", "foreach", "(", "$", "actualData", "as", "$", "propName", "=>", "$", "actualValue", ")", "{", "/* At this PersistentCollection shouldn't be here, probably it\n * was cloned and its ownership must be fixed\n */", "if", "(", "$", "actualValue", "instanceof", "PersistentCollectionInterface", "&&", "$", "actualValue", "->", "getOwner", "(", ")", "!==", "$", "document", ")", "{", "$", "actualData", "[", "$", "propName", "]", "=", "$", "this", "->", "fixPersistentCollectionOwnership", "(", "$", "actualValue", ",", "$", "document", ",", "$", "class", ",", "$", "propName", ")", ";", "$", "actualValue", "=", "$", "actualData", "[", "$", "propName", "]", ";", "}", "// ignore inverse side of reference relationship", "if", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'reference'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'isInverseSide'", "]", ")", "{", "continue", ";", "}", "$", "changeSet", "[", "$", "propName", "]", "=", "[", "null", ",", "$", "actualValue", "]", ";", "}", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", "=", "$", "changeSet", ";", "}", "else", "{", "if", "(", "$", "class", "->", "isReadOnly", ")", "{", "return", ";", "}", "// Document is \"fully\" MANAGED: it was already fully persisted before", "// and we have a copy of the original data", "$", "originalData", "=", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", ";", "$", "isChangeTrackingNotify", "=", "$", "class", "->", "isChangeTrackingNotify", "(", ")", ";", "if", "(", "$", "isChangeTrackingNotify", "&&", "!", "$", "recompute", "&&", "isset", "(", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", ")", ")", "{", "$", "changeSet", "=", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", ";", "}", "else", "{", "$", "changeSet", "=", "[", "]", ";", "}", "$", "gridFSMetadataProperty", "=", "null", ";", "if", "(", "$", "class", "->", "isFile", ")", "{", "try", "{", "$", "gridFSMetadata", "=", "$", "class", "->", "getFieldMappingByDbFieldName", "(", "'metadata'", ")", ";", "$", "gridFSMetadataProperty", "=", "$", "gridFSMetadata", "[", "'fieldName'", "]", ";", "}", "catch", "(", "MappingException", "$", "e", ")", "{", "}", "}", "foreach", "(", "$", "actualData", "as", "$", "propName", "=>", "$", "actualValue", ")", "{", "// skip not saved fields", "if", "(", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'notSaved'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'notSaved'", "]", "===", "true", ")", "||", "(", "$", "class", "->", "isFile", "&&", "$", "propName", "!==", "$", "gridFSMetadataProperty", ")", ")", "{", "continue", ";", "}", "$", "orgValue", "=", "$", "originalData", "[", "$", "propName", "]", "??", "null", ";", "// skip if value has not changed", "if", "(", "$", "orgValue", "===", "$", "actualValue", ")", "{", "if", "(", "!", "$", "actualValue", "instanceof", "PersistentCollectionInterface", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "actualValue", "->", "isDirty", "(", ")", "&&", "!", "$", "this", "->", "isCollectionScheduledForDeletion", "(", "$", "actualValue", ")", ")", "{", "// consider dirty collections as changed as well", "continue", ";", "}", "}", "// if relationship is a embed-one, schedule orphan removal to trigger cascade remove operations", "if", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'embedded'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'type'", "]", "===", "'one'", ")", "{", "if", "(", "$", "orgValue", "!==", "null", ")", "{", "$", "this", "->", "scheduleOrphanRemoval", "(", "$", "orgValue", ")", ";", "}", "$", "changeSet", "[", "$", "propName", "]", "=", "[", "$", "orgValue", ",", "$", "actualValue", "]", ";", "continue", ";", "}", "// if owning side of reference-one relationship", "if", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'reference'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'type'", "]", "===", "'one'", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'isOwningSide'", "]", ")", "{", "if", "(", "$", "orgValue", "!==", "null", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'orphanRemoval'", "]", ")", "{", "$", "this", "->", "scheduleOrphanRemoval", "(", "$", "orgValue", ")", ";", "}", "$", "changeSet", "[", "$", "propName", "]", "=", "[", "$", "orgValue", ",", "$", "actualValue", "]", ";", "continue", ";", "}", "if", "(", "$", "isChangeTrackingNotify", ")", "{", "continue", ";", "}", "// ignore inverse side of reference relationship", "if", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'reference'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'isInverseSide'", "]", ")", "{", "continue", ";", "}", "// Persistent collection was exchanged with the \"originally\"", "// created one. This can only mean it was cloned and replaced", "// on another document.", "if", "(", "$", "actualValue", "instanceof", "PersistentCollectionInterface", "&&", "$", "actualValue", "->", "getOwner", "(", ")", "!==", "$", "document", ")", "{", "$", "actualValue", "=", "$", "this", "->", "fixPersistentCollectionOwnership", "(", "$", "actualValue", ",", "$", "document", ",", "$", "class", ",", "$", "propName", ")", ";", "}", "// if embed-many or reference-many relationship", "if", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'type'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'type'", "]", "===", "'many'", ")", "{", "$", "changeSet", "[", "$", "propName", "]", "=", "[", "$", "orgValue", ",", "$", "actualValue", "]", ";", "/* If original collection was exchanged with a non-empty value\n * and $set will be issued, there is no need to $unset it first\n */", "if", "(", "$", "actualValue", "&&", "$", "actualValue", "->", "isDirty", "(", ")", "&&", "CollectionHelper", "::", "usesSet", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'strategy'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "orgValue", "!==", "$", "actualValue", "&&", "$", "orgValue", "instanceof", "PersistentCollectionInterface", ")", "{", "$", "this", "->", "scheduleCollectionDeletion", "(", "$", "orgValue", ")", ";", "}", "continue", ";", "}", "// skip equivalent date values", "if", "(", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'type'", "]", ")", "&&", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", "[", "'type'", "]", "===", "'date'", ")", "{", "/** @var DateType $dateType */", "$", "dateType", "=", "Type", "::", "getType", "(", "'date'", ")", ";", "$", "dbOrgValue", "=", "$", "dateType", "->", "convertToDatabaseValue", "(", "$", "orgValue", ")", ";", "$", "dbActualValue", "=", "$", "dateType", "->", "convertToDatabaseValue", "(", "$", "actualValue", ")", ";", "$", "orgTimestamp", "=", "$", "dbOrgValue", "instanceof", "UTCDateTime", "?", "$", "dbOrgValue", "->", "toDateTime", "(", ")", "->", "getTimestamp", "(", ")", ":", "null", ";", "$", "actualTimestamp", "=", "$", "dbActualValue", "instanceof", "UTCDateTime", "?", "$", "dbActualValue", "->", "toDateTime", "(", ")", "->", "getTimestamp", "(", ")", ":", "null", ";", "if", "(", "$", "orgTimestamp", "===", "$", "actualTimestamp", ")", "{", "continue", ";", "}", "}", "// regular field", "$", "changeSet", "[", "$", "propName", "]", "=", "[", "$", "orgValue", ",", "$", "actualValue", "]", ";", "}", "if", "(", "$", "changeSet", ")", "{", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", "=", "isset", "(", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", ")", "?", "$", "changeSet", "+", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", ":", "$", "changeSet", ";", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", "=", "$", "actualData", ";", "$", "this", "->", "scheduleForUpdate", "(", "$", "document", ")", ";", "}", "}", "// Look for changes in associations of the document", "$", "associationMappings", "=", "array_filter", "(", "$", "class", "->", "associationMappings", ",", "static", "function", "(", "$", "assoc", ")", "{", "return", "empty", "(", "$", "assoc", "[", "'notSaved'", "]", ")", ";", "}", ")", ";", "foreach", "(", "$", "associationMappings", "as", "$", "mapping", ")", "{", "$", "value", "=", "$", "class", "->", "reflFields", "[", "$", "mapping", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "value", "===", "null", ")", "{", "continue", ";", "}", "$", "this", "->", "computeAssociationChanges", "(", "$", "document", ",", "$", "mapping", ",", "$", "value", ")", ";", "if", "(", "isset", "(", "$", "mapping", "[", "'reference'", "]", ")", ")", "{", "continue", ";", "}", "$", "values", "=", "$", "mapping", "[", "'type'", "]", "===", "ClassMetadata", "::", "ONE", "?", "[", "$", "value", "]", ":", "$", "value", "->", "unwrap", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "obj", ")", "{", "$", "oid2", "=", "spl_object_hash", "(", "$", "obj", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "documentChangeSets", "[", "$", "oid2", "]", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", "[", "$", "mapping", "[", "'fieldName'", "]", "]", ")", ")", "{", "// instance of $value is the same as it was previously otherwise there would be", "// change set already in place", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", "[", "$", "mapping", "[", "'fieldName'", "]", "]", "=", "[", "$", "value", ",", "$", "value", "]", ";", "}", "if", "(", "!", "$", "isNewDocument", ")", "{", "$", "this", "->", "scheduleForUpdate", "(", "$", "document", ")", ";", "}", "break", ";", "}", "}", "}", "}" ]
Used to do the common work of computeChangeSet and recomputeSingleDocumentChangeSet
[ "Used", "to", "do", "the", "common", "work", "of", "computeChangeSet", "and", "recomputeSingleDocumentChangeSet" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L607-L796
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.computeChangeSets
public function computeChangeSets() : void { $this->computeScheduleInsertsChangeSets(); $this->computeScheduleUpsertsChangeSets(); // Compute changes for other MANAGED documents. Change tracking policies take effect here. foreach ($this->identityMap as $className => $documents) { $class = $this->dm->getClassMetadata($className); if ($class->isEmbeddedDocument) { /* we do not want to compute changes to embedded documents up front * in case embedded document was replaced and its changeset * would corrupt data. Embedded documents' change set will * be calculated by reachability from owning document. */ continue; } // If change tracking is explicit or happens through notification, then only compute // changes on document of that type that are explicitly marked for synchronization. switch (true) { case $class->isChangeTrackingDeferredImplicit(): $documentsToProcess = $documents; break; case isset($this->scheduledForSynchronization[$className]): $documentsToProcess = $this->scheduledForSynchronization[$className]; break; default: $documentsToProcess = []; } foreach ($documentsToProcess as $document) { // Ignore uninitialized proxy objects if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { continue; } // Only MANAGED documents that are NOT SCHEDULED FOR INSERTION, UPSERT OR DELETION are processed here. $oid = spl_object_hash($document); if (isset($this->documentInsertions[$oid]) || isset($this->documentUpserts[$oid]) || isset($this->documentDeletions[$oid]) || ! isset($this->documentStates[$oid]) ) { continue; } $this->computeChangeSet($class, $document); } } }
php
public function computeChangeSets() : void { $this->computeScheduleInsertsChangeSets(); $this->computeScheduleUpsertsChangeSets(); foreach ($this->identityMap as $className => $documents) { $class = $this->dm->getClassMetadata($className); if ($class->isEmbeddedDocument) { continue; } switch (true) { case $class->isChangeTrackingDeferredImplicit(): $documentsToProcess = $documents; break; case isset($this->scheduledForSynchronization[$className]): $documentsToProcess = $this->scheduledForSynchronization[$className]; break; default: $documentsToProcess = []; } foreach ($documentsToProcess as $document) { if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { continue; } $oid = spl_object_hash($document); if (isset($this->documentInsertions[$oid]) || isset($this->documentUpserts[$oid]) || isset($this->documentDeletions[$oid]) || ! isset($this->documentStates[$oid]) ) { continue; } $this->computeChangeSet($class, $document); } } }
[ "public", "function", "computeChangeSets", "(", ")", ":", "void", "{", "$", "this", "->", "computeScheduleInsertsChangeSets", "(", ")", ";", "$", "this", "->", "computeScheduleUpsertsChangeSets", "(", ")", ";", "// Compute changes for other MANAGED documents. Change tracking policies take effect here.", "foreach", "(", "$", "this", "->", "identityMap", "as", "$", "className", "=>", "$", "documents", ")", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "className", ")", ";", "if", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "/* we do not want to compute changes to embedded documents up front\n * in case embedded document was replaced and its changeset\n * would corrupt data. Embedded documents' change set will\n * be calculated by reachability from owning document.\n */", "continue", ";", "}", "// If change tracking is explicit or happens through notification, then only compute", "// changes on document of that type that are explicitly marked for synchronization.", "switch", "(", "true", ")", "{", "case", "$", "class", "->", "isChangeTrackingDeferredImplicit", "(", ")", ":", "$", "documentsToProcess", "=", "$", "documents", ";", "break", ";", "case", "isset", "(", "$", "this", "->", "scheduledForSynchronization", "[", "$", "className", "]", ")", ":", "$", "documentsToProcess", "=", "$", "this", "->", "scheduledForSynchronization", "[", "$", "className", "]", ";", "break", ";", "default", ":", "$", "documentsToProcess", "=", "[", "]", ";", "}", "foreach", "(", "$", "documentsToProcess", "as", "$", "document", ")", "{", "// Ignore uninitialized proxy objects", "if", "(", "$", "document", "instanceof", "GhostObjectInterface", "&&", "!", "$", "document", "->", "isProxyInitialized", "(", ")", ")", "{", "continue", ";", "}", "// Only MANAGED documents that are NOT SCHEDULED FOR INSERTION, UPSERT OR DELETION are processed here.", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", ")", "||", "isset", "(", "$", "this", "->", "documentUpserts", "[", "$", "oid", "]", ")", "||", "isset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "documentStates", "[", "$", "oid", "]", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "computeChangeSet", "(", "$", "class", ",", "$", "document", ")", ";", "}", "}", "}" ]
Computes all the changes that have been done to documents and collections since the last commit and stores these changes in the _documentChangeSet map temporarily for access by the persisters, until the UoW commit is finished.
[ "Computes", "all", "the", "changes", "that", "have", "been", "done", "to", "documents", "and", "collections", "since", "the", "last", "commit", "and", "stores", "these", "changes", "in", "the", "_documentChangeSet", "map", "temporarily", "for", "access", "by", "the", "persisters", "until", "the", "UoW", "commit", "is", "finished", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L803-L853
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.computeAssociationChanges
private function computeAssociationChanges(object $parentDocument, array $assoc, $value) : void { $isNewParentDocument = isset($this->documentInsertions[spl_object_hash($parentDocument)]); $class = $this->dm->getClassMetadata(get_class($parentDocument)); $topOrExistingDocument = ( ! $isNewParentDocument || ! $class->isEmbeddedDocument); if ($value instanceof GhostObjectInterface && ! $value->isProxyInitialized()) { return; } if ($value instanceof PersistentCollectionInterface && $value->isDirty() && $value->getOwner() !== null && ($assoc['isOwningSide'] || isset($assoc['embedded']))) { if ($topOrExistingDocument || CollectionHelper::usesSet($assoc['strategy'])) { $this->scheduleCollectionUpdate($value); } $topmostOwner = $this->getOwningDocument($value->getOwner()); $this->visitedCollections[spl_object_hash($topmostOwner)][] = $value; if (! empty($assoc['orphanRemoval']) || isset($assoc['embedded'])) { $value->initialize(); foreach ($value->getDeletedDocuments() as $orphan) { $this->scheduleOrphanRemoval($orphan); } } } // Look through the documents, and in any of their associations, // for transient (new) documents, recursively. ("Persistence by reachability") // Unwrap. Uninitialized collections will simply be empty. $unwrappedValue = $assoc['type'] === ClassMetadata::ONE ? [$value] : $value->unwrap(); $count = 0; foreach ($unwrappedValue as $key => $entry) { if (! is_object($entry)) { throw new InvalidArgumentException( sprintf('Expected object, found "%s" in %s::%s', $entry, get_class($parentDocument), $assoc['name']) ); } $targetClass = $this->dm->getClassMetadata(get_class($entry)); $state = $this->getDocumentState($entry, self::STATE_NEW); // Handle "set" strategy for multi-level hierarchy $pathKey = ! isset($assoc['strategy']) || CollectionHelper::isList($assoc['strategy']) ? $count : $key; $path = $assoc['type'] === 'many' ? $assoc['name'] . '.' . $pathKey : $assoc['name']; $count++; switch ($state) { case self::STATE_NEW: if (! $assoc['isCascadePersist']) { throw new InvalidArgumentException('A new document was found through a relationship that was not' . ' configured to cascade persist operations: ' . $this->objToStr($entry) . '.' . ' Explicitly persist the new document or configure cascading persist operations' . ' on the relationship.'); } $this->persistNew($targetClass, $entry); $this->setParentAssociation($entry, $assoc, $parentDocument, $path); $this->computeChangeSet($targetClass, $entry); break; case self::STATE_MANAGED: if ($targetClass->isEmbeddedDocument) { [, $knownParent ] = $this->getParentAssociation($entry); if ($knownParent && $knownParent !== $parentDocument) { $entry = clone $entry; if ($assoc['type'] === ClassMetadata::ONE) { $class->setFieldValue($parentDocument, $assoc['fieldName'], $entry); $this->setOriginalDocumentProperty(spl_object_hash($parentDocument), $assoc['fieldName'], $entry); $poid = spl_object_hash($parentDocument); if (isset($this->documentChangeSets[$poid][$assoc['fieldName']])) { $this->documentChangeSets[$poid][$assoc['fieldName']][1] = $entry; } } else { // must use unwrapped value to not trigger orphan removal $unwrappedValue[$key] = $entry; } $this->persistNew($targetClass, $entry); } $this->setParentAssociation($entry, $assoc, $parentDocument, $path); $this->computeChangeSet($targetClass, $entry); } break; case self::STATE_REMOVED: // Consume the $value as array (it's either an array or an ArrayAccess) // and remove the element from Collection. if ($assoc['type'] === ClassMetadata::MANY) { unset($value[$key]); } break; case self::STATE_DETACHED: // Can actually not happen right now as we assume STATE_NEW, // so the exception will be raised from the DBAL layer (constraint violation). throw new InvalidArgumentException('A detached document was found through a ' . 'relationship during cascading a persist operation.'); default: // MANAGED associated documents are already taken into account // during changeset calculation anyway, since they are in the identity map. } } }
php
private function computeAssociationChanges(object $parentDocument, array $assoc, $value) : void { $isNewParentDocument = isset($this->documentInsertions[spl_object_hash($parentDocument)]); $class = $this->dm->getClassMetadata(get_class($parentDocument)); $topOrExistingDocument = ( ! $isNewParentDocument || ! $class->isEmbeddedDocument); if ($value instanceof GhostObjectInterface && ! $value->isProxyInitialized()) { return; } if ($value instanceof PersistentCollectionInterface && $value->isDirty() && $value->getOwner() !== null && ($assoc['isOwningSide'] || isset($assoc['embedded']))) { if ($topOrExistingDocument || CollectionHelper::usesSet($assoc['strategy'])) { $this->scheduleCollectionUpdate($value); } $topmostOwner = $this->getOwningDocument($value->getOwner()); $this->visitedCollections[spl_object_hash($topmostOwner)][] = $value; if (! empty($assoc['orphanRemoval']) || isset($assoc['embedded'])) { $value->initialize(); foreach ($value->getDeletedDocuments() as $orphan) { $this->scheduleOrphanRemoval($orphan); } } } $unwrappedValue = $assoc['type'] === ClassMetadata::ONE ? [$value] : $value->unwrap(); $count = 0; foreach ($unwrappedValue as $key => $entry) { if (! is_object($entry)) { throw new InvalidArgumentException( sprintf('Expected object, found "%s" in %s::%s', $entry, get_class($parentDocument), $assoc['name']) ); } $targetClass = $this->dm->getClassMetadata(get_class($entry)); $state = $this->getDocumentState($entry, self::STATE_NEW); $pathKey = ! isset($assoc['strategy']) || CollectionHelper::isList($assoc['strategy']) ? $count : $key; $path = $assoc['type'] === 'many' ? $assoc['name'] . '.' . $pathKey : $assoc['name']; $count++; switch ($state) { case self::STATE_NEW: if (! $assoc['isCascadePersist']) { throw new InvalidArgumentException('A new document was found through a relationship that was not' . ' configured to cascade persist operations: ' . $this->objToStr($entry) . '.' . ' Explicitly persist the new document or configure cascading persist operations' . ' on the relationship.'); } $this->persistNew($targetClass, $entry); $this->setParentAssociation($entry, $assoc, $parentDocument, $path); $this->computeChangeSet($targetClass, $entry); break; case self::STATE_MANAGED: if ($targetClass->isEmbeddedDocument) { [, $knownParent ] = $this->getParentAssociation($entry); if ($knownParent && $knownParent !== $parentDocument) { $entry = clone $entry; if ($assoc['type'] === ClassMetadata::ONE) { $class->setFieldValue($parentDocument, $assoc['fieldName'], $entry); $this->setOriginalDocumentProperty(spl_object_hash($parentDocument), $assoc['fieldName'], $entry); $poid = spl_object_hash($parentDocument); if (isset($this->documentChangeSets[$poid][$assoc['fieldName']])) { $this->documentChangeSets[$poid][$assoc['fieldName']][1] = $entry; } } else { $unwrappedValue[$key] = $entry; } $this->persistNew($targetClass, $entry); } $this->setParentAssociation($entry, $assoc, $parentDocument, $path); $this->computeChangeSet($targetClass, $entry); } break; case self::STATE_REMOVED: if ($assoc['type'] === ClassMetadata::MANY) { unset($value[$key]); } break; case self::STATE_DETACHED: throw new InvalidArgumentException('A detached document was found through a ' . 'relationship during cascading a persist operation.'); default: } } }
[ "private", "function", "computeAssociationChanges", "(", "object", "$", "parentDocument", ",", "array", "$", "assoc", ",", "$", "value", ")", ":", "void", "{", "$", "isNewParentDocument", "=", "isset", "(", "$", "this", "->", "documentInsertions", "[", "spl_object_hash", "(", "$", "parentDocument", ")", "]", ")", ";", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "parentDocument", ")", ")", ";", "$", "topOrExistingDocument", "=", "(", "!", "$", "isNewParentDocument", "||", "!", "$", "class", "->", "isEmbeddedDocument", ")", ";", "if", "(", "$", "value", "instanceof", "GhostObjectInterface", "&&", "!", "$", "value", "->", "isProxyInitialized", "(", ")", ")", "{", "return", ";", "}", "if", "(", "$", "value", "instanceof", "PersistentCollectionInterface", "&&", "$", "value", "->", "isDirty", "(", ")", "&&", "$", "value", "->", "getOwner", "(", ")", "!==", "null", "&&", "(", "$", "assoc", "[", "'isOwningSide'", "]", "||", "isset", "(", "$", "assoc", "[", "'embedded'", "]", ")", ")", ")", "{", "if", "(", "$", "topOrExistingDocument", "||", "CollectionHelper", "::", "usesSet", "(", "$", "assoc", "[", "'strategy'", "]", ")", ")", "{", "$", "this", "->", "scheduleCollectionUpdate", "(", "$", "value", ")", ";", "}", "$", "topmostOwner", "=", "$", "this", "->", "getOwningDocument", "(", "$", "value", "->", "getOwner", "(", ")", ")", ";", "$", "this", "->", "visitedCollections", "[", "spl_object_hash", "(", "$", "topmostOwner", ")", "]", "[", "]", "=", "$", "value", ";", "if", "(", "!", "empty", "(", "$", "assoc", "[", "'orphanRemoval'", "]", ")", "||", "isset", "(", "$", "assoc", "[", "'embedded'", "]", ")", ")", "{", "$", "value", "->", "initialize", "(", ")", ";", "foreach", "(", "$", "value", "->", "getDeletedDocuments", "(", ")", "as", "$", "orphan", ")", "{", "$", "this", "->", "scheduleOrphanRemoval", "(", "$", "orphan", ")", ";", "}", "}", "}", "// Look through the documents, and in any of their associations,", "// for transient (new) documents, recursively. (\"Persistence by reachability\")", "// Unwrap. Uninitialized collections will simply be empty.", "$", "unwrappedValue", "=", "$", "assoc", "[", "'type'", "]", "===", "ClassMetadata", "::", "ONE", "?", "[", "$", "value", "]", ":", "$", "value", "->", "unwrap", "(", ")", ";", "$", "count", "=", "0", ";", "foreach", "(", "$", "unwrappedValue", "as", "$", "key", "=>", "$", "entry", ")", "{", "if", "(", "!", "is_object", "(", "$", "entry", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Expected object, found \"%s\" in %s::%s'", ",", "$", "entry", ",", "get_class", "(", "$", "parentDocument", ")", ",", "$", "assoc", "[", "'name'", "]", ")", ")", ";", "}", "$", "targetClass", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "entry", ")", ")", ";", "$", "state", "=", "$", "this", "->", "getDocumentState", "(", "$", "entry", ",", "self", "::", "STATE_NEW", ")", ";", "// Handle \"set\" strategy for multi-level hierarchy", "$", "pathKey", "=", "!", "isset", "(", "$", "assoc", "[", "'strategy'", "]", ")", "||", "CollectionHelper", "::", "isList", "(", "$", "assoc", "[", "'strategy'", "]", ")", "?", "$", "count", ":", "$", "key", ";", "$", "path", "=", "$", "assoc", "[", "'type'", "]", "===", "'many'", "?", "$", "assoc", "[", "'name'", "]", ".", "'.'", ".", "$", "pathKey", ":", "$", "assoc", "[", "'name'", "]", ";", "$", "count", "++", ";", "switch", "(", "$", "state", ")", "{", "case", "self", "::", "STATE_NEW", ":", "if", "(", "!", "$", "assoc", "[", "'isCascadePersist'", "]", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'A new document was found through a relationship that was not'", ".", "' configured to cascade persist operations: '", ".", "$", "this", "->", "objToStr", "(", "$", "entry", ")", ".", "'.'", ".", "' Explicitly persist the new document or configure cascading persist operations'", ".", "' on the relationship.'", ")", ";", "}", "$", "this", "->", "persistNew", "(", "$", "targetClass", ",", "$", "entry", ")", ";", "$", "this", "->", "setParentAssociation", "(", "$", "entry", ",", "$", "assoc", ",", "$", "parentDocument", ",", "$", "path", ")", ";", "$", "this", "->", "computeChangeSet", "(", "$", "targetClass", ",", "$", "entry", ")", ";", "break", ";", "case", "self", "::", "STATE_MANAGED", ":", "if", "(", "$", "targetClass", "->", "isEmbeddedDocument", ")", "{", "[", ",", "$", "knownParent", "]", "=", "$", "this", "->", "getParentAssociation", "(", "$", "entry", ")", ";", "if", "(", "$", "knownParent", "&&", "$", "knownParent", "!==", "$", "parentDocument", ")", "{", "$", "entry", "=", "clone", "$", "entry", ";", "if", "(", "$", "assoc", "[", "'type'", "]", "===", "ClassMetadata", "::", "ONE", ")", "{", "$", "class", "->", "setFieldValue", "(", "$", "parentDocument", ",", "$", "assoc", "[", "'fieldName'", "]", ",", "$", "entry", ")", ";", "$", "this", "->", "setOriginalDocumentProperty", "(", "spl_object_hash", "(", "$", "parentDocument", ")", ",", "$", "assoc", "[", "'fieldName'", "]", ",", "$", "entry", ")", ";", "$", "poid", "=", "spl_object_hash", "(", "$", "parentDocument", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "documentChangeSets", "[", "$", "poid", "]", "[", "$", "assoc", "[", "'fieldName'", "]", "]", ")", ")", "{", "$", "this", "->", "documentChangeSets", "[", "$", "poid", "]", "[", "$", "assoc", "[", "'fieldName'", "]", "]", "[", "1", "]", "=", "$", "entry", ";", "}", "}", "else", "{", "// must use unwrapped value to not trigger orphan removal", "$", "unwrappedValue", "[", "$", "key", "]", "=", "$", "entry", ";", "}", "$", "this", "->", "persistNew", "(", "$", "targetClass", ",", "$", "entry", ")", ";", "}", "$", "this", "->", "setParentAssociation", "(", "$", "entry", ",", "$", "assoc", ",", "$", "parentDocument", ",", "$", "path", ")", ";", "$", "this", "->", "computeChangeSet", "(", "$", "targetClass", ",", "$", "entry", ")", ";", "}", "break", ";", "case", "self", "::", "STATE_REMOVED", ":", "// Consume the $value as array (it's either an array or an ArrayAccess)", "// and remove the element from Collection.", "if", "(", "$", "assoc", "[", "'type'", "]", "===", "ClassMetadata", "::", "MANY", ")", "{", "unset", "(", "$", "value", "[", "$", "key", "]", ")", ";", "}", "break", ";", "case", "self", "::", "STATE_DETACHED", ":", "// Can actually not happen right now as we assume STATE_NEW,", "// so the exception will be raised from the DBAL layer (constraint violation).", "throw", "new", "InvalidArgumentException", "(", "'A detached document was found through a '", ".", "'relationship during cascading a persist operation.'", ")", ";", "default", ":", "// MANAGED associated documents are already taken into account", "// during changeset calculation anyway, since they are in the identity map.", "}", "}", "}" ]
Computes the changes of an association. @param mixed $value The value of the association. @throws InvalidArgumentException
[ "Computes", "the", "changes", "of", "an", "association", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L862-L966
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.executeInserts
private function executeInserts(ClassMetadata $class, array $documents, array $options = []) : void { $persister = $this->getDocumentPersister($class->name); foreach ($documents as $oid => $document) { $persister->addInsert($document); unset($this->documentInsertions[$oid]); } $persister->executeInserts($options); foreach ($documents as $document) { $this->lifecycleEventManager->postPersist($class, $document); } }
php
private function executeInserts(ClassMetadata $class, array $documents, array $options = []) : void { $persister = $this->getDocumentPersister($class->name); foreach ($documents as $oid => $document) { $persister->addInsert($document); unset($this->documentInsertions[$oid]); } $persister->executeInserts($options); foreach ($documents as $document) { $this->lifecycleEventManager->postPersist($class, $document); } }
[ "private", "function", "executeInserts", "(", "ClassMetadata", "$", "class", ",", "array", "$", "documents", ",", "array", "$", "options", "=", "[", "]", ")", ":", "void", "{", "$", "persister", "=", "$", "this", "->", "getDocumentPersister", "(", "$", "class", "->", "name", ")", ";", "foreach", "(", "$", "documents", "as", "$", "oid", "=>", "$", "document", ")", "{", "$", "persister", "->", "addInsert", "(", "$", "document", ")", ";", "unset", "(", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", ")", ";", "}", "$", "persister", "->", "executeInserts", "(", "$", "options", ")", ";", "foreach", "(", "$", "documents", "as", "$", "document", ")", "{", "$", "this", "->", "lifecycleEventManager", "->", "postPersist", "(", "$", "class", ",", "$", "document", ")", ";", "}", "}" ]
Executes all document insertions for documents of the specified type.
[ "Executes", "all", "document", "insertions", "for", "documents", "of", "the", "specified", "type", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1048-L1062
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.executeUpserts
private function executeUpserts(ClassMetadata $class, array $documents, array $options = []) : void { $persister = $this->getDocumentPersister($class->name); foreach ($documents as $oid => $document) { $persister->addUpsert($document); unset($this->documentUpserts[$oid]); } $persister->executeUpserts($options); foreach ($documents as $document) { $this->lifecycleEventManager->postPersist($class, $document); } }
php
private function executeUpserts(ClassMetadata $class, array $documents, array $options = []) : void { $persister = $this->getDocumentPersister($class->name); foreach ($documents as $oid => $document) { $persister->addUpsert($document); unset($this->documentUpserts[$oid]); } $persister->executeUpserts($options); foreach ($documents as $document) { $this->lifecycleEventManager->postPersist($class, $document); } }
[ "private", "function", "executeUpserts", "(", "ClassMetadata", "$", "class", ",", "array", "$", "documents", ",", "array", "$", "options", "=", "[", "]", ")", ":", "void", "{", "$", "persister", "=", "$", "this", "->", "getDocumentPersister", "(", "$", "class", "->", "name", ")", ";", "foreach", "(", "$", "documents", "as", "$", "oid", "=>", "$", "document", ")", "{", "$", "persister", "->", "addUpsert", "(", "$", "document", ")", ";", "unset", "(", "$", "this", "->", "documentUpserts", "[", "$", "oid", "]", ")", ";", "}", "$", "persister", "->", "executeUpserts", "(", "$", "options", ")", ";", "foreach", "(", "$", "documents", "as", "$", "document", ")", "{", "$", "this", "->", "lifecycleEventManager", "->", "postPersist", "(", "$", "class", ",", "$", "document", ")", ";", "}", "}" ]
Executes all document upserts for documents of the specified type.
[ "Executes", "all", "document", "upserts", "for", "documents", "of", "the", "specified", "type", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1067-L1081
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.executeDeletions
private function executeDeletions(ClassMetadata $class, array $documents, array $options = []) : void { $persister = $this->getDocumentPersister($class->name); foreach ($documents as $oid => $document) { if (! $class->isEmbeddedDocument) { $persister->delete($document, $options); } unset( $this->documentDeletions[$oid], $this->documentIdentifiers[$oid], $this->originalDocumentData[$oid] ); // Clear snapshot information for any referenced PersistentCollection // http://www.doctrine-project.org/jira/browse/MODM-95 foreach ($class->associationMappings as $fieldMapping) { if (! isset($fieldMapping['type']) || $fieldMapping['type'] !== ClassMetadata::MANY) { continue; } $value = $class->reflFields[$fieldMapping['fieldName']]->getValue($document); if (! ($value instanceof PersistentCollectionInterface)) { continue; } $value->clearSnapshot(); } // Document with this $oid after deletion treated as NEW, even if the $oid // is obtained by a new document because the old one went out of scope. $this->documentStates[$oid] = self::STATE_NEW; $this->lifecycleEventManager->postRemove($class, $document); } }
php
private function executeDeletions(ClassMetadata $class, array $documents, array $options = []) : void { $persister = $this->getDocumentPersister($class->name); foreach ($documents as $oid => $document) { if (! $class->isEmbeddedDocument) { $persister->delete($document, $options); } unset( $this->documentDeletions[$oid], $this->documentIdentifiers[$oid], $this->originalDocumentData[$oid] ); foreach ($class->associationMappings as $fieldMapping) { if (! isset($fieldMapping['type']) || $fieldMapping['type'] !== ClassMetadata::MANY) { continue; } $value = $class->reflFields[$fieldMapping['fieldName']]->getValue($document); if (! ($value instanceof PersistentCollectionInterface)) { continue; } $value->clearSnapshot(); } $this->documentStates[$oid] = self::STATE_NEW; $this->lifecycleEventManager->postRemove($class, $document); } }
[ "private", "function", "executeDeletions", "(", "ClassMetadata", "$", "class", ",", "array", "$", "documents", ",", "array", "$", "options", "=", "[", "]", ")", ":", "void", "{", "$", "persister", "=", "$", "this", "->", "getDocumentPersister", "(", "$", "class", "->", "name", ")", ";", "foreach", "(", "$", "documents", "as", "$", "oid", "=>", "$", "document", ")", "{", "if", "(", "!", "$", "class", "->", "isEmbeddedDocument", ")", "{", "$", "persister", "->", "delete", "(", "$", "document", ",", "$", "options", ")", ";", "}", "unset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ",", "$", "this", "->", "documentIdentifiers", "[", "$", "oid", "]", ",", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", ")", ";", "// Clear snapshot information for any referenced PersistentCollection", "// http://www.doctrine-project.org/jira/browse/MODM-95", "foreach", "(", "$", "class", "->", "associationMappings", "as", "$", "fieldMapping", ")", "{", "if", "(", "!", "isset", "(", "$", "fieldMapping", "[", "'type'", "]", ")", "||", "$", "fieldMapping", "[", "'type'", "]", "!==", "ClassMetadata", "::", "MANY", ")", "{", "continue", ";", "}", "$", "value", "=", "$", "class", "->", "reflFields", "[", "$", "fieldMapping", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "!", "(", "$", "value", "instanceof", "PersistentCollectionInterface", ")", ")", "{", "continue", ";", "}", "$", "value", "->", "clearSnapshot", "(", ")", ";", "}", "// Document with this $oid after deletion treated as NEW, even if the $oid", "// is obtained by a new document because the old one went out of scope.", "$", "this", "->", "documentStates", "[", "$", "oid", "]", "=", "self", "::", "STATE_NEW", ";", "$", "this", "->", "lifecycleEventManager", "->", "postRemove", "(", "$", "class", ",", "$", "document", ")", ";", "}", "}" ]
Executes all document deletions for documents of the specified type.
[ "Executes", "all", "document", "deletions", "for", "documents", "of", "the", "specified", "type", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1111-L1146
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleForInsert
public function scheduleForInsert(ClassMetadata $class, object $document) : void { $oid = spl_object_hash($document); if (isset($this->documentUpdates[$oid])) { throw new InvalidArgumentException('Dirty document can not be scheduled for insertion.'); } if (isset($this->documentDeletions[$oid])) { throw new InvalidArgumentException('Removed document can not be scheduled for insertion.'); } if (isset($this->documentInsertions[$oid])) { throw new InvalidArgumentException('Document can not be scheduled for insertion twice.'); } $this->documentInsertions[$oid] = $document; if (! isset($this->documentIdentifiers[$oid])) { return; } $this->addToIdentityMap($document); }
php
public function scheduleForInsert(ClassMetadata $class, object $document) : void { $oid = spl_object_hash($document); if (isset($this->documentUpdates[$oid])) { throw new InvalidArgumentException('Dirty document can not be scheduled for insertion.'); } if (isset($this->documentDeletions[$oid])) { throw new InvalidArgumentException('Removed document can not be scheduled for insertion.'); } if (isset($this->documentInsertions[$oid])) { throw new InvalidArgumentException('Document can not be scheduled for insertion twice.'); } $this->documentInsertions[$oid] = $document; if (! isset($this->documentIdentifiers[$oid])) { return; } $this->addToIdentityMap($document); }
[ "public", "function", "scheduleForInsert", "(", "ClassMetadata", "$", "class", ",", "object", "$", "document", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "documentUpdates", "[", "$", "oid", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Dirty document can not be scheduled for insertion.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Removed document can not be scheduled for insertion.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Document can not be scheduled for insertion twice.'", ")", ";", "}", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", "=", "$", "document", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "documentIdentifiers", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "addToIdentityMap", "(", "$", "document", ")", ";", "}" ]
Schedules a document for insertion into the database. If the document already has an identifier, it will be added to the identity map. @internal @throws InvalidArgumentException
[ "Schedules", "a", "document", "for", "insertion", "into", "the", "database", ".", "If", "the", "document", "already", "has", "an", "identifier", "it", "will", "be", "added", "to", "the", "identity", "map", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1157-L1178
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleForUpsert
public function scheduleForUpsert(ClassMetadata $class, object $document) : void { $oid = spl_object_hash($document); if ($class->isEmbeddedDocument) { throw new InvalidArgumentException('Embedded document can not be scheduled for upsert.'); } if (isset($this->documentUpdates[$oid])) { throw new InvalidArgumentException('Dirty document can not be scheduled for upsert.'); } if (isset($this->documentDeletions[$oid])) { throw new InvalidArgumentException('Removed document can not be scheduled for upsert.'); } if (isset($this->documentUpserts[$oid])) { throw new InvalidArgumentException('Document can not be scheduled for upsert twice.'); } $this->documentUpserts[$oid] = $document; $this->documentIdentifiers[$oid] = $class->getIdentifierValue($document); $this->addToIdentityMap($document); }
php
public function scheduleForUpsert(ClassMetadata $class, object $document) : void { $oid = spl_object_hash($document); if ($class->isEmbeddedDocument) { throw new InvalidArgumentException('Embedded document can not be scheduled for upsert.'); } if (isset($this->documentUpdates[$oid])) { throw new InvalidArgumentException('Dirty document can not be scheduled for upsert.'); } if (isset($this->documentDeletions[$oid])) { throw new InvalidArgumentException('Removed document can not be scheduled for upsert.'); } if (isset($this->documentUpserts[$oid])) { throw new InvalidArgumentException('Document can not be scheduled for upsert twice.'); } $this->documentUpserts[$oid] = $document; $this->documentIdentifiers[$oid] = $class->getIdentifierValue($document); $this->addToIdentityMap($document); }
[ "public", "function", "scheduleForUpsert", "(", "ClassMetadata", "$", "class", ",", "object", "$", "document", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Embedded document can not be scheduled for upsert.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "documentUpdates", "[", "$", "oid", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Dirty document can not be scheduled for upsert.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Removed document can not be scheduled for upsert.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "documentUpserts", "[", "$", "oid", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Document can not be scheduled for upsert twice.'", ")", ";", "}", "$", "this", "->", "documentUpserts", "[", "$", "oid", "]", "=", "$", "document", ";", "$", "this", "->", "documentIdentifiers", "[", "$", "oid", "]", "=", "$", "class", "->", "getIdentifierValue", "(", "$", "document", ")", ";", "$", "this", "->", "addToIdentityMap", "(", "$", "document", ")", ";", "}" ]
Schedules a document for upsert into the database and adds it to the identity map @internal @throws InvalidArgumentException
[ "Schedules", "a", "document", "for", "upsert", "into", "the", "database", "and", "adds", "it", "to", "the", "identity", "map" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1188-L1208
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.isScheduledForSynchronization
public function isScheduledForSynchronization(object $document) : bool { $class = $this->dm->getClassMetadata(get_class($document)); return isset($this->scheduledForSynchronization[$class->name][spl_object_hash($document)]); }
php
public function isScheduledForSynchronization(object $document) : bool { $class = $this->dm->getClassMetadata(get_class($document)); return isset($this->scheduledForSynchronization[$class->name][spl_object_hash($document)]); }
[ "public", "function", "isScheduledForSynchronization", "(", "object", "$", "document", ")", ":", "bool", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "return", "isset", "(", "$", "this", "->", "scheduledForSynchronization", "[", "$", "class", "->", "name", "]", "[", "spl_object_hash", "(", "$", "document", ")", "]", ")", ";", "}" ]
Checks whether a document is registered to be checked in the unit of work.
[ "Checks", "whether", "a", "document", "is", "registered", "to", "be", "checked", "in", "the", "unit", "of", "work", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1266-L1270
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleForDelete
public function scheduleForDelete(object $document) : void { $oid = spl_object_hash($document); if (isset($this->documentInsertions[$oid])) { if ($this->isInIdentityMap($document)) { $this->removeFromIdentityMap($document); } unset($this->documentInsertions[$oid]); return; // document has not been persisted yet, so nothing more to do. } if (! $this->isInIdentityMap($document)) { return; // ignore } $this->removeFromIdentityMap($document); $this->documentStates[$oid] = self::STATE_REMOVED; if (isset($this->documentUpdates[$oid])) { unset($this->documentUpdates[$oid]); } if (isset($this->documentDeletions[$oid])) { return; } $this->documentDeletions[$oid] = $document; }
php
public function scheduleForDelete(object $document) : void { $oid = spl_object_hash($document); if (isset($this->documentInsertions[$oid])) { if ($this->isInIdentityMap($document)) { $this->removeFromIdentityMap($document); } unset($this->documentInsertions[$oid]); return; } if (! $this->isInIdentityMap($document)) { return; } $this->removeFromIdentityMap($document); $this->documentStates[$oid] = self::STATE_REMOVED; if (isset($this->documentUpdates[$oid])) { unset($this->documentUpdates[$oid]); } if (isset($this->documentDeletions[$oid])) { return; } $this->documentDeletions[$oid] = $document; }
[ "public", "function", "scheduleForDelete", "(", "object", "$", "document", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", ")", ")", "{", "if", "(", "$", "this", "->", "isInIdentityMap", "(", "$", "document", ")", ")", "{", "$", "this", "->", "removeFromIdentityMap", "(", "$", "document", ")", ";", "}", "unset", "(", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", ")", ";", "return", ";", "// document has not been persisted yet, so nothing more to do.", "}", "if", "(", "!", "$", "this", "->", "isInIdentityMap", "(", "$", "document", ")", ")", "{", "return", ";", "// ignore", "}", "$", "this", "->", "removeFromIdentityMap", "(", "$", "document", ")", ";", "$", "this", "->", "documentStates", "[", "$", "oid", "]", "=", "self", "::", "STATE_REMOVED", ";", "if", "(", "isset", "(", "$", "this", "->", "documentUpdates", "[", "$", "oid", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "documentUpdates", "[", "$", "oid", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", "=", "$", "document", ";", "}" ]
Schedules a document for deletion. @internal
[ "Schedules", "a", "document", "for", "deletion", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1277-L1304
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.isDocumentScheduled
public function isDocumentScheduled(object $document) : bool { $oid = spl_object_hash($document); return isset($this->documentInsertions[$oid]) || isset($this->documentUpserts[$oid]) || isset($this->documentUpdates[$oid]) || isset($this->documentDeletions[$oid]); }
php
public function isDocumentScheduled(object $document) : bool { $oid = spl_object_hash($document); return isset($this->documentInsertions[$oid]) || isset($this->documentUpserts[$oid]) || isset($this->documentUpdates[$oid]) || isset($this->documentDeletions[$oid]); }
[ "public", "function", "isDocumentScheduled", "(", "object", "$", "document", ")", ":", "bool", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "return", "isset", "(", "$", "this", "->", "documentInsertions", "[", "$", "oid", "]", ")", "||", "isset", "(", "$", "this", "->", "documentUpserts", "[", "$", "oid", "]", ")", "||", "isset", "(", "$", "this", "->", "documentUpdates", "[", "$", "oid", "]", ")", "||", "isset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ")", ";", "}" ]
Checks whether a document is scheduled for insertion, update or deletion. @internal
[ "Checks", "whether", "a", "document", "is", "scheduled", "for", "insertion", "update", "or", "deletion", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1320-L1327
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.addToIdentityMap
public function addToIdentityMap(object $document) : bool { $class = $this->dm->getClassMetadata(get_class($document)); $id = $this->getIdForIdentityMap($document); if (isset($this->identityMap[$class->name][$id])) { return false; } $this->identityMap[$class->name][$id] = $document; if ($document instanceof NotifyPropertyChanged && ( ! $document instanceof GhostObjectInterface || $document->isProxyInitialized())) { $document->addPropertyChangedListener($this); } return true; }
php
public function addToIdentityMap(object $document) : bool { $class = $this->dm->getClassMetadata(get_class($document)); $id = $this->getIdForIdentityMap($document); if (isset($this->identityMap[$class->name][$id])) { return false; } $this->identityMap[$class->name][$id] = $document; if ($document instanceof NotifyPropertyChanged && ( ! $document instanceof GhostObjectInterface || $document->isProxyInitialized())) { $document->addPropertyChangedListener($this); } return true; }
[ "public", "function", "addToIdentityMap", "(", "object", "$", "document", ")", ":", "bool", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "id", "=", "$", "this", "->", "getIdForIdentityMap", "(", "$", "document", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "id", "]", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "id", "]", "=", "$", "document", ";", "if", "(", "$", "document", "instanceof", "NotifyPropertyChanged", "&&", "(", "!", "$", "document", "instanceof", "GhostObjectInterface", "||", "$", "document", "->", "isProxyInitialized", "(", ")", ")", ")", "{", "$", "document", "->", "addPropertyChangedListener", "(", "$", "this", ")", ";", "}", "return", "true", ";", "}" ]
Registers a document in the identity map. Note that documents in a hierarchy are registered with the class name of the root document. Identifiers are serialized before being used as array keys to allow differentiation of equal, but not identical, values. @internal
[ "Registers", "a", "document", "in", "the", "identity", "map", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1338-L1355
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.tryGetById
public function tryGetById($id, ClassMetadata $class) { if (! $class->identifier) { throw new InvalidArgumentException(sprintf('Class "%s" does not have an identifier', $class->name)); } $serializedId = serialize($class->getDatabaseIdentifierValue($id)); return $this->identityMap[$class->name][$serializedId] ?? false; }
php
public function tryGetById($id, ClassMetadata $class) { if (! $class->identifier) { throw new InvalidArgumentException(sprintf('Class "%s" does not have an identifier', $class->name)); } $serializedId = serialize($class->getDatabaseIdentifierValue($id)); return $this->identityMap[$class->name][$serializedId] ?? false; }
[ "public", "function", "tryGetById", "(", "$", "id", ",", "ClassMetadata", "$", "class", ")", "{", "if", "(", "!", "$", "class", "->", "identifier", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Class \"%s\" does not have an identifier'", ",", "$", "class", "->", "name", ")", ")", ";", "}", "$", "serializedId", "=", "serialize", "(", "$", "class", "->", "getDatabaseIdentifierValue", "(", "$", "id", ")", ")", ";", "return", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "serializedId", "]", "??", "false", ";", "}" ]
Tries to get a document by its identifier hash. If no document is found for the given hash, FALSE is returned. @internal @param mixed $id Document identifier @return mixed The found document or FALSE. @throws InvalidArgumentException If the class does not have an identifier.
[ "Tries", "to", "get", "a", "document", "by", "its", "identifier", "hash", ".", "If", "no", "document", "is", "found", "for", "the", "given", "hash", "FALSE", "is", "returned", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1477-L1486
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleForSynchronization
public function scheduleForSynchronization(object $document) : void { $class = $this->dm->getClassMetadata(get_class($document)); $this->scheduledForSynchronization[$class->name][spl_object_hash($document)] = $document; }
php
public function scheduleForSynchronization(object $document) : void { $class = $this->dm->getClassMetadata(get_class($document)); $this->scheduledForSynchronization[$class->name][spl_object_hash($document)] = $document; }
[ "public", "function", "scheduleForSynchronization", "(", "object", "$", "document", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "this", "->", "scheduledForSynchronization", "[", "$", "class", "->", "name", "]", "[", "spl_object_hash", "(", "$", "document", ")", "]", "=", "$", "document", ";", "}" ]
Schedules a document for dirty-checking at commit-time. @internal
[ "Schedules", "a", "document", "for", "dirty", "-", "checking", "at", "commit", "-", "time", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1493-L1497
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.isInIdentityMap
public function isInIdentityMap(object $document) : bool { $oid = spl_object_hash($document); if (! isset($this->documentIdentifiers[$oid])) { return false; } $class = $this->dm->getClassMetadata(get_class($document)); $id = $this->getIdForIdentityMap($document); return isset($this->identityMap[$class->name][$id]); }
php
public function isInIdentityMap(object $document) : bool { $oid = spl_object_hash($document); if (! isset($this->documentIdentifiers[$oid])) { return false; } $class = $this->dm->getClassMetadata(get_class($document)); $id = $this->getIdForIdentityMap($document); return isset($this->identityMap[$class->name][$id]); }
[ "public", "function", "isInIdentityMap", "(", "object", "$", "document", ")", ":", "bool", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "documentIdentifiers", "[", "$", "oid", "]", ")", ")", "{", "return", "false", ";", "}", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "id", "=", "$", "this", "->", "getIdForIdentityMap", "(", "$", "document", ")", ";", "return", "isset", "(", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "id", "]", ")", ";", "}" ]
Checks whether a document is registered in the identity map. @internal
[ "Checks", "whether", "a", "document", "is", "registered", "in", "the", "identity", "map", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1504-L1516
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.containsId
public function containsId($id, string $rootClassName) : bool { return isset($this->identityMap[$rootClassName][serialize($id)]); }
php
public function containsId($id, string $rootClassName) : bool { return isset($this->identityMap[$rootClassName][serialize($id)]); }
[ "public", "function", "containsId", "(", "$", "id", ",", "string", "$", "rootClassName", ")", ":", "bool", "{", "return", "isset", "(", "$", "this", "->", "identityMap", "[", "$", "rootClassName", "]", "[", "serialize", "(", "$", "id", ")", "]", ")", ";", "}" ]
Checks whether an identifier exists in the identity map. @internal
[ "Checks", "whether", "an", "identifier", "exists", "in", "the", "identity", "map", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1537-L1540
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.persist
public function persist(object $document) : void { $class = $this->dm->getClassMetadata(get_class($document)); if ($class->isMappedSuperclass || $class->isQueryResultDocument) { throw MongoDBException::cannotPersistMappedSuperclass($class->name); } $visited = []; $this->doPersist($document, $visited); }
php
public function persist(object $document) : void { $class = $this->dm->getClassMetadata(get_class($document)); if ($class->isMappedSuperclass || $class->isQueryResultDocument) { throw MongoDBException::cannotPersistMappedSuperclass($class->name); } $visited = []; $this->doPersist($document, $visited); }
[ "public", "function", "persist", "(", "object", "$", "document", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "if", "(", "$", "class", "->", "isMappedSuperclass", "||", "$", "class", "->", "isQueryResultDocument", ")", "{", "throw", "MongoDBException", "::", "cannotPersistMappedSuperclass", "(", "$", "class", "->", "name", ")", ";", "}", "$", "visited", "=", "[", "]", ";", "$", "this", "->", "doPersist", "(", "$", "document", ",", "$", "visited", ")", ";", "}" ]
Persists a document as part of the current unit of work. @internal @throws MongoDBException If trying to persist MappedSuperclass. @throws InvalidArgumentException If there is something wrong with document's identifier.
[ "Persists", "a", "document", "as", "part", "of", "the", "current", "unit", "of", "work", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1550-L1558
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.doPersist
private function doPersist(object $document, array &$visited) : void { $oid = spl_object_hash($document); if (isset($visited[$oid])) { return; // Prevent infinite recursion } $visited[$oid] = $document; // Mark visited $class = $this->dm->getClassMetadata(get_class($document)); $documentState = $this->getDocumentState($document, self::STATE_NEW); switch ($documentState) { case self::STATE_MANAGED: // Nothing to do, except if policy is "deferred explicit" if ($class->isChangeTrackingDeferredExplicit()) { $this->scheduleForSynchronization($document); } break; case self::STATE_NEW: if ($class->isFile) { throw MongoDBException::cannotPersistGridFSFile($class->name); } $this->persistNew($class, $document); break; case self::STATE_REMOVED: // Document becomes managed again unset($this->documentDeletions[$oid]); $this->documentStates[$oid] = self::STATE_MANAGED; break; case self::STATE_DETACHED: throw new InvalidArgumentException( 'Behavior of persist() for a detached document is not yet defined.' ); default: throw MongoDBException::invalidDocumentState($documentState); } $this->cascadePersist($document, $visited); }
php
private function doPersist(object $document, array &$visited) : void { $oid = spl_object_hash($document); if (isset($visited[$oid])) { return; } $visited[$oid] = $document; $class = $this->dm->getClassMetadata(get_class($document)); $documentState = $this->getDocumentState($document, self::STATE_NEW); switch ($documentState) { case self::STATE_MANAGED: if ($class->isChangeTrackingDeferredExplicit()) { $this->scheduleForSynchronization($document); } break; case self::STATE_NEW: if ($class->isFile) { throw MongoDBException::cannotPersistGridFSFile($class->name); } $this->persistNew($class, $document); break; case self::STATE_REMOVED: unset($this->documentDeletions[$oid]); $this->documentStates[$oid] = self::STATE_MANAGED; break; case self::STATE_DETACHED: throw new InvalidArgumentException( 'Behavior of persist() for a detached document is not yet defined.' ); default: throw MongoDBException::invalidDocumentState($documentState); } $this->cascadePersist($document, $visited); }
[ "private", "function", "doPersist", "(", "object", "$", "document", ",", "array", "&", "$", "visited", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "isset", "(", "$", "visited", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "// Prevent infinite recursion", "}", "$", "visited", "[", "$", "oid", "]", "=", "$", "document", ";", "// Mark visited", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "documentState", "=", "$", "this", "->", "getDocumentState", "(", "$", "document", ",", "self", "::", "STATE_NEW", ")", ";", "switch", "(", "$", "documentState", ")", "{", "case", "self", "::", "STATE_MANAGED", ":", "// Nothing to do, except if policy is \"deferred explicit\"", "if", "(", "$", "class", "->", "isChangeTrackingDeferredExplicit", "(", ")", ")", "{", "$", "this", "->", "scheduleForSynchronization", "(", "$", "document", ")", ";", "}", "break", ";", "case", "self", "::", "STATE_NEW", ":", "if", "(", "$", "class", "->", "isFile", ")", "{", "throw", "MongoDBException", "::", "cannotPersistGridFSFile", "(", "$", "class", "->", "name", ")", ";", "}", "$", "this", "->", "persistNew", "(", "$", "class", ",", "$", "document", ")", ";", "break", ";", "case", "self", "::", "STATE_REMOVED", ":", "// Document becomes managed again", "unset", "(", "$", "this", "->", "documentDeletions", "[", "$", "oid", "]", ")", ";", "$", "this", "->", "documentStates", "[", "$", "oid", "]", "=", "self", "::", "STATE_MANAGED", ";", "break", ";", "case", "self", "::", "STATE_DETACHED", ":", "throw", "new", "InvalidArgumentException", "(", "'Behavior of persist() for a detached document is not yet defined.'", ")", ";", "default", ":", "throw", "MongoDBException", "::", "invalidDocumentState", "(", "$", "documentState", ")", ";", "}", "$", "this", "->", "cascadePersist", "(", "$", "document", ",", "$", "visited", ")", ";", "}" ]
Saves a document as part of the current unit of work. This method is internally called during save() cascades as it tracks the already visited documents to prevent infinite recursions. NOTE: This method always considers documents that are not yet known to this UnitOfWork as NEW. @throws InvalidArgumentException @throws MongoDBException
[ "Saves", "a", "document", "as", "part", "of", "the", "current", "unit", "of", "work", ".", "This", "method", "is", "internally", "called", "during", "save", "()", "cascades", "as", "it", "tracks", "the", "already", "visited", "documents", "to", "prevent", "infinite", "recursions", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1571-L1615
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.doMerge
private function doMerge(object $document, array &$visited, ?object $prevManagedCopy = null, ?array $assoc = null) : object { $oid = spl_object_hash($document); if (isset($visited[$oid])) { return $visited[$oid]; // Prevent infinite recursion } $visited[$oid] = $document; // mark visited $class = $this->dm->getClassMetadata(get_class($document)); /* First we assume DETACHED, although it can still be NEW but we can * avoid an extra DB round trip this way. If it is not MANAGED but has * an identity, we need to fetch it from the DB anyway in order to * merge. MANAGED documents are ignored by the merge operation. */ $managedCopy = $document; if ($this->getDocumentState($document, self::STATE_DETACHED) !== self::STATE_MANAGED) { if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->initializeProxy(); } $identifier = $class->getIdentifier(); // We always have one element in the identifier array but it might be null $id = $identifier[0] !== null ? $class->getIdentifierObject($document) : null; $managedCopy = null; // Try to fetch document from the database if (! $class->isEmbeddedDocument && $id !== null) { $managedCopy = $this->dm->find($class->name, $id); // Managed copy may be removed in which case we can't merge if ($managedCopy && $this->getDocumentState($managedCopy) === self::STATE_REMOVED) { throw new InvalidArgumentException('Removed entity detected during merge. Cannot merge with a removed entity.'); } if ($managedCopy instanceof GhostObjectInterface && ! $managedCopy->isProxyInitialized()) { $managedCopy->initializeProxy(); } } if ($managedCopy === null) { // Create a new managed instance $managedCopy = $class->newInstance(); if ($id !== null) { $class->setIdentifierValue($managedCopy, $id); } $this->persistNew($class, $managedCopy); } if ($class->isVersioned) { $managedCopyVersion = $class->reflFields[$class->versionField]->getValue($managedCopy); $documentVersion = $class->reflFields[$class->versionField]->getValue($document); // Throw exception if versions don't match if ($managedCopyVersion !== $documentVersion) { throw LockException::lockFailedVersionMissmatch($document, $documentVersion, $managedCopyVersion); } } // Merge state of $document into existing (managed) document foreach ($class->reflClass->getProperties() as $prop) { $name = $prop->name; $prop->setAccessible(true); if (! isset($class->associationMappings[$name])) { if (! $class->isIdentifier($name)) { $prop->setValue($managedCopy, $prop->getValue($document)); } } else { $assoc2 = $class->associationMappings[$name]; if ($assoc2['type'] === 'one') { $other = $prop->getValue($document); if ($other === null) { $prop->setValue($managedCopy, null); } elseif ($other instanceof GhostObjectInterface && ! $other->isProxyInitialized()) { // Do not merge fields marked lazy that have not been fetched continue; } elseif (! $assoc2['isCascadeMerge']) { if ($this->getDocumentState($other) === self::STATE_DETACHED) { $targetDocument = $assoc2['targetDocument'] ?? get_class($other); /** @var ClassMetadata $targetClass */ $targetClass = $this->dm->getClassMetadata($targetDocument); $relatedId = $targetClass->getIdentifierObject($other); if ($targetClass->subClasses) { $other = $this->dm->find($targetClass->name, $relatedId); } else { $other = $this ->dm ->getProxyFactory() ->getProxy($targetClass, $relatedId); $this->registerManaged($other, $relatedId, []); } } $prop->setValue($managedCopy, $other); } } else { $mergeCol = $prop->getValue($document); if ($mergeCol instanceof PersistentCollectionInterface && ! $mergeCol->isInitialized() && ! $assoc2['isCascadeMerge']) { /* Do not merge fields marked lazy that have not * been fetched. Keep the lazy persistent collection * of the managed copy. */ continue; } $managedCol = $prop->getValue($managedCopy); if (! $managedCol) { $managedCol = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $assoc2, null); $managedCol->setOwner($managedCopy, $assoc2); $prop->setValue($managedCopy, $managedCol); $this->originalDocumentData[$oid][$name] = $managedCol; } /* Note: do not process association's target documents. * They will be handled during the cascade. Initialize * and, if necessary, clear $managedCol for now. */ if ($assoc2['isCascadeMerge']) { $managedCol->initialize(); // If $managedCol differs from the merged collection, clear and set dirty if (! $managedCol->isEmpty() && $managedCol !== $mergeCol) { $managedCol->unwrap()->clear(); $managedCol->setDirty(true); if ($assoc2['isOwningSide'] && $class->isChangeTrackingNotify()) { $this->scheduleForSynchronization($managedCopy); } } } } } if (! $class->isChangeTrackingNotify()) { continue; } // Just treat all properties as changed, there is no other choice. $this->propertyChanged($managedCopy, $name, null, $prop->getValue($managedCopy)); } if ($class->isChangeTrackingDeferredExplicit()) { $this->scheduleForSynchronization($document); } } if ($prevManagedCopy !== null) { $assocField = $assoc['fieldName']; $prevClass = $this->dm->getClassMetadata(get_class($prevManagedCopy)); if ($assoc['type'] === 'one') { $prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy); } else { $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy); if ($assoc['type'] === 'many' && isset($assoc['mappedBy'])) { $class->reflFields[$assoc['mappedBy']]->setValue($managedCopy, $prevManagedCopy); } } } // Mark the managed copy visited as well $visited[spl_object_hash($managedCopy)] = $managedCopy; $this->cascadeMerge($document, $managedCopy, $visited); return $managedCopy; }
php
private function doMerge(object $document, array &$visited, ?object $prevManagedCopy = null, ?array $assoc = null) : object { $oid = spl_object_hash($document); if (isset($visited[$oid])) { return $visited[$oid]; } $visited[$oid] = $document; $class = $this->dm->getClassMetadata(get_class($document)); $managedCopy = $document; if ($this->getDocumentState($document, self::STATE_DETACHED) !== self::STATE_MANAGED) { if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->initializeProxy(); } $identifier = $class->getIdentifier(); $id = $identifier[0] !== null ? $class->getIdentifierObject($document) : null; $managedCopy = null; if (! $class->isEmbeddedDocument && $id !== null) { $managedCopy = $this->dm->find($class->name, $id); if ($managedCopy && $this->getDocumentState($managedCopy) === self::STATE_REMOVED) { throw new InvalidArgumentException('Removed entity detected during merge. Cannot merge with a removed entity.'); } if ($managedCopy instanceof GhostObjectInterface && ! $managedCopy->isProxyInitialized()) { $managedCopy->initializeProxy(); } } if ($managedCopy === null) { $managedCopy = $class->newInstance(); if ($id !== null) { $class->setIdentifierValue($managedCopy, $id); } $this->persistNew($class, $managedCopy); } if ($class->isVersioned) { $managedCopyVersion = $class->reflFields[$class->versionField]->getValue($managedCopy); $documentVersion = $class->reflFields[$class->versionField]->getValue($document); if ($managedCopyVersion !== $documentVersion) { throw LockException::lockFailedVersionMissmatch($document, $documentVersion, $managedCopyVersion); } } foreach ($class->reflClass->getProperties() as $prop) { $name = $prop->name; $prop->setAccessible(true); if (! isset($class->associationMappings[$name])) { if (! $class->isIdentifier($name)) { $prop->setValue($managedCopy, $prop->getValue($document)); } } else { $assoc2 = $class->associationMappings[$name]; if ($assoc2['type'] === 'one') { $other = $prop->getValue($document); if ($other === null) { $prop->setValue($managedCopy, null); } elseif ($other instanceof GhostObjectInterface && ! $other->isProxyInitialized()) { continue; } elseif (! $assoc2['isCascadeMerge']) { if ($this->getDocumentState($other) === self::STATE_DETACHED) { $targetDocument = $assoc2['targetDocument'] ?? get_class($other); $targetClass = $this->dm->getClassMetadata($targetDocument); $relatedId = $targetClass->getIdentifierObject($other); if ($targetClass->subClasses) { $other = $this->dm->find($targetClass->name, $relatedId); } else { $other = $this ->dm ->getProxyFactory() ->getProxy($targetClass, $relatedId); $this->registerManaged($other, $relatedId, []); } } $prop->setValue($managedCopy, $other); } } else { $mergeCol = $prop->getValue($document); if ($mergeCol instanceof PersistentCollectionInterface && ! $mergeCol->isInitialized() && ! $assoc2['isCascadeMerge']) { continue; } $managedCol = $prop->getValue($managedCopy); if (! $managedCol) { $managedCol = $this->dm->getConfiguration()->getPersistentCollectionFactory()->create($this->dm, $assoc2, null); $managedCol->setOwner($managedCopy, $assoc2); $prop->setValue($managedCopy, $managedCol); $this->originalDocumentData[$oid][$name] = $managedCol; } if ($assoc2['isCascadeMerge']) { $managedCol->initialize(); if (! $managedCol->isEmpty() && $managedCol !== $mergeCol) { $managedCol->unwrap()->clear(); $managedCol->setDirty(true); if ($assoc2['isOwningSide'] && $class->isChangeTrackingNotify()) { $this->scheduleForSynchronization($managedCopy); } } } } } if (! $class->isChangeTrackingNotify()) { continue; } $this->propertyChanged($managedCopy, $name, null, $prop->getValue($managedCopy)); } if ($class->isChangeTrackingDeferredExplicit()) { $this->scheduleForSynchronization($document); } } if ($prevManagedCopy !== null) { $assocField = $assoc['fieldName']; $prevClass = $this->dm->getClassMetadata(get_class($prevManagedCopy)); if ($assoc['type'] === 'one') { $prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy); } else { $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->add($managedCopy); if ($assoc['type'] === 'many' && isset($assoc['mappedBy'])) { $class->reflFields[$assoc['mappedBy']]->setValue($managedCopy, $prevManagedCopy); } } } $visited[spl_object_hash($managedCopy)] = $managedCopy; $this->cascadeMerge($document, $managedCopy, $visited); return $managedCopy; }
[ "private", "function", "doMerge", "(", "object", "$", "document", ",", "array", "&", "$", "visited", ",", "?", "object", "$", "prevManagedCopy", "=", "null", ",", "?", "array", "$", "assoc", "=", "null", ")", ":", "object", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "isset", "(", "$", "visited", "[", "$", "oid", "]", ")", ")", "{", "return", "$", "visited", "[", "$", "oid", "]", ";", "// Prevent infinite recursion", "}", "$", "visited", "[", "$", "oid", "]", "=", "$", "document", ";", "// mark visited", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "/* First we assume DETACHED, although it can still be NEW but we can\n * avoid an extra DB round trip this way. If it is not MANAGED but has\n * an identity, we need to fetch it from the DB anyway in order to\n * merge. MANAGED documents are ignored by the merge operation.\n */", "$", "managedCopy", "=", "$", "document", ";", "if", "(", "$", "this", "->", "getDocumentState", "(", "$", "document", ",", "self", "::", "STATE_DETACHED", ")", "!==", "self", "::", "STATE_MANAGED", ")", "{", "if", "(", "$", "document", "instanceof", "GhostObjectInterface", "&&", "!", "$", "document", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "document", "->", "initializeProxy", "(", ")", ";", "}", "$", "identifier", "=", "$", "class", "->", "getIdentifier", "(", ")", ";", "// We always have one element in the identifier array but it might be null", "$", "id", "=", "$", "identifier", "[", "0", "]", "!==", "null", "?", "$", "class", "->", "getIdentifierObject", "(", "$", "document", ")", ":", "null", ";", "$", "managedCopy", "=", "null", ";", "// Try to fetch document from the database", "if", "(", "!", "$", "class", "->", "isEmbeddedDocument", "&&", "$", "id", "!==", "null", ")", "{", "$", "managedCopy", "=", "$", "this", "->", "dm", "->", "find", "(", "$", "class", "->", "name", ",", "$", "id", ")", ";", "// Managed copy may be removed in which case we can't merge", "if", "(", "$", "managedCopy", "&&", "$", "this", "->", "getDocumentState", "(", "$", "managedCopy", ")", "===", "self", "::", "STATE_REMOVED", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Removed entity detected during merge. Cannot merge with a removed entity.'", ")", ";", "}", "if", "(", "$", "managedCopy", "instanceof", "GhostObjectInterface", "&&", "!", "$", "managedCopy", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "managedCopy", "->", "initializeProxy", "(", ")", ";", "}", "}", "if", "(", "$", "managedCopy", "===", "null", ")", "{", "// Create a new managed instance", "$", "managedCopy", "=", "$", "class", "->", "newInstance", "(", ")", ";", "if", "(", "$", "id", "!==", "null", ")", "{", "$", "class", "->", "setIdentifierValue", "(", "$", "managedCopy", ",", "$", "id", ")", ";", "}", "$", "this", "->", "persistNew", "(", "$", "class", ",", "$", "managedCopy", ")", ";", "}", "if", "(", "$", "class", "->", "isVersioned", ")", "{", "$", "managedCopyVersion", "=", "$", "class", "->", "reflFields", "[", "$", "class", "->", "versionField", "]", "->", "getValue", "(", "$", "managedCopy", ")", ";", "$", "documentVersion", "=", "$", "class", "->", "reflFields", "[", "$", "class", "->", "versionField", "]", "->", "getValue", "(", "$", "document", ")", ";", "// Throw exception if versions don't match", "if", "(", "$", "managedCopyVersion", "!==", "$", "documentVersion", ")", "{", "throw", "LockException", "::", "lockFailedVersionMissmatch", "(", "$", "document", ",", "$", "documentVersion", ",", "$", "managedCopyVersion", ")", ";", "}", "}", "// Merge state of $document into existing (managed) document", "foreach", "(", "$", "class", "->", "reflClass", "->", "getProperties", "(", ")", "as", "$", "prop", ")", "{", "$", "name", "=", "$", "prop", "->", "name", ";", "$", "prop", "->", "setAccessible", "(", "true", ")", ";", "if", "(", "!", "isset", "(", "$", "class", "->", "associationMappings", "[", "$", "name", "]", ")", ")", "{", "if", "(", "!", "$", "class", "->", "isIdentifier", "(", "$", "name", ")", ")", "{", "$", "prop", "->", "setValue", "(", "$", "managedCopy", ",", "$", "prop", "->", "getValue", "(", "$", "document", ")", ")", ";", "}", "}", "else", "{", "$", "assoc2", "=", "$", "class", "->", "associationMappings", "[", "$", "name", "]", ";", "if", "(", "$", "assoc2", "[", "'type'", "]", "===", "'one'", ")", "{", "$", "other", "=", "$", "prop", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "other", "===", "null", ")", "{", "$", "prop", "->", "setValue", "(", "$", "managedCopy", ",", "null", ")", ";", "}", "elseif", "(", "$", "other", "instanceof", "GhostObjectInterface", "&&", "!", "$", "other", "->", "isProxyInitialized", "(", ")", ")", "{", "// Do not merge fields marked lazy that have not been fetched", "continue", ";", "}", "elseif", "(", "!", "$", "assoc2", "[", "'isCascadeMerge'", "]", ")", "{", "if", "(", "$", "this", "->", "getDocumentState", "(", "$", "other", ")", "===", "self", "::", "STATE_DETACHED", ")", "{", "$", "targetDocument", "=", "$", "assoc2", "[", "'targetDocument'", "]", "??", "get_class", "(", "$", "other", ")", ";", "/** @var ClassMetadata $targetClass */", "$", "targetClass", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "targetDocument", ")", ";", "$", "relatedId", "=", "$", "targetClass", "->", "getIdentifierObject", "(", "$", "other", ")", ";", "if", "(", "$", "targetClass", "->", "subClasses", ")", "{", "$", "other", "=", "$", "this", "->", "dm", "->", "find", "(", "$", "targetClass", "->", "name", ",", "$", "relatedId", ")", ";", "}", "else", "{", "$", "other", "=", "$", "this", "->", "dm", "->", "getProxyFactory", "(", ")", "->", "getProxy", "(", "$", "targetClass", ",", "$", "relatedId", ")", ";", "$", "this", "->", "registerManaged", "(", "$", "other", ",", "$", "relatedId", ",", "[", "]", ")", ";", "}", "}", "$", "prop", "->", "setValue", "(", "$", "managedCopy", ",", "$", "other", ")", ";", "}", "}", "else", "{", "$", "mergeCol", "=", "$", "prop", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "mergeCol", "instanceof", "PersistentCollectionInterface", "&&", "!", "$", "mergeCol", "->", "isInitialized", "(", ")", "&&", "!", "$", "assoc2", "[", "'isCascadeMerge'", "]", ")", "{", "/* Do not merge fields marked lazy that have not\n * been fetched. Keep the lazy persistent collection\n * of the managed copy.\n */", "continue", ";", "}", "$", "managedCol", "=", "$", "prop", "->", "getValue", "(", "$", "managedCopy", ")", ";", "if", "(", "!", "$", "managedCol", ")", "{", "$", "managedCol", "=", "$", "this", "->", "dm", "->", "getConfiguration", "(", ")", "->", "getPersistentCollectionFactory", "(", ")", "->", "create", "(", "$", "this", "->", "dm", ",", "$", "assoc2", ",", "null", ")", ";", "$", "managedCol", "->", "setOwner", "(", "$", "managedCopy", ",", "$", "assoc2", ")", ";", "$", "prop", "->", "setValue", "(", "$", "managedCopy", ",", "$", "managedCol", ")", ";", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", "[", "$", "name", "]", "=", "$", "managedCol", ";", "}", "/* Note: do not process association's target documents.\n * They will be handled during the cascade. Initialize\n * and, if necessary, clear $managedCol for now.\n */", "if", "(", "$", "assoc2", "[", "'isCascadeMerge'", "]", ")", "{", "$", "managedCol", "->", "initialize", "(", ")", ";", "// If $managedCol differs from the merged collection, clear and set dirty", "if", "(", "!", "$", "managedCol", "->", "isEmpty", "(", ")", "&&", "$", "managedCol", "!==", "$", "mergeCol", ")", "{", "$", "managedCol", "->", "unwrap", "(", ")", "->", "clear", "(", ")", ";", "$", "managedCol", "->", "setDirty", "(", "true", ")", ";", "if", "(", "$", "assoc2", "[", "'isOwningSide'", "]", "&&", "$", "class", "->", "isChangeTrackingNotify", "(", ")", ")", "{", "$", "this", "->", "scheduleForSynchronization", "(", "$", "managedCopy", ")", ";", "}", "}", "}", "}", "}", "if", "(", "!", "$", "class", "->", "isChangeTrackingNotify", "(", ")", ")", "{", "continue", ";", "}", "// Just treat all properties as changed, there is no other choice.", "$", "this", "->", "propertyChanged", "(", "$", "managedCopy", ",", "$", "name", ",", "null", ",", "$", "prop", "->", "getValue", "(", "$", "managedCopy", ")", ")", ";", "}", "if", "(", "$", "class", "->", "isChangeTrackingDeferredExplicit", "(", ")", ")", "{", "$", "this", "->", "scheduleForSynchronization", "(", "$", "document", ")", ";", "}", "}", "if", "(", "$", "prevManagedCopy", "!==", "null", ")", "{", "$", "assocField", "=", "$", "assoc", "[", "'fieldName'", "]", ";", "$", "prevClass", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "prevManagedCopy", ")", ")", ";", "if", "(", "$", "assoc", "[", "'type'", "]", "===", "'one'", ")", "{", "$", "prevClass", "->", "reflFields", "[", "$", "assocField", "]", "->", "setValue", "(", "$", "prevManagedCopy", ",", "$", "managedCopy", ")", ";", "}", "else", "{", "$", "prevClass", "->", "reflFields", "[", "$", "assocField", "]", "->", "getValue", "(", "$", "prevManagedCopy", ")", "->", "add", "(", "$", "managedCopy", ")", ";", "if", "(", "$", "assoc", "[", "'type'", "]", "===", "'many'", "&&", "isset", "(", "$", "assoc", "[", "'mappedBy'", "]", ")", ")", "{", "$", "class", "->", "reflFields", "[", "$", "assoc", "[", "'mappedBy'", "]", "]", "->", "setValue", "(", "$", "managedCopy", ",", "$", "prevManagedCopy", ")", ";", "}", "}", "}", "// Mark the managed copy visited as well", "$", "visited", "[", "spl_object_hash", "(", "$", "managedCopy", ")", "]", "=", "$", "managedCopy", ";", "$", "this", "->", "cascadeMerge", "(", "$", "document", ",", "$", "managedCopy", ",", "$", "visited", ")", ";", "return", "$", "managedCopy", ";", "}" ]
Executes a merge operation on a document. @throws InvalidArgumentException If the entity instance is NEW. @throws LockException If the document uses optimistic locking through a version attribute and the version check against the managed copy fails.
[ "Executes", "a", "merge", "operation", "on", "a", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1689-L1864
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.cascadeRefresh
private function cascadeRefresh(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return $assoc['isCascadeRefresh']; } ); foreach ($associationMappings as $mapping) { $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments instanceof PersistentCollectionInterface) { // Unwrap so that foreach() does not initialize $relatedDocuments = $relatedDocuments->unwrap(); } foreach ($relatedDocuments as $relatedDocument) { $this->doRefresh($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { $this->doRefresh($relatedDocuments, $visited); } } }
php
private function cascadeRefresh(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return $assoc['isCascadeRefresh']; } ); foreach ($associationMappings as $mapping) { $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments instanceof PersistentCollectionInterface) { $relatedDocuments = $relatedDocuments->unwrap(); } foreach ($relatedDocuments as $relatedDocument) { $this->doRefresh($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { $this->doRefresh($relatedDocuments, $visited); } } }
[ "private", "function", "cascadeRefresh", "(", "object", "$", "document", ",", "array", "&", "$", "visited", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "associationMappings", "=", "array_filter", "(", "$", "class", "->", "associationMappings", ",", "static", "function", "(", "$", "assoc", ")", "{", "return", "$", "assoc", "[", "'isCascadeRefresh'", "]", ";", "}", ")", ";", "foreach", "(", "$", "associationMappings", "as", "$", "mapping", ")", "{", "$", "relatedDocuments", "=", "$", "class", "->", "reflFields", "[", "$", "mapping", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "relatedDocuments", "instanceof", "Collection", "||", "is_array", "(", "$", "relatedDocuments", ")", ")", "{", "if", "(", "$", "relatedDocuments", "instanceof", "PersistentCollectionInterface", ")", "{", "// Unwrap so that foreach() does not initialize", "$", "relatedDocuments", "=", "$", "relatedDocuments", "->", "unwrap", "(", ")", ";", "}", "foreach", "(", "$", "relatedDocuments", "as", "$", "relatedDocument", ")", "{", "$", "this", "->", "doRefresh", "(", "$", "relatedDocument", ",", "$", "visited", ")", ";", "}", "}", "elseif", "(", "$", "relatedDocuments", "!==", "null", ")", "{", "$", "this", "->", "doRefresh", "(", "$", "relatedDocuments", ",", "$", "visited", ")", ";", "}", "}", "}" ]
Cascades a refresh operation to associated documents.
[ "Cascades", "a", "refresh", "operation", "to", "associated", "documents", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1960-L1985
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.cascadeDetach
private function cascadeDetach(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); foreach ($class->fieldMappings as $mapping) { if (! $mapping['isCascadeDetach']) { continue; } $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments instanceof PersistentCollectionInterface) { // Unwrap so that foreach() does not initialize $relatedDocuments = $relatedDocuments->unwrap(); } foreach ($relatedDocuments as $relatedDocument) { $this->doDetach($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { $this->doDetach($relatedDocuments, $visited); } } }
php
private function cascadeDetach(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); foreach ($class->fieldMappings as $mapping) { if (! $mapping['isCascadeDetach']) { continue; } $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments instanceof PersistentCollectionInterface) { $relatedDocuments = $relatedDocuments->unwrap(); } foreach ($relatedDocuments as $relatedDocument) { $this->doDetach($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { $this->doDetach($relatedDocuments, $visited); } } }
[ "private", "function", "cascadeDetach", "(", "object", "$", "document", ",", "array", "&", "$", "visited", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "foreach", "(", "$", "class", "->", "fieldMappings", "as", "$", "mapping", ")", "{", "if", "(", "!", "$", "mapping", "[", "'isCascadeDetach'", "]", ")", "{", "continue", ";", "}", "$", "relatedDocuments", "=", "$", "class", "->", "reflFields", "[", "$", "mapping", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "relatedDocuments", "instanceof", "Collection", "||", "is_array", "(", "$", "relatedDocuments", ")", ")", "{", "if", "(", "$", "relatedDocuments", "instanceof", "PersistentCollectionInterface", ")", "{", "// Unwrap so that foreach() does not initialize", "$", "relatedDocuments", "=", "$", "relatedDocuments", "->", "unwrap", "(", ")", ";", "}", "foreach", "(", "$", "relatedDocuments", "as", "$", "relatedDocument", ")", "{", "$", "this", "->", "doDetach", "(", "$", "relatedDocument", ",", "$", "visited", ")", ";", "}", "}", "elseif", "(", "$", "relatedDocuments", "!==", "null", ")", "{", "$", "this", "->", "doDetach", "(", "$", "relatedDocuments", ",", "$", "visited", ")", ";", "}", "}", "}" ]
Cascades a detach operation to associated documents.
[ "Cascades", "a", "detach", "operation", "to", "associated", "documents", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L1990-L2010
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.cascadeMerge
private function cascadeMerge(object $document, object $managedCopy, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return $assoc['isCascadeMerge']; } ); foreach ($associationMappings as $assoc) { $relatedDocuments = $class->reflFields[$assoc['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments === $class->reflFields[$assoc['fieldName']]->getValue($managedCopy)) { // Collections are the same, so there is nothing to do continue; } foreach ($relatedDocuments as $relatedDocument) { $this->doMerge($relatedDocument, $visited, $managedCopy, $assoc); } } elseif ($relatedDocuments !== null) { $this->doMerge($relatedDocuments, $visited, $managedCopy, $assoc); } } }
php
private function cascadeMerge(object $document, object $managedCopy, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return $assoc['isCascadeMerge']; } ); foreach ($associationMappings as $assoc) { $relatedDocuments = $class->reflFields[$assoc['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments === $class->reflFields[$assoc['fieldName']]->getValue($managedCopy)) { continue; } foreach ($relatedDocuments as $relatedDocument) { $this->doMerge($relatedDocument, $visited, $managedCopy, $assoc); } } elseif ($relatedDocuments !== null) { $this->doMerge($relatedDocuments, $visited, $managedCopy, $assoc); } } }
[ "private", "function", "cascadeMerge", "(", "object", "$", "document", ",", "object", "$", "managedCopy", ",", "array", "&", "$", "visited", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "associationMappings", "=", "array_filter", "(", "$", "class", "->", "associationMappings", ",", "static", "function", "(", "$", "assoc", ")", "{", "return", "$", "assoc", "[", "'isCascadeMerge'", "]", ";", "}", ")", ";", "foreach", "(", "$", "associationMappings", "as", "$", "assoc", ")", "{", "$", "relatedDocuments", "=", "$", "class", "->", "reflFields", "[", "$", "assoc", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "relatedDocuments", "instanceof", "Collection", "||", "is_array", "(", "$", "relatedDocuments", ")", ")", "{", "if", "(", "$", "relatedDocuments", "===", "$", "class", "->", "reflFields", "[", "$", "assoc", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "managedCopy", ")", ")", "{", "// Collections are the same, so there is nothing to do", "continue", ";", "}", "foreach", "(", "$", "relatedDocuments", "as", "$", "relatedDocument", ")", "{", "$", "this", "->", "doMerge", "(", "$", "relatedDocument", ",", "$", "visited", ",", "$", "managedCopy", ",", "$", "assoc", ")", ";", "}", "}", "elseif", "(", "$", "relatedDocuments", "!==", "null", ")", "{", "$", "this", "->", "doMerge", "(", "$", "relatedDocuments", ",", "$", "visited", ",", "$", "managedCopy", ",", "$", "assoc", ")", ";", "}", "}", "}" ]
Cascades a merge operation to associated documents.
[ "Cascades", "a", "merge", "operation", "to", "associated", "documents", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2014-L2041
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.cascadePersist
private function cascadePersist(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return $assoc['isCascadePersist']; } ); foreach ($associationMappings as $fieldName => $mapping) { $relatedDocuments = $class->reflFields[$fieldName]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments instanceof PersistentCollectionInterface) { if ($relatedDocuments->getOwner() !== $document) { $relatedDocuments = $this->fixPersistentCollectionOwnership($relatedDocuments, $document, $class, $mapping['fieldName']); } // Unwrap so that foreach() does not initialize $relatedDocuments = $relatedDocuments->unwrap(); } $count = 0; foreach ($relatedDocuments as $relatedKey => $relatedDocument) { if (! empty($mapping['embedded'])) { [, $knownParent ] = $this->getParentAssociation($relatedDocument); if ($knownParent && $knownParent !== $document) { $relatedDocument = clone $relatedDocument; $relatedDocuments[$relatedKey] = $relatedDocument; } $pathKey = CollectionHelper::isList($mapping['strategy']) ? $count++ : $relatedKey; $this->setParentAssociation($relatedDocument, $mapping, $document, $mapping['fieldName'] . '.' . $pathKey); } $this->doPersist($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { if (! empty($mapping['embedded'])) { [, $knownParent ] = $this->getParentAssociation($relatedDocuments); if ($knownParent && $knownParent !== $document) { $relatedDocuments = clone $relatedDocuments; $class->setFieldValue($document, $mapping['fieldName'], $relatedDocuments); } $this->setParentAssociation($relatedDocuments, $mapping, $document, $mapping['fieldName']); } $this->doPersist($relatedDocuments, $visited); } } }
php
private function cascadePersist(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); $associationMappings = array_filter( $class->associationMappings, static function ($assoc) { return $assoc['isCascadePersist']; } ); foreach ($associationMappings as $fieldName => $mapping) { $relatedDocuments = $class->reflFields[$fieldName]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { if ($relatedDocuments instanceof PersistentCollectionInterface) { if ($relatedDocuments->getOwner() !== $document) { $relatedDocuments = $this->fixPersistentCollectionOwnership($relatedDocuments, $document, $class, $mapping['fieldName']); } $relatedDocuments = $relatedDocuments->unwrap(); } $count = 0; foreach ($relatedDocuments as $relatedKey => $relatedDocument) { if (! empty($mapping['embedded'])) { [, $knownParent ] = $this->getParentAssociation($relatedDocument); if ($knownParent && $knownParent !== $document) { $relatedDocument = clone $relatedDocument; $relatedDocuments[$relatedKey] = $relatedDocument; } $pathKey = CollectionHelper::isList($mapping['strategy']) ? $count++ : $relatedKey; $this->setParentAssociation($relatedDocument, $mapping, $document, $mapping['fieldName'] . '.' . $pathKey); } $this->doPersist($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { if (! empty($mapping['embedded'])) { [, $knownParent ] = $this->getParentAssociation($relatedDocuments); if ($knownParent && $knownParent !== $document) { $relatedDocuments = clone $relatedDocuments; $class->setFieldValue($document, $mapping['fieldName'], $relatedDocuments); } $this->setParentAssociation($relatedDocuments, $mapping, $document, $mapping['fieldName']); } $this->doPersist($relatedDocuments, $visited); } } }
[ "private", "function", "cascadePersist", "(", "object", "$", "document", ",", "array", "&", "$", "visited", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "associationMappings", "=", "array_filter", "(", "$", "class", "->", "associationMappings", ",", "static", "function", "(", "$", "assoc", ")", "{", "return", "$", "assoc", "[", "'isCascadePersist'", "]", ";", "}", ")", ";", "foreach", "(", "$", "associationMappings", "as", "$", "fieldName", "=>", "$", "mapping", ")", "{", "$", "relatedDocuments", "=", "$", "class", "->", "reflFields", "[", "$", "fieldName", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "relatedDocuments", "instanceof", "Collection", "||", "is_array", "(", "$", "relatedDocuments", ")", ")", "{", "if", "(", "$", "relatedDocuments", "instanceof", "PersistentCollectionInterface", ")", "{", "if", "(", "$", "relatedDocuments", "->", "getOwner", "(", ")", "!==", "$", "document", ")", "{", "$", "relatedDocuments", "=", "$", "this", "->", "fixPersistentCollectionOwnership", "(", "$", "relatedDocuments", ",", "$", "document", ",", "$", "class", ",", "$", "mapping", "[", "'fieldName'", "]", ")", ";", "}", "// Unwrap so that foreach() does not initialize", "$", "relatedDocuments", "=", "$", "relatedDocuments", "->", "unwrap", "(", ")", ";", "}", "$", "count", "=", "0", ";", "foreach", "(", "$", "relatedDocuments", "as", "$", "relatedKey", "=>", "$", "relatedDocument", ")", "{", "if", "(", "!", "empty", "(", "$", "mapping", "[", "'embedded'", "]", ")", ")", "{", "[", ",", "$", "knownParent", "]", "=", "$", "this", "->", "getParentAssociation", "(", "$", "relatedDocument", ")", ";", "if", "(", "$", "knownParent", "&&", "$", "knownParent", "!==", "$", "document", ")", "{", "$", "relatedDocument", "=", "clone", "$", "relatedDocument", ";", "$", "relatedDocuments", "[", "$", "relatedKey", "]", "=", "$", "relatedDocument", ";", "}", "$", "pathKey", "=", "CollectionHelper", "::", "isList", "(", "$", "mapping", "[", "'strategy'", "]", ")", "?", "$", "count", "++", ":", "$", "relatedKey", ";", "$", "this", "->", "setParentAssociation", "(", "$", "relatedDocument", ",", "$", "mapping", ",", "$", "document", ",", "$", "mapping", "[", "'fieldName'", "]", ".", "'.'", ".", "$", "pathKey", ")", ";", "}", "$", "this", "->", "doPersist", "(", "$", "relatedDocument", ",", "$", "visited", ")", ";", "}", "}", "elseif", "(", "$", "relatedDocuments", "!==", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "mapping", "[", "'embedded'", "]", ")", ")", "{", "[", ",", "$", "knownParent", "]", "=", "$", "this", "->", "getParentAssociation", "(", "$", "relatedDocuments", ")", ";", "if", "(", "$", "knownParent", "&&", "$", "knownParent", "!==", "$", "document", ")", "{", "$", "relatedDocuments", "=", "clone", "$", "relatedDocuments", ";", "$", "class", "->", "setFieldValue", "(", "$", "document", ",", "$", "mapping", "[", "'fieldName'", "]", ",", "$", "relatedDocuments", ")", ";", "}", "$", "this", "->", "setParentAssociation", "(", "$", "relatedDocuments", ",", "$", "mapping", ",", "$", "document", ",", "$", "mapping", "[", "'fieldName'", "]", ")", ";", "}", "$", "this", "->", "doPersist", "(", "$", "relatedDocuments", ",", "$", "visited", ")", ";", "}", "}", "}" ]
Cascades the save operation to associated documents.
[ "Cascades", "the", "save", "operation", "to", "associated", "documents", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2046-L2094
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.cascadeRemove
private function cascadeRemove(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); foreach ($class->fieldMappings as $mapping) { if (! $mapping['isCascadeRemove'] && ( ! isset($mapping['orphanRemoval']) || ! $mapping['orphanRemoval'])) { continue; } if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->initializeProxy(); } $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { // If its a PersistentCollection initialization is intended! No unwrap! foreach ($relatedDocuments as $relatedDocument) { $this->doRemove($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { $this->doRemove($relatedDocuments, $visited); } } }
php
private function cascadeRemove(object $document, array &$visited) : void { $class = $this->dm->getClassMetadata(get_class($document)); foreach ($class->fieldMappings as $mapping) { if (! $mapping['isCascadeRemove'] && ( ! isset($mapping['orphanRemoval']) || ! $mapping['orphanRemoval'])) { continue; } if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->initializeProxy(); } $relatedDocuments = $class->reflFields[$mapping['fieldName']]->getValue($document); if ($relatedDocuments instanceof Collection || is_array($relatedDocuments)) { foreach ($relatedDocuments as $relatedDocument) { $this->doRemove($relatedDocument, $visited); } } elseif ($relatedDocuments !== null) { $this->doRemove($relatedDocuments, $visited); } } }
[ "private", "function", "cascadeRemove", "(", "object", "$", "document", ",", "array", "&", "$", "visited", ")", ":", "void", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "foreach", "(", "$", "class", "->", "fieldMappings", "as", "$", "mapping", ")", "{", "if", "(", "!", "$", "mapping", "[", "'isCascadeRemove'", "]", "&&", "(", "!", "isset", "(", "$", "mapping", "[", "'orphanRemoval'", "]", ")", "||", "!", "$", "mapping", "[", "'orphanRemoval'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "document", "instanceof", "GhostObjectInterface", "&&", "!", "$", "document", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "document", "->", "initializeProxy", "(", ")", ";", "}", "$", "relatedDocuments", "=", "$", "class", "->", "reflFields", "[", "$", "mapping", "[", "'fieldName'", "]", "]", "->", "getValue", "(", "$", "document", ")", ";", "if", "(", "$", "relatedDocuments", "instanceof", "Collection", "||", "is_array", "(", "$", "relatedDocuments", ")", ")", "{", "// If its a PersistentCollection initialization is intended! No unwrap!", "foreach", "(", "$", "relatedDocuments", "as", "$", "relatedDocument", ")", "{", "$", "this", "->", "doRemove", "(", "$", "relatedDocument", ",", "$", "visited", ")", ";", "}", "}", "elseif", "(", "$", "relatedDocuments", "!==", "null", ")", "{", "$", "this", "->", "doRemove", "(", "$", "relatedDocuments", ",", "$", "visited", ")", ";", "}", "}", "}" ]
Cascades the delete operation to associated documents.
[ "Cascades", "the", "delete", "operation", "to", "associated", "documents", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2099-L2120
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.unscheduleOrphanRemoval
public function unscheduleOrphanRemoval(object $document) : void { $oid = spl_object_hash($document); unset($this->orphanRemovals[$oid]); }
php
public function unscheduleOrphanRemoval(object $document) : void { $oid = spl_object_hash($document); unset($this->orphanRemovals[$oid]); }
[ "public", "function", "unscheduleOrphanRemoval", "(", "object", "$", "document", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "unset", "(", "$", "this", "->", "orphanRemovals", "[", "$", "oid", "]", ")", ";", "}" ]
Unschedules an embedded or referenced object for removal. @internal
[ "Unschedules", "an", "embedded", "or", "referenced", "object", "for", "removal", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2232-L2236
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.fixPersistentCollectionOwnership
private function fixPersistentCollectionOwnership(PersistentCollectionInterface $coll, object $document, ClassMetadata $class, string $propName) : PersistentCollectionInterface { $owner = $coll->getOwner(); if ($owner === null) { // cloned $coll->setOwner($document, $class->fieldMappings[$propName]); } elseif ($owner !== $document) { // no clone, we have to fix if (! $coll->isInitialized()) { $coll->initialize(); // we have to do this otherwise the cols share state } $newValue = clone $coll; $newValue->setOwner($document, $class->fieldMappings[$propName]); $class->reflFields[$propName]->setValue($document, $newValue); if ($this->isScheduledForUpdate($document)) { // @todo following line should be superfluous once collections are stored in change sets $this->setOriginalDocumentProperty(spl_object_hash($document), $propName, $newValue); } return $newValue; } return $coll; }
php
private function fixPersistentCollectionOwnership(PersistentCollectionInterface $coll, object $document, ClassMetadata $class, string $propName) : PersistentCollectionInterface { $owner = $coll->getOwner(); if ($owner === null) { $coll->setOwner($document, $class->fieldMappings[$propName]); } elseif ($owner !== $document) { if (! $coll->isInitialized()) { $coll->initialize(); } $newValue = clone $coll; $newValue->setOwner($document, $class->fieldMappings[$propName]); $class->reflFields[$propName]->setValue($document, $newValue); if ($this->isScheduledForUpdate($document)) { $this->setOriginalDocumentProperty(spl_object_hash($document), $propName, $newValue); } return $newValue; } return $coll; }
[ "private", "function", "fixPersistentCollectionOwnership", "(", "PersistentCollectionInterface", "$", "coll", ",", "object", "$", "document", ",", "ClassMetadata", "$", "class", ",", "string", "$", "propName", ")", ":", "PersistentCollectionInterface", "{", "$", "owner", "=", "$", "coll", "->", "getOwner", "(", ")", ";", "if", "(", "$", "owner", "===", "null", ")", "{", "// cloned", "$", "coll", "->", "setOwner", "(", "$", "document", ",", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", ")", ";", "}", "elseif", "(", "$", "owner", "!==", "$", "document", ")", "{", "// no clone, we have to fix", "if", "(", "!", "$", "coll", "->", "isInitialized", "(", ")", ")", "{", "$", "coll", "->", "initialize", "(", ")", ";", "// we have to do this otherwise the cols share state", "}", "$", "newValue", "=", "clone", "$", "coll", ";", "$", "newValue", "->", "setOwner", "(", "$", "document", ",", "$", "class", "->", "fieldMappings", "[", "$", "propName", "]", ")", ";", "$", "class", "->", "reflFields", "[", "$", "propName", "]", "->", "setValue", "(", "$", "document", ",", "$", "newValue", ")", ";", "if", "(", "$", "this", "->", "isScheduledForUpdate", "(", "$", "document", ")", ")", "{", "// @todo following line should be superfluous once collections are stored in change sets", "$", "this", "->", "setOriginalDocumentProperty", "(", "spl_object_hash", "(", "$", "document", ")", ",", "$", "propName", ",", "$", "newValue", ")", ";", "}", "return", "$", "newValue", ";", "}", "return", "$", "coll", ";", "}" ]
Fixes PersistentCollection state if it wasn't used exactly as we had in mind: 1) sets owner if it was cloned 2) clones collection, sets owner, updates document's property and, if necessary, updates originalData 3) NOP if state is OK Returned collection should be used from now on (only important with 2nd point)
[ "Fixes", "PersistentCollection", "state", "if", "it", "wasn", "t", "used", "exactly", "as", "we", "had", "in", "mind", ":", "1", ")", "sets", "owner", "if", "it", "was", "cloned", "2", ")", "clones", "collection", "sets", "owner", "updates", "document", "s", "property", "and", "if", "necessary", "updates", "originalData", "3", ")", "NOP", "if", "state", "is", "OK", "Returned", "collection", "should", "be", "used", "from", "now", "on", "(", "only", "important", "with", "2nd", "point", ")" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2245-L2264
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleCollectionDeletion
public function scheduleCollectionDeletion(PersistentCollectionInterface $coll) : void { $oid = spl_object_hash($coll); unset($this->collectionUpdates[$oid]); if (isset($this->collectionDeletions[$oid])) { return; } $this->collectionDeletions[$oid] = $coll; $this->scheduleCollectionOwner($coll); }
php
public function scheduleCollectionDeletion(PersistentCollectionInterface $coll) : void { $oid = spl_object_hash($coll); unset($this->collectionUpdates[$oid]); if (isset($this->collectionDeletions[$oid])) { return; } $this->collectionDeletions[$oid] = $coll; $this->scheduleCollectionOwner($coll); }
[ "public", "function", "scheduleCollectionDeletion", "(", "PersistentCollectionInterface", "$", "coll", ")", ":", "void", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "coll", ")", ";", "unset", "(", "$", "this", "->", "collectionUpdates", "[", "$", "oid", "]", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "collectionDeletions", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "collectionDeletions", "[", "$", "oid", "]", "=", "$", "coll", ";", "$", "this", "->", "scheduleCollectionOwner", "(", "$", "coll", ")", ";", "}" ]
Schedules a complete collection for removal when this UnitOfWork commits. @internal
[ "Schedules", "a", "complete", "collection", "for", "removal", "when", "this", "UnitOfWork", "commits", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2271-L2281
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.unscheduleCollectionDeletion
public function unscheduleCollectionDeletion(PersistentCollectionInterface $coll) : void { if ($coll->getOwner() === null) { return; } $oid = spl_object_hash($coll); if (! isset($this->collectionDeletions[$oid])) { return; } $topmostOwner = $this->getOwningDocument($coll->getOwner()); unset($this->collectionDeletions[$oid]); unset($this->hasScheduledCollections[spl_object_hash($topmostOwner)][$oid]); }
php
public function unscheduleCollectionDeletion(PersistentCollectionInterface $coll) : void { if ($coll->getOwner() === null) { return; } $oid = spl_object_hash($coll); if (! isset($this->collectionDeletions[$oid])) { return; } $topmostOwner = $this->getOwningDocument($coll->getOwner()); unset($this->collectionDeletions[$oid]); unset($this->hasScheduledCollections[spl_object_hash($topmostOwner)][$oid]); }
[ "public", "function", "unscheduleCollectionDeletion", "(", "PersistentCollectionInterface", "$", "coll", ")", ":", "void", "{", "if", "(", "$", "coll", "->", "getOwner", "(", ")", "===", "null", ")", "{", "return", ";", "}", "$", "oid", "=", "spl_object_hash", "(", "$", "coll", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "collectionDeletions", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "topmostOwner", "=", "$", "this", "->", "getOwningDocument", "(", "$", "coll", "->", "getOwner", "(", ")", ")", ";", "unset", "(", "$", "this", "->", "collectionDeletions", "[", "$", "oid", "]", ")", ";", "unset", "(", "$", "this", "->", "hasScheduledCollections", "[", "spl_object_hash", "(", "$", "topmostOwner", ")", "]", "[", "$", "oid", "]", ")", ";", "}" ]
Unschedules a collection from being deleted when this UnitOfWork commits. @internal
[ "Unschedules", "a", "collection", "from", "being", "deleted", "when", "this", "UnitOfWork", "commits", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2298-L2312
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleCollectionUpdate
public function scheduleCollectionUpdate(PersistentCollectionInterface $coll) : void { $mapping = $coll->getMapping(); if (CollectionHelper::usesSet($mapping['strategy'])) { /* There is no need to $unset collection if it will be $set later * This is NOP if collection is not scheduled for deletion */ $this->unscheduleCollectionDeletion($coll); } $oid = spl_object_hash($coll); if (isset($this->collectionUpdates[$oid])) { return; } $this->collectionUpdates[$oid] = $coll; $this->scheduleCollectionOwner($coll); }
php
public function scheduleCollectionUpdate(PersistentCollectionInterface $coll) : void { $mapping = $coll->getMapping(); if (CollectionHelper::usesSet($mapping['strategy'])) { $this->unscheduleCollectionDeletion($coll); } $oid = spl_object_hash($coll); if (isset($this->collectionUpdates[$oid])) { return; } $this->collectionUpdates[$oid] = $coll; $this->scheduleCollectionOwner($coll); }
[ "public", "function", "scheduleCollectionUpdate", "(", "PersistentCollectionInterface", "$", "coll", ")", ":", "void", "{", "$", "mapping", "=", "$", "coll", "->", "getMapping", "(", ")", ";", "if", "(", "CollectionHelper", "::", "usesSet", "(", "$", "mapping", "[", "'strategy'", "]", ")", ")", "{", "/* There is no need to $unset collection if it will be $set later\n * This is NOP if collection is not scheduled for deletion\n */", "$", "this", "->", "unscheduleCollectionDeletion", "(", "$", "coll", ")", ";", "}", "$", "oid", "=", "spl_object_hash", "(", "$", "coll", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "collectionUpdates", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "collectionUpdates", "[", "$", "oid", "]", "=", "$", "coll", ";", "$", "this", "->", "scheduleCollectionOwner", "(", "$", "coll", ")", ";", "}" ]
Schedules a collection for update when this UnitOfWork commits. @internal
[ "Schedules", "a", "collection", "for", "update", "when", "this", "UnitOfWork", "commits", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2319-L2335
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.unscheduleCollectionUpdate
public function unscheduleCollectionUpdate(PersistentCollectionInterface $coll) : void { if ($coll->getOwner() === null) { return; } $oid = spl_object_hash($coll); if (! isset($this->collectionUpdates[$oid])) { return; } $topmostOwner = $this->getOwningDocument($coll->getOwner()); unset($this->collectionUpdates[$oid]); unset($this->hasScheduledCollections[spl_object_hash($topmostOwner)][$oid]); }
php
public function unscheduleCollectionUpdate(PersistentCollectionInterface $coll) : void { if ($coll->getOwner() === null) { return; } $oid = spl_object_hash($coll); if (! isset($this->collectionUpdates[$oid])) { return; } $topmostOwner = $this->getOwningDocument($coll->getOwner()); unset($this->collectionUpdates[$oid]); unset($this->hasScheduledCollections[spl_object_hash($topmostOwner)][$oid]); }
[ "public", "function", "unscheduleCollectionUpdate", "(", "PersistentCollectionInterface", "$", "coll", ")", ":", "void", "{", "if", "(", "$", "coll", "->", "getOwner", "(", ")", "===", "null", ")", "{", "return", ";", "}", "$", "oid", "=", "spl_object_hash", "(", "$", "coll", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "collectionUpdates", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "topmostOwner", "=", "$", "this", "->", "getOwningDocument", "(", "$", "coll", "->", "getOwner", "(", ")", ")", ";", "unset", "(", "$", "this", "->", "collectionUpdates", "[", "$", "oid", "]", ")", ";", "unset", "(", "$", "this", "->", "hasScheduledCollections", "[", "spl_object_hash", "(", "$", "topmostOwner", ")", "]", "[", "$", "oid", "]", ")", ";", "}" ]
Unschedules a collection from being updated when this UnitOfWork commits. @internal
[ "Unschedules", "a", "collection", "from", "being", "updated", "when", "this", "UnitOfWork", "commits", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2342-L2356
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.scheduleCollectionOwner
private function scheduleCollectionOwner(PersistentCollectionInterface $coll) : void { if ($coll->getOwner() === null) { return; } $document = $this->getOwningDocument($coll->getOwner()); $this->hasScheduledCollections[spl_object_hash($document)][spl_object_hash($coll)] = $coll; if ($document !== $coll->getOwner()) { $parent = $coll->getOwner(); $mapping = []; while (($parentAssoc = $this->getParentAssociation($parent)) !== null) { [$mapping, $parent ] = $parentAssoc; } if (CollectionHelper::isAtomic($mapping['strategy'])) { $class = $this->dm->getClassMetadata(get_class($document)); $atomicCollection = $class->getFieldValue($document, $mapping['fieldName']); $this->scheduleCollectionUpdate($atomicCollection); $this->unscheduleCollectionDeletion($coll); $this->unscheduleCollectionUpdate($coll); } } if ($this->isDocumentScheduled($document)) { return; } $this->scheduleForUpdate($document); }
php
private function scheduleCollectionOwner(PersistentCollectionInterface $coll) : void { if ($coll->getOwner() === null) { return; } $document = $this->getOwningDocument($coll->getOwner()); $this->hasScheduledCollections[spl_object_hash($document)][spl_object_hash($coll)] = $coll; if ($document !== $coll->getOwner()) { $parent = $coll->getOwner(); $mapping = []; while (($parentAssoc = $this->getParentAssociation($parent)) !== null) { [$mapping, $parent ] = $parentAssoc; } if (CollectionHelper::isAtomic($mapping['strategy'])) { $class = $this->dm->getClassMetadata(get_class($document)); $atomicCollection = $class->getFieldValue($document, $mapping['fieldName']); $this->scheduleCollectionUpdate($atomicCollection); $this->unscheduleCollectionDeletion($coll); $this->unscheduleCollectionUpdate($coll); } } if ($this->isDocumentScheduled($document)) { return; } $this->scheduleForUpdate($document); }
[ "private", "function", "scheduleCollectionOwner", "(", "PersistentCollectionInterface", "$", "coll", ")", ":", "void", "{", "if", "(", "$", "coll", "->", "getOwner", "(", ")", "===", "null", ")", "{", "return", ";", "}", "$", "document", "=", "$", "this", "->", "getOwningDocument", "(", "$", "coll", "->", "getOwner", "(", ")", ")", ";", "$", "this", "->", "hasScheduledCollections", "[", "spl_object_hash", "(", "$", "document", ")", "]", "[", "spl_object_hash", "(", "$", "coll", ")", "]", "=", "$", "coll", ";", "if", "(", "$", "document", "!==", "$", "coll", "->", "getOwner", "(", ")", ")", "{", "$", "parent", "=", "$", "coll", "->", "getOwner", "(", ")", ";", "$", "mapping", "=", "[", "]", ";", "while", "(", "(", "$", "parentAssoc", "=", "$", "this", "->", "getParentAssociation", "(", "$", "parent", ")", ")", "!==", "null", ")", "{", "[", "$", "mapping", ",", "$", "parent", "]", "=", "$", "parentAssoc", ";", "}", "if", "(", "CollectionHelper", "::", "isAtomic", "(", "$", "mapping", "[", "'strategy'", "]", ")", ")", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "$", "atomicCollection", "=", "$", "class", "->", "getFieldValue", "(", "$", "document", ",", "$", "mapping", "[", "'fieldName'", "]", ")", ";", "$", "this", "->", "scheduleCollectionUpdate", "(", "$", "atomicCollection", ")", ";", "$", "this", "->", "unscheduleCollectionDeletion", "(", "$", "coll", ")", ";", "$", "this", "->", "unscheduleCollectionUpdate", "(", "$", "coll", ")", ";", "}", "}", "if", "(", "$", "this", "->", "isDocumentScheduled", "(", "$", "document", ")", ")", "{", "return", ";", "}", "$", "this", "->", "scheduleForUpdate", "(", "$", "document", ")", ";", "}" ]
Marks the PersistentCollection's top-level owner as having a relation to a collection scheduled for update or deletion. If the owner is not scheduled for any lifecycle action, it will be scheduled for update to ensure that versioning takes place if necessary. If the collection is nested within atomic collection, it is immediately unscheduled and atomic one is scheduled for update instead. This makes calculating update data way easier.
[ "Marks", "the", "PersistentCollection", "s", "top", "-", "level", "owner", "as", "having", "a", "relation", "to", "a", "collection", "scheduled", "for", "update", "or", "deletion", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2419-L2448
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getOwningDocument
public function getOwningDocument(object $document) : object { $class = $this->dm->getClassMetadata(get_class($document)); while ($class->isEmbeddedDocument) { $parentAssociation = $this->getParentAssociation($document); if (! $parentAssociation) { throw new UnexpectedValueException('Could not determine parent association for ' . get_class($document)); } [, $document ] = $parentAssociation; $class = $this->dm->getClassMetadata(get_class($document)); } return $document; }
php
public function getOwningDocument(object $document) : object { $class = $this->dm->getClassMetadata(get_class($document)); while ($class->isEmbeddedDocument) { $parentAssociation = $this->getParentAssociation($document); if (! $parentAssociation) { throw new UnexpectedValueException('Could not determine parent association for ' . get_class($document)); } [, $document ] = $parentAssociation; $class = $this->dm->getClassMetadata(get_class($document)); } return $document; }
[ "public", "function", "getOwningDocument", "(", "object", "$", "document", ")", ":", "object", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "while", "(", "$", "class", "->", "isEmbeddedDocument", ")", "{", "$", "parentAssociation", "=", "$", "this", "->", "getParentAssociation", "(", "$", "document", ")", ";", "if", "(", "!", "$", "parentAssociation", ")", "{", "throw", "new", "UnexpectedValueException", "(", "'Could not determine parent association for '", ".", "get_class", "(", "$", "document", ")", ")", ";", "}", "[", ",", "$", "document", "]", "=", "$", "parentAssociation", ";", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "}", "return", "$", "document", ";", "}" ]
Get the top-most owning document of a given document If a top-level document is provided, that same document will be returned. For an embedded document, we will walk through parent associations until we find a top-level document. @throws UnexpectedValueException When a top-level document could not be found.
[ "Get", "the", "top", "-", "most", "owning", "document", "of", "a", "given", "document" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2459-L2474
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getClassNameForAssociation
public function getClassNameForAssociation(array $mapping, $data) : string { $discriminatorField = $mapping['discriminatorField'] ?? null; $discriminatorValue = null; if (isset($discriminatorField, $data[$discriminatorField])) { $discriminatorValue = $data[$discriminatorField]; } elseif (isset($mapping['defaultDiscriminatorValue'])) { $discriminatorValue = $mapping['defaultDiscriminatorValue']; } if ($discriminatorValue !== null) { return $mapping['discriminatorMap'][$discriminatorValue] ?? (string) $discriminatorValue; } $class = $this->dm->getClassMetadata($mapping['targetDocument']); if (isset($class->discriminatorField, $data[$class->discriminatorField])) { $discriminatorValue = $data[$class->discriminatorField]; } elseif ($class->defaultDiscriminatorValue !== null) { $discriminatorValue = $class->defaultDiscriminatorValue; } if ($discriminatorValue !== null) { return $class->discriminatorMap[$discriminatorValue] ?? $discriminatorValue; } return $mapping['targetDocument']; }
php
public function getClassNameForAssociation(array $mapping, $data) : string { $discriminatorField = $mapping['discriminatorField'] ?? null; $discriminatorValue = null; if (isset($discriminatorField, $data[$discriminatorField])) { $discriminatorValue = $data[$discriminatorField]; } elseif (isset($mapping['defaultDiscriminatorValue'])) { $discriminatorValue = $mapping['defaultDiscriminatorValue']; } if ($discriminatorValue !== null) { return $mapping['discriminatorMap'][$discriminatorValue] ?? (string) $discriminatorValue; } $class = $this->dm->getClassMetadata($mapping['targetDocument']); if (isset($class->discriminatorField, $data[$class->discriminatorField])) { $discriminatorValue = $data[$class->discriminatorField]; } elseif ($class->defaultDiscriminatorValue !== null) { $discriminatorValue = $class->defaultDiscriminatorValue; } if ($discriminatorValue !== null) { return $class->discriminatorMap[$discriminatorValue] ?? $discriminatorValue; } return $mapping['targetDocument']; }
[ "public", "function", "getClassNameForAssociation", "(", "array", "$", "mapping", ",", "$", "data", ")", ":", "string", "{", "$", "discriminatorField", "=", "$", "mapping", "[", "'discriminatorField'", "]", "??", "null", ";", "$", "discriminatorValue", "=", "null", ";", "if", "(", "isset", "(", "$", "discriminatorField", ",", "$", "data", "[", "$", "discriminatorField", "]", ")", ")", "{", "$", "discriminatorValue", "=", "$", "data", "[", "$", "discriminatorField", "]", ";", "}", "elseif", "(", "isset", "(", "$", "mapping", "[", "'defaultDiscriminatorValue'", "]", ")", ")", "{", "$", "discriminatorValue", "=", "$", "mapping", "[", "'defaultDiscriminatorValue'", "]", ";", "}", "if", "(", "$", "discriminatorValue", "!==", "null", ")", "{", "return", "$", "mapping", "[", "'discriminatorMap'", "]", "[", "$", "discriminatorValue", "]", "??", "(", "string", ")", "$", "discriminatorValue", ";", "}", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "mapping", "[", "'targetDocument'", "]", ")", ";", "if", "(", "isset", "(", "$", "class", "->", "discriminatorField", ",", "$", "data", "[", "$", "class", "->", "discriminatorField", "]", ")", ")", "{", "$", "discriminatorValue", "=", "$", "data", "[", "$", "class", "->", "discriminatorField", "]", ";", "}", "elseif", "(", "$", "class", "->", "defaultDiscriminatorValue", "!==", "null", ")", "{", "$", "discriminatorValue", "=", "$", "class", "->", "defaultDiscriminatorValue", ";", "}", "if", "(", "$", "discriminatorValue", "!==", "null", ")", "{", "return", "$", "class", "->", "discriminatorMap", "[", "$", "discriminatorValue", "]", "??", "$", "discriminatorValue", ";", "}", "return", "$", "mapping", "[", "'targetDocument'", "]", ";", "}" ]
Gets the class name for an association (embed or reference) with respect to any discriminator value. @internal @param array|null $data
[ "Gets", "the", "class", "name", "for", "an", "association", "(", "embed", "or", "reference", ")", "with", "respect", "to", "any", "discriminator", "value", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2484-L2513
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.getOrCreateDocument
public function getOrCreateDocument(string $className, array $data, array &$hints = [], ?object $document = null) : object { $class = $this->dm->getClassMetadata($className); // @TODO figure out how to remove this $discriminatorValue = null; if (isset($class->discriminatorField, $data[$class->discriminatorField])) { $discriminatorValue = $data[$class->discriminatorField]; } elseif (isset($class->defaultDiscriminatorValue)) { $discriminatorValue = $class->defaultDiscriminatorValue; } if ($discriminatorValue !== null) { $className = $class->discriminatorMap[$discriminatorValue] ?? $discriminatorValue; $class = $this->dm->getClassMetadata($className); unset($data[$class->discriminatorField]); } if (! empty($hints[Query::HINT_READ_ONLY])) { $document = $class->newInstance(); $this->hydratorFactory->hydrate($document, $data, $hints); return $document; } $isManagedObject = false; $serializedId = null; $id = null; if (! $class->isQueryResultDocument) { $id = $class->getDatabaseIdentifierValue($data['_id']); $serializedId = serialize($id); $isManagedObject = isset($this->identityMap[$class->name][$serializedId]); } $oid = null; if ($isManagedObject) { $document = $this->identityMap[$class->name][$serializedId]; $oid = spl_object_hash($document); if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->setProxyInitializer(null); $overrideLocalValues = true; if ($document instanceof NotifyPropertyChanged) { $document->addPropertyChangedListener($this); } } else { $overrideLocalValues = ! empty($hints[Query::HINT_REFRESH]); } if ($overrideLocalValues) { $data = $this->hydratorFactory->hydrate($document, $data, $hints); $this->originalDocumentData[$oid] = $data; } } else { if ($document === null) { $document = $class->newInstance(); } if (! $class->isQueryResultDocument) { $this->registerManaged($document, $id, $data); $oid = spl_object_hash($document); $this->documentStates[$oid] = self::STATE_MANAGED; $this->identityMap[$class->name][$serializedId] = $document; } $data = $this->hydratorFactory->hydrate($document, $data, $hints); if (! $class->isQueryResultDocument) { $this->originalDocumentData[$oid] = $data; } } return $document; }
php
public function getOrCreateDocument(string $className, array $data, array &$hints = [], ?object $document = null) : object { $class = $this->dm->getClassMetadata($className); $discriminatorValue = null; if (isset($class->discriminatorField, $data[$class->discriminatorField])) { $discriminatorValue = $data[$class->discriminatorField]; } elseif (isset($class->defaultDiscriminatorValue)) { $discriminatorValue = $class->defaultDiscriminatorValue; } if ($discriminatorValue !== null) { $className = $class->discriminatorMap[$discriminatorValue] ?? $discriminatorValue; $class = $this->dm->getClassMetadata($className); unset($data[$class->discriminatorField]); } if (! empty($hints[Query::HINT_READ_ONLY])) { $document = $class->newInstance(); $this->hydratorFactory->hydrate($document, $data, $hints); return $document; } $isManagedObject = false; $serializedId = null; $id = null; if (! $class->isQueryResultDocument) { $id = $class->getDatabaseIdentifierValue($data['_id']); $serializedId = serialize($id); $isManagedObject = isset($this->identityMap[$class->name][$serializedId]); } $oid = null; if ($isManagedObject) { $document = $this->identityMap[$class->name][$serializedId]; $oid = spl_object_hash($document); if ($document instanceof GhostObjectInterface && ! $document->isProxyInitialized()) { $document->setProxyInitializer(null); $overrideLocalValues = true; if ($document instanceof NotifyPropertyChanged) { $document->addPropertyChangedListener($this); } } else { $overrideLocalValues = ! empty($hints[Query::HINT_REFRESH]); } if ($overrideLocalValues) { $data = $this->hydratorFactory->hydrate($document, $data, $hints); $this->originalDocumentData[$oid] = $data; } } else { if ($document === null) { $document = $class->newInstance(); } if (! $class->isQueryResultDocument) { $this->registerManaged($document, $id, $data); $oid = spl_object_hash($document); $this->documentStates[$oid] = self::STATE_MANAGED; $this->identityMap[$class->name][$serializedId] = $document; } $data = $this->hydratorFactory->hydrate($document, $data, $hints); if (! $class->isQueryResultDocument) { $this->originalDocumentData[$oid] = $data; } } return $document; }
[ "public", "function", "getOrCreateDocument", "(", "string", "$", "className", ",", "array", "$", "data", ",", "array", "&", "$", "hints", "=", "[", "]", ",", "?", "object", "$", "document", "=", "null", ")", ":", "object", "{", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "className", ")", ";", "// @TODO figure out how to remove this", "$", "discriminatorValue", "=", "null", ";", "if", "(", "isset", "(", "$", "class", "->", "discriminatorField", ",", "$", "data", "[", "$", "class", "->", "discriminatorField", "]", ")", ")", "{", "$", "discriminatorValue", "=", "$", "data", "[", "$", "class", "->", "discriminatorField", "]", ";", "}", "elseif", "(", "isset", "(", "$", "class", "->", "defaultDiscriminatorValue", ")", ")", "{", "$", "discriminatorValue", "=", "$", "class", "->", "defaultDiscriminatorValue", ";", "}", "if", "(", "$", "discriminatorValue", "!==", "null", ")", "{", "$", "className", "=", "$", "class", "->", "discriminatorMap", "[", "$", "discriminatorValue", "]", "??", "$", "discriminatorValue", ";", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "$", "className", ")", ";", "unset", "(", "$", "data", "[", "$", "class", "->", "discriminatorField", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "hints", "[", "Query", "::", "HINT_READ_ONLY", "]", ")", ")", "{", "$", "document", "=", "$", "class", "->", "newInstance", "(", ")", ";", "$", "this", "->", "hydratorFactory", "->", "hydrate", "(", "$", "document", ",", "$", "data", ",", "$", "hints", ")", ";", "return", "$", "document", ";", "}", "$", "isManagedObject", "=", "false", ";", "$", "serializedId", "=", "null", ";", "$", "id", "=", "null", ";", "if", "(", "!", "$", "class", "->", "isQueryResultDocument", ")", "{", "$", "id", "=", "$", "class", "->", "getDatabaseIdentifierValue", "(", "$", "data", "[", "'_id'", "]", ")", ";", "$", "serializedId", "=", "serialize", "(", "$", "id", ")", ";", "$", "isManagedObject", "=", "isset", "(", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "serializedId", "]", ")", ";", "}", "$", "oid", "=", "null", ";", "if", "(", "$", "isManagedObject", ")", "{", "$", "document", "=", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "serializedId", "]", ";", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "if", "(", "$", "document", "instanceof", "GhostObjectInterface", "&&", "!", "$", "document", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "document", "->", "setProxyInitializer", "(", "null", ")", ";", "$", "overrideLocalValues", "=", "true", ";", "if", "(", "$", "document", "instanceof", "NotifyPropertyChanged", ")", "{", "$", "document", "->", "addPropertyChangedListener", "(", "$", "this", ")", ";", "}", "}", "else", "{", "$", "overrideLocalValues", "=", "!", "empty", "(", "$", "hints", "[", "Query", "::", "HINT_REFRESH", "]", ")", ";", "}", "if", "(", "$", "overrideLocalValues", ")", "{", "$", "data", "=", "$", "this", "->", "hydratorFactory", "->", "hydrate", "(", "$", "document", ",", "$", "data", ",", "$", "hints", ")", ";", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", "=", "$", "data", ";", "}", "}", "else", "{", "if", "(", "$", "document", "===", "null", ")", "{", "$", "document", "=", "$", "class", "->", "newInstance", "(", ")", ";", "}", "if", "(", "!", "$", "class", "->", "isQueryResultDocument", ")", "{", "$", "this", "->", "registerManaged", "(", "$", "document", ",", "$", "id", ",", "$", "data", ")", ";", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "$", "this", "->", "documentStates", "[", "$", "oid", "]", "=", "self", "::", "STATE_MANAGED", ";", "$", "this", "->", "identityMap", "[", "$", "class", "->", "name", "]", "[", "$", "serializedId", "]", "=", "$", "document", ";", "}", "$", "data", "=", "$", "this", "->", "hydratorFactory", "->", "hydrate", "(", "$", "document", ",", "$", "data", ",", "$", "hints", ")", ";", "if", "(", "!", "$", "class", "->", "isQueryResultDocument", ")", "{", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", "=", "$", "data", ";", "}", "}", "return", "$", "document", ";", "}" ]
Creates a document. Used for reconstitution of documents during hydration. @internal
[ "Creates", "a", "document", ".", "Used", "for", "reconstitution", "of", "documents", "during", "hydration", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2520-L2592
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.loadCollection
public function loadCollection(PersistentCollectionInterface $collection) : void { if ($collection->getOwner() === null) { throw PersistentCollectionException::ownerRequiredToLoadCollection(); } $this->getDocumentPersister(get_class($collection->getOwner()))->loadCollection($collection); $this->lifecycleEventManager->postCollectionLoad($collection); }
php
public function loadCollection(PersistentCollectionInterface $collection) : void { if ($collection->getOwner() === null) { throw PersistentCollectionException::ownerRequiredToLoadCollection(); } $this->getDocumentPersister(get_class($collection->getOwner()))->loadCollection($collection); $this->lifecycleEventManager->postCollectionLoad($collection); }
[ "public", "function", "loadCollection", "(", "PersistentCollectionInterface", "$", "collection", ")", ":", "void", "{", "if", "(", "$", "collection", "->", "getOwner", "(", ")", "===", "null", ")", "{", "throw", "PersistentCollectionException", "::", "ownerRequiredToLoadCollection", "(", ")", ";", "}", "$", "this", "->", "getDocumentPersister", "(", "get_class", "(", "$", "collection", "->", "getOwner", "(", ")", ")", ")", "->", "loadCollection", "(", "$", "collection", ")", ";", "$", "this", "->", "lifecycleEventManager", "->", "postCollectionLoad", "(", "$", "collection", ")", ";", "}" ]
Initializes (loads) an uninitialized persistent collection of a document. @internal
[ "Initializes", "(", "loads", ")", "an", "uninitialized", "persistent", "collection", "of", "a", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2599-L2607
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.setOriginalDocumentProperty
public function setOriginalDocumentProperty(string $oid, string $property, $value) : void { $this->originalDocumentData[$oid][$property] = $value; }
php
public function setOriginalDocumentProperty(string $oid, string $property, $value) : void { $this->originalDocumentData[$oid][$property] = $value; }
[ "public", "function", "setOriginalDocumentProperty", "(", "string", "$", "oid", ",", "string", "$", "property", ",", "$", "value", ")", ":", "void", "{", "$", "this", "->", "originalDocumentData", "[", "$", "oid", "]", "[", "$", "property", "]", "=", "$", "value", ";", "}" ]
Sets a property value of the original data array of a document. @internal @param mixed $value
[ "Sets", "a", "property", "value", "of", "the", "original", "data", "array", "of", "a", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2649-L2652
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.propertyChanged
public function propertyChanged($document, $propertyName, $oldValue, $newValue) { $oid = spl_object_hash($document); $class = $this->dm->getClassMetadata(get_class($document)); if (! isset($class->fieldMappings[$propertyName])) { return; // ignore non-persistent fields } // Update changeset and mark document for synchronization $this->documentChangeSets[$oid][$propertyName] = [$oldValue, $newValue]; if (isset($this->scheduledForSynchronization[$class->name][$oid])) { return; } $this->scheduleForSynchronization($document); }
php
public function propertyChanged($document, $propertyName, $oldValue, $newValue) { $oid = spl_object_hash($document); $class = $this->dm->getClassMetadata(get_class($document)); if (! isset($class->fieldMappings[$propertyName])) { return; } $this->documentChangeSets[$oid][$propertyName] = [$oldValue, $newValue]; if (isset($this->scheduledForSynchronization[$class->name][$oid])) { return; } $this->scheduleForSynchronization($document); }
[ "public", "function", "propertyChanged", "(", "$", "document", ",", "$", "propertyName", ",", "$", "oldValue", ",", "$", "newValue", ")", "{", "$", "oid", "=", "spl_object_hash", "(", "$", "document", ")", ";", "$", "class", "=", "$", "this", "->", "dm", "->", "getClassMetadata", "(", "get_class", "(", "$", "document", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "class", "->", "fieldMappings", "[", "$", "propertyName", "]", ")", ")", "{", "return", ";", "// ignore non-persistent fields", "}", "// Update changeset and mark document for synchronization", "$", "this", "->", "documentChangeSets", "[", "$", "oid", "]", "[", "$", "propertyName", "]", "=", "[", "$", "oldValue", ",", "$", "newValue", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "scheduledForSynchronization", "[", "$", "class", "->", "name", "]", "[", "$", "oid", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "scheduleForSynchronization", "(", "$", "document", ")", ";", "}" ]
Notifies this UnitOfWork of a property change in a document. @param object $document The document that owns the property. @param string $propertyName The name of the property that changed. @param mixed $oldValue The old value of the property. @param mixed $newValue The new value of the property.
[ "Notifies", "this", "UnitOfWork", "of", "a", "property", "change", "in", "a", "document", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2741-L2757
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/UnitOfWork.php
UnitOfWork.initializeObject
public function initializeObject(object $obj) : void { if ($obj instanceof GhostObjectInterface) { $obj->initializeProxy(); } elseif ($obj instanceof PersistentCollectionInterface) { $obj->initialize(); } }
php
public function initializeObject(object $obj) : void { if ($obj instanceof GhostObjectInterface) { $obj->initializeProxy(); } elseif ($obj instanceof PersistentCollectionInterface) { $obj->initialize(); } }
[ "public", "function", "initializeObject", "(", "object", "$", "obj", ")", ":", "void", "{", "if", "(", "$", "obj", "instanceof", "GhostObjectInterface", ")", "{", "$", "obj", "->", "initializeProxy", "(", ")", ";", "}", "elseif", "(", "$", "obj", "instanceof", "PersistentCollectionInterface", ")", "{", "$", "obj", "->", "initialize", "(", ")", ";", "}", "}" ]
Helper method to initialize a lazy loading proxy or persistent collection. @internal
[ "Helper", "method", "to", "initialize", "a", "lazy", "loading", "proxy", "or", "persistent", "collection", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/UnitOfWork.php#L2816-L2823
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Lookup.localField
public function localField(string $localField) : self { $this->localField = $this->prepareFieldName($localField, $this->class); return $this; }
php
public function localField(string $localField) : self { $this->localField = $this->prepareFieldName($localField, $this->class); return $this; }
[ "public", "function", "localField", "(", "string", "$", "localField", ")", ":", "self", "{", "$", "this", "->", "localField", "=", "$", "this", "->", "prepareFieldName", "(", "$", "localField", ",", "$", "this", "->", "class", ")", ";", "return", "$", "this", ";", "}" ]
Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes.
[ "Specifies", "the", "field", "from", "the", "documents", "input", "to", "the", "$lookup", "stage", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php#L120-L124
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Lookup.foreignField
public function foreignField(string $foreignField) : self { $this->foreignField = $this->prepareFieldName($foreignField, $this->targetClass); return $this; }
php
public function foreignField(string $foreignField) : self { $this->foreignField = $this->prepareFieldName($foreignField, $this->targetClass); return $this; }
[ "public", "function", "foreignField", "(", "string", "$", "foreignField", ")", ":", "self", "{", "$", "this", "->", "foreignField", "=", "$", "this", "->", "prepareFieldName", "(", "$", "foreignField", ",", "$", "this", "->", "targetClass", ")", ";", "return", "$", "this", ";", "}" ]
Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes.
[ "Specifies", "the", "field", "from", "the", "documents", "in", "the", "from", "collection", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php#L134-L138
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.getReferenceId
public static function getReferenceId($reference, string $storeAs) { return $storeAs === self::REFERENCE_STORE_AS_ID ? $reference : $reference[self::getReferencePrefix($storeAs) . 'id']; }
php
public static function getReferenceId($reference, string $storeAs) { return $storeAs === self::REFERENCE_STORE_AS_ID ? $reference : $reference[self::getReferencePrefix($storeAs) . 'id']; }
[ "public", "static", "function", "getReferenceId", "(", "$", "reference", ",", "string", "$", "storeAs", ")", "{", "return", "$", "storeAs", "===", "self", "::", "REFERENCE_STORE_AS_ID", "?", "$", "reference", ":", "$", "reference", "[", "self", "::", "getReferencePrefix", "(", "$", "storeAs", ")", ".", "'id'", "]", ";", "}" ]
Helper method to get reference id of ref* type references @internal @param mixed $reference @return mixed
[ "Helper", "method", "to", "get", "reference", "id", "of", "ref", "*", "type", "references" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L526-L529
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.getReferencePrefix
private static function getReferencePrefix(string $storeAs) : string { if (! in_array($storeAs, [self::REFERENCE_STORE_AS_REF, self::REFERENCE_STORE_AS_DB_REF, self::REFERENCE_STORE_AS_DB_REF_WITH_DB])) { throw new LogicException('Can only get a reference prefix for DBRef and reference arrays'); } return $storeAs === self::REFERENCE_STORE_AS_REF ? '' : '$'; }
php
private static function getReferencePrefix(string $storeAs) : string { if (! in_array($storeAs, [self::REFERENCE_STORE_AS_REF, self::REFERENCE_STORE_AS_DB_REF, self::REFERENCE_STORE_AS_DB_REF_WITH_DB])) { throw new LogicException('Can only get a reference prefix for DBRef and reference arrays'); } return $storeAs === self::REFERENCE_STORE_AS_REF ? '' : '$'; }
[ "private", "static", "function", "getReferencePrefix", "(", "string", "$", "storeAs", ")", ":", "string", "{", "if", "(", "!", "in_array", "(", "$", "storeAs", ",", "[", "self", "::", "REFERENCE_STORE_AS_REF", ",", "self", "::", "REFERENCE_STORE_AS_DB_REF", ",", "self", "::", "REFERENCE_STORE_AS_DB_REF_WITH_DB", "]", ")", ")", "{", "throw", "new", "LogicException", "(", "'Can only get a reference prefix for DBRef and reference arrays'", ")", ";", "}", "return", "$", "storeAs", "===", "self", "::", "REFERENCE_STORE_AS_REF", "?", "''", ":", "'$'", ";", "}" ]
Returns the reference prefix used for a reference
[ "Returns", "the", "reference", "prefix", "used", "for", "a", "reference" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L534-L541
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.getReferenceFieldName
public static function getReferenceFieldName(string $storeAs, string $pathPrefix = '') : string { if ($storeAs === self::REFERENCE_STORE_AS_ID) { return $pathPrefix; } return ($pathPrefix ? $pathPrefix . '.' : '') . static::getReferencePrefix($storeAs) . 'id'; }
php
public static function getReferenceFieldName(string $storeAs, string $pathPrefix = '') : string { if ($storeAs === self::REFERENCE_STORE_AS_ID) { return $pathPrefix; } return ($pathPrefix ? $pathPrefix . '.' : '') . static::getReferencePrefix($storeAs) . 'id'; }
[ "public", "static", "function", "getReferenceFieldName", "(", "string", "$", "storeAs", ",", "string", "$", "pathPrefix", "=", "''", ")", ":", "string", "{", "if", "(", "$", "storeAs", "===", "self", "::", "REFERENCE_STORE_AS_ID", ")", "{", "return", "$", "pathPrefix", ";", "}", "return", "(", "$", "pathPrefix", "?", "$", "pathPrefix", ".", "'.'", ":", "''", ")", ".", "static", "::", "getReferencePrefix", "(", "$", "storeAs", ")", ".", "'id'", ";", "}" ]
Returns a fully qualified field name for a given reference @internal @param string $pathPrefix The field path prefix
[ "Returns", "a", "fully", "qualified", "field", "name", "for", "a", "given", "reference" ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L550-L557
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.setCustomRepositoryClass
public function setCustomRepositoryClass(?string $repositoryClassName) : void { if ($this->isEmbeddedDocument || $this->isQueryResultDocument) { return; } $this->customRepositoryClassName = $repositoryClassName; }
php
public function setCustomRepositoryClass(?string $repositoryClassName) : void { if ($this->isEmbeddedDocument || $this->isQueryResultDocument) { return; } $this->customRepositoryClassName = $repositoryClassName; }
[ "public", "function", "setCustomRepositoryClass", "(", "?", "string", "$", "repositoryClassName", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isEmbeddedDocument", "||", "$", "this", "->", "isQueryResultDocument", ")", "{", "return", ";", "}", "$", "this", "->", "customRepositoryClassName", "=", "$", "repositoryClassName", ";", "}" ]
Registers a custom repository class for the document class.
[ "Registers", "a", "custom", "repository", "class", "for", "the", "document", "class", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L634-L641
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.invokeLifecycleCallbacks
public function invokeLifecycleCallbacks(string $event, object $document, ?array $arguments = null) : void { if (! $document instanceof $this->name) { throw new InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document))); } if (empty($this->lifecycleCallbacks[$event])) { return; } foreach ($this->lifecycleCallbacks[$event] as $callback) { if ($arguments !== null) { $document->$callback(...$arguments); } else { $document->$callback(); } } }
php
public function invokeLifecycleCallbacks(string $event, object $document, ?array $arguments = null) : void { if (! $document instanceof $this->name) { throw new InvalidArgumentException(sprintf('Expected document class "%s"; found: "%s"', $this->name, get_class($document))); } if (empty($this->lifecycleCallbacks[$event])) { return; } foreach ($this->lifecycleCallbacks[$event] as $callback) { if ($arguments !== null) { $document->$callback(...$arguments); } else { $document->$callback(); } } }
[ "public", "function", "invokeLifecycleCallbacks", "(", "string", "$", "event", ",", "object", "$", "document", ",", "?", "array", "$", "arguments", "=", "null", ")", ":", "void", "{", "if", "(", "!", "$", "document", "instanceof", "$", "this", "->", "name", ")", "{", "throw", "new", "InvalidArgumentException", "(", "sprintf", "(", "'Expected document class \"%s\"; found: \"%s\"'", ",", "$", "this", "->", "name", ",", "get_class", "(", "$", "document", ")", ")", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "lifecycleCallbacks", "[", "$", "event", "]", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "lifecycleCallbacks", "[", "$", "event", "]", "as", "$", "callback", ")", "{", "if", "(", "$", "arguments", "!==", "null", ")", "{", "$", "document", "->", "$", "callback", "(", "...", "$", "arguments", ")", ";", "}", "else", "{", "$", "document", "->", "$", "callback", "(", ")", ";", "}", "}", "}" ]
Dispatches the lifecycle event of the given document by invoking all registered callbacks. @throws InvalidArgumentException If document class is not this class or a Proxy of this class.
[ "Dispatches", "the", "lifecycle", "event", "of", "the", "given", "document", "by", "invoking", "all", "registered", "callbacks", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L650-L667
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.addLifecycleCallback
public function addLifecycleCallback(string $callback, string $event) : void { if (isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) { return; } $this->lifecycleCallbacks[$event][] = $callback; }
php
public function addLifecycleCallback(string $callback, string $event) : void { if (isset($this->lifecycleCallbacks[$event]) && in_array($callback, $this->lifecycleCallbacks[$event])) { return; } $this->lifecycleCallbacks[$event][] = $callback; }
[ "public", "function", "addLifecycleCallback", "(", "string", "$", "callback", ",", "string", "$", "event", ")", ":", "void", "{", "if", "(", "isset", "(", "$", "this", "->", "lifecycleCallbacks", "[", "$", "event", "]", ")", "&&", "in_array", "(", "$", "callback", ",", "$", "this", "->", "lifecycleCallbacks", "[", "$", "event", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "lifecycleCallbacks", "[", "$", "event", "]", "[", "]", "=", "$", "callback", ";", "}" ]
Adds a lifecycle callback for documents of this class. If the callback is already registered, this is a NOOP.
[ "Adds", "a", "lifecycle", "callback", "for", "documents", "of", "this", "class", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L690-L697
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.registerAlsoLoadMethod
public function registerAlsoLoadMethod(string $method, $fields) : void { $this->alsoLoadMethods[$method] = is_array($fields) ? $fields : [$fields]; }
php
public function registerAlsoLoadMethod(string $method, $fields) : void { $this->alsoLoadMethods[$method] = is_array($fields) ? $fields : [$fields]; }
[ "public", "function", "registerAlsoLoadMethod", "(", "string", "$", "method", ",", "$", "fields", ")", ":", "void", "{", "$", "this", "->", "alsoLoadMethods", "[", "$", "method", "]", "=", "is_array", "(", "$", "fields", ")", "?", "$", "fields", ":", "[", "$", "fields", "]", ";", "}" ]
Registers a method for loading document data before field hydration. Note: A method may be registered multiple times for different fields. it will be invoked only once for the first field found. @param array|string $fields Database field name(s)
[ "Registers", "a", "method", "for", "loading", "document", "data", "before", "field", "hydration", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L717-L720
doctrine/mongodb-odm
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
ClassMetadata.setDiscriminatorMap
public function setDiscriminatorMap(array $map) : void { if ($this->isFile) { throw MappingException::discriminatorNotAllowedForGridFS($this->name); } $this->subClasses = []; $this->discriminatorMap = []; $this->discriminatorValue = null; foreach ($map as $value => $className) { $this->discriminatorMap[$value] = $className; if ($this->name === $className) { $this->discriminatorValue = $value; } else { if (! class_exists($className)) { throw MappingException::invalidClassInDiscriminatorMap($className, $this->name); } if (is_subclass_of($className, $this->name)) { $this->subClasses[] = $className; } } } }
php
public function setDiscriminatorMap(array $map) : void { if ($this->isFile) { throw MappingException::discriminatorNotAllowedForGridFS($this->name); } $this->subClasses = []; $this->discriminatorMap = []; $this->discriminatorValue = null; foreach ($map as $value => $className) { $this->discriminatorMap[$value] = $className; if ($this->name === $className) { $this->discriminatorValue = $value; } else { if (! class_exists($className)) { throw MappingException::invalidClassInDiscriminatorMap($className, $this->name); } if (is_subclass_of($className, $this->name)) { $this->subClasses[] = $className; } } } }
[ "public", "function", "setDiscriminatorMap", "(", "array", "$", "map", ")", ":", "void", "{", "if", "(", "$", "this", "->", "isFile", ")", "{", "throw", "MappingException", "::", "discriminatorNotAllowedForGridFS", "(", "$", "this", "->", "name", ")", ";", "}", "$", "this", "->", "subClasses", "=", "[", "]", ";", "$", "this", "->", "discriminatorMap", "=", "[", "]", ";", "$", "this", "->", "discriminatorValue", "=", "null", ";", "foreach", "(", "$", "map", "as", "$", "value", "=>", "$", "className", ")", "{", "$", "this", "->", "discriminatorMap", "[", "$", "value", "]", "=", "$", "className", ";", "if", "(", "$", "this", "->", "name", "===", "$", "className", ")", "{", "$", "this", "->", "discriminatorValue", "=", "$", "value", ";", "}", "else", "{", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "throw", "MappingException", "::", "invalidClassInDiscriminatorMap", "(", "$", "className", ",", "$", "this", "->", "name", ")", ";", "}", "if", "(", "is_subclass_of", "(", "$", "className", ",", "$", "this", "->", "name", ")", ")", "{", "$", "this", "->", "subClasses", "[", "]", "=", "$", "className", ";", "}", "}", "}", "}" ]
Sets the discriminator values used by this class. Used for JOINED and SINGLE_TABLE inheritance mapping strategies. @throws MappingException
[ "Sets", "the", "discriminator", "values", "used", "by", "this", "class", ".", "Used", "for", "JOINED", "and", "SINGLE_TABLE", "inheritance", "mapping", "strategies", "." ]
train
https://github.com/doctrine/mongodb-odm/blob/e4971557a8200456d87e2f1def8bde7fb07bbb3f/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L781-L804