|
7 | 7 | use MongoDB\Exception\InvalidArgumentTypeException;
|
8 | 8 | use stdClass;
|
9 | 9 |
|
| 10 | +/** |
| 11 | + * Generate an index name from a key specification. |
| 12 | + * |
| 13 | + * @internal |
| 14 | + * @param array|object $document Document containing fields mapped to values, |
| 15 | + * which denote order or an index type |
| 16 | + * @return string |
| 17 | + * @throws InvalidArgumentTypeException |
| 18 | + */ |
| 19 | +function generate_index_name($document) |
| 20 | +{ |
| 21 | + if (is_object($document)) { |
| 22 | + $document = get_object_vars($document); |
| 23 | + } |
| 24 | + |
| 25 | + if ( ! is_array($document)) { |
| 26 | + throw new InvalidArgumentTypeException('$document', $document, 'array or object'); |
| 27 | + } |
| 28 | + |
| 29 | + $name = ''; |
| 30 | + |
| 31 | + foreach ($document as $field => $type) { |
| 32 | + $name .= ($name != '' ? '_' : '') . $field . '_' . $type; |
| 33 | + } |
| 34 | + |
| 35 | + return $name; |
| 36 | +} |
| 37 | + |
10 | 38 | /**
|
11 | 39 | * Return whether the first key in the document starts with a "$" character.
|
12 | 40 | *
|
@@ -55,34 +83,6 @@ function is_last_pipeline_operator_out(array $pipeline)
|
55 | 83 | return key($lastOp) === '$out';
|
56 | 84 | }
|
57 | 85 |
|
58 |
| -/** |
59 |
| - * Generate an index name from a key specification. |
60 |
| - * |
61 |
| - * @internal |
62 |
| - * @param array|object $document Document containing fields mapped to values, |
63 |
| - * which denote order or an index type |
64 |
| - * @return string |
65 |
| - * @throws InvalidArgumentTypeException |
66 |
| - */ |
67 |
| -function generate_index_name($document) |
68 |
| -{ |
69 |
| - if (is_object($document)) { |
70 |
| - $document = get_object_vars($document); |
71 |
| - } |
72 |
| - |
73 |
| - if ( ! is_array($document)) { |
74 |
| - throw new InvalidArgumentTypeException('$document', $document, 'array or object'); |
75 |
| - } |
76 |
| - |
77 |
| - $name = ''; |
78 |
| - |
79 |
| - foreach ($document as $field => $type) { |
80 |
| - $name .= ($name != '' ? '_' : '') . $field . '_' . $type; |
81 |
| - } |
82 |
| - |
83 |
| - return $name; |
84 |
| -} |
85 |
| - |
86 | 86 | /**
|
87 | 87 | * Converts a ReadConcern instance to a stdClass for use in a BSON document.
|
88 | 88 | *
|
|
0 commit comments