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
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
yiisoft/yii2-mongodb
src/Collection.php
Collection.findAndModify
public function findAndModify($condition, $update, $options = []) { return $this->database->createCommand()->findAndModify($this->name, $condition, $update, $options); }
php
public function findAndModify($condition, $update, $options = []) { return $this->database->createCommand()->findAndModify($this->name, $condition, $update, $options); }
[ "public", "function", "findAndModify", "(", "$", "condition", ",", "$", "update", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "findAndModify", "(", "$", "this", "->", "na...
Updates a document and returns it. @param array $condition query condition @param array $update update criteria @param array $options list of options in format: optionName => optionValue. @return array|null the original document, or the modified document when $options['new'] is set. @throws Exception on failure.
[ "Updates", "a", "document", "and", "returns", "it", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L252-L255
yiisoft/yii2-mongodb
src/Collection.php
Collection.insert
public function insert($data, $options = []) { return $this->database->createCommand()->insert($this->name, $data, $options); }
php
public function insert($data, $options = []) { return $this->database->createCommand()->insert($this->name, $data, $options); }
[ "public", "function", "insert", "(", "$", "data", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "insert", "(", "$", "this", "->", "name", ",", "$", "data", ",", "$", ...
Inserts new data into collection. @param array|object $data data to be inserted. @param array $options list of options in format: optionName => optionValue. @return \MongoDB\BSON\ObjectID new record ID instance. @throws Exception on failure.
[ "Inserts", "new", "data", "into", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L264-L267
yiisoft/yii2-mongodb
src/Collection.php
Collection.batchInsert
public function batchInsert($rows, $options = []) { $insertedIds = $this->database->createCommand()->batchInsert($this->name, $rows, $options); foreach ($rows as $key => $row) { $rows[$key]['_id'] = $insertedIds[$key]; } return $rows; }
php
public function batchInsert($rows, $options = []) { $insertedIds = $this->database->createCommand()->batchInsert($this->name, $rows, $options); foreach ($rows as $key => $row) { $rows[$key]['_id'] = $insertedIds[$key]; } return $rows; }
[ "public", "function", "batchInsert", "(", "$", "rows", ",", "$", "options", "=", "[", "]", ")", "{", "$", "insertedIds", "=", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "batchInsert", "(", "$", "this", "->", "name", ",", "$...
Inserts several new rows into collection. @param array $rows array of arrays or objects to be inserted. @param array $options list of options in format: optionName => optionValue. @return array inserted data, each row will have "_id" key assigned to it. @throws Exception on failure.
[ "Inserts", "several", "new", "rows", "into", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L276-L283
yiisoft/yii2-mongodb
src/Collection.php
Collection.update
public function update($condition, $newData, $options = []) { $writeResult = $this->database->createCommand()->update($this->name, $condition, $newData, $options); return $writeResult->getModifiedCount() + $writeResult->getUpsertedCount(); }
php
public function update($condition, $newData, $options = []) { $writeResult = $this->database->createCommand()->update($this->name, $condition, $newData, $options); return $writeResult->getModifiedCount() + $writeResult->getUpsertedCount(); }
[ "public", "function", "update", "(", "$", "condition", ",", "$", "newData", ",", "$", "options", "=", "[", "]", ")", "{", "$", "writeResult", "=", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "update", "(", "$", "this", "->",...
Updates the rows, which matches given criteria by given data. Note: for "multi" mode Mongo requires explicit strategy "$set" or "$inc" to be specified for the "newData". If no strategy is passed "$set" will be used. @param array $condition description of the objects to update. @param array $newData the object with which to update the matching records. @param array $options list of options in format: optionName => optionValue. @return int|bool number of updated documents or whether operation was successful. @throws Exception on failure.
[ "Updates", "the", "rows", "which", "matches", "given", "criteria", "by", "given", "data", ".", "Note", ":", "for", "multi", "mode", "Mongo", "requires", "explicit", "strategy", "$set", "or", "$inc", "to", "be", "specified", "for", "the", "newData", ".", "I...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L295-L299
yiisoft/yii2-mongodb
src/Collection.php
Collection.save
public function save($data, $options = []) { if (empty($data['_id'])) { return $this->insert($data, $options); } $id = $data['_id']; unset($data['_id']); $this->update(['_id' => $id], ['$set' => $data], ['upsert' => true]); return is_object($id) ? $id : new ObjectID($id); }
php
public function save($data, $options = []) { if (empty($data['_id'])) { return $this->insert($data, $options); } $id = $data['_id']; unset($data['_id']); $this->update(['_id' => $id], ['$set' => $data], ['upsert' => true]); return is_object($id) ? $id : new ObjectID($id); }
[ "public", "function", "save", "(", "$", "data", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "data", "[", "'_id'", "]", ")", ")", "{", "return", "$", "this", "->", "insert", "(", "$", "data", ",", "$", "options", ...
Update the existing database data, otherwise insert this data @param array|object $data data to be updated/inserted. @param array $options list of options in format: optionName => optionValue. @return \MongoDB\BSON\ObjectID updated/new record id instance. @throws Exception on failure.
[ "Update", "the", "existing", "database", "data", "otherwise", "insert", "this", "data" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L308-L318
yiisoft/yii2-mongodb
src/Collection.php
Collection.remove
public function remove($condition = [], $options = []) { $options = array_merge(['limit' => 0], $options); $writeResult = $this->database->createCommand()->delete($this->name, $condition, $options); return $writeResult->getDeletedCount(); }
php
public function remove($condition = [], $options = []) { $options = array_merge(['limit' => 0], $options); $writeResult = $this->database->createCommand()->delete($this->name, $condition, $options); return $writeResult->getDeletedCount(); }
[ "public", "function", "remove", "(", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "array_merge", "(", "[", "'limit'", "=>", "0", "]", ",", "$", "options", ")", ";", "$", "writeResult", "=", "...
Removes data from the collection. @param array $condition description of records to remove. @param array $options list of options in format: optionName => optionValue. @return int|bool number of updated documents or whether operation was successful. @throws Exception on failure.
[ "Removes", "data", "from", "the", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L327-L332
yiisoft/yii2-mongodb
src/Collection.php
Collection.count
public function count($condition = [], $options = []) { return $this->database->createCommand()->count($this->name, $condition, $options); }
php
public function count($condition = [], $options = []) { return $this->database->createCommand()->count($this->name, $condition, $options); }
[ "public", "function", "count", "(", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "count", "(", "$", "this", "->", "name", ",", "$", ...
Counts records in this collection. @param array $condition query condition @param array $options list of options in format: optionName => optionValue. @return int records count. @since 2.1
[ "Counts", "records", "in", "this", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L341-L344
yiisoft/yii2-mongodb
src/Collection.php
Collection.distinct
public function distinct($column, $condition = [], $options = []) { return $this->database->createCommand()->distinct($this->name, $column, $condition, $options); }
php
public function distinct($column, $condition = [], $options = []) { return $this->database->createCommand()->distinct($this->name, $column, $condition, $options); }
[ "public", "function", "distinct", "(", "$", "column", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "distinct", "(", "$", "this", ...
Returns a list of distinct values for the given column across a collection. @param string $column column to use. @param array $condition query parameters. @param array $options list of options in format: optionName => optionValue. @return array|bool array of distinct values, or "false" on failure. @throws Exception on failure.
[ "Returns", "a", "list", "of", "distinct", "values", "for", "the", "given", "column", "across", "a", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L354-L357
yiisoft/yii2-mongodb
src/Collection.php
Collection.aggregate
public function aggregate($pipelines, $options = []) { return $this->database->createCommand()->aggregate($this->name, $pipelines, $options); }
php
public function aggregate($pipelines, $options = []) { return $this->database->createCommand()->aggregate($this->name, $pipelines, $options); }
[ "public", "function", "aggregate", "(", "$", "pipelines", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "aggregate", "(", "$", "this", "->", "name", ",", "$", "pipelines", ...
Performs aggregation using Mongo Aggregation Framework. In case 'cursor' option is specified [[\MongoDB\Driver\Cursor]] instance is returned, otherwise - an array of aggregation results. @param array $pipelines list of pipeline operators. @param array $options optional parameters. @return array|\MongoDB\Driver\Cursor the result of the aggregation. @throws Exception on failure.
[ "Performs", "aggregation", "using", "Mongo", "Aggregation", "Framework", ".", "In", "case", "cursor", "option", "is", "specified", "[[", "\\", "MongoDB", "\\", "Driver", "\\", "Cursor", "]]", "instance", "is", "returned", "otherwise", "-", "an", "array", "of",...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L368-L371
yiisoft/yii2-mongodb
src/Collection.php
Collection.group
public function group($keys, $initial, $reduce, $options = []) { return $this->database->createCommand()->group($this->name, $keys, $initial, $reduce, $options); }
php
public function group($keys, $initial, $reduce, $options = []) { return $this->database->createCommand()->group($this->name, $keys, $initial, $reduce, $options); }
[ "public", "function", "group", "(", "$", "keys", ",", "$", "initial", ",", "$", "reduce", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", "->", "group", "(", "$", "this", "->",...
Performs aggregation using Mongo "group" command. @param mixed $keys fields to group by. If an array or non-code object is passed, it will be the key used to group results. If instance of [[\MongoDB\BSON\Javascript]] passed, it will be treated as a function that returns the key to group by. @param array $initial Initial value of the aggregation counter object. @param \MongoDB\BSON\Javascript|string $reduce function that takes two arguments (the current document and the aggregation to this point) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param array $options optional parameters to the group command. Valid options include: - condition - criteria for including a document in the aggregation. - finalize - function called once per unique key that takes the final output of the reduce function. @return array the result of the aggregation. @throws Exception on failure.
[ "Performs", "aggregation", "using", "Mongo", "group", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L388-L391
yiisoft/yii2-mongodb
src/Collection.php
Collection.mapReduce
public function mapReduce($map, $reduce, $out, $condition = [], $options = []) { return $this->database->createCommand()->mapReduce($this->name, $map, $reduce, $out, $condition, $options); }
php
public function mapReduce($map, $reduce, $out, $condition = [], $options = []) { return $this->database->createCommand()->mapReduce($this->name, $map, $reduce, $out, $condition, $options); }
[ "public", "function", "mapReduce", "(", "$", "map", ",", "$", "reduce", ",", "$", "out", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "database", "->", "createCommand", "(", ")", ...
Performs aggregation using MongoDB "map-reduce" mechanism. Note: this function will not return the aggregation result, instead it will write it inside the another Mongo collection specified by "out" parameter. For example: ```php $customerCollection = Yii::$app->mongo->getCollection('customer'); $resultCollectionName = $customerCollection->mapReduce( 'function () {emit(this.status, this.amount)}', 'function (key, values) {return Array.sum(values)}', 'mapReduceOut', ['status' => 3] ); $query = new Query(); $results = $query->from($resultCollectionName)->all(); ``` @param \MongoDB\BSON\Javascript|string $map function, which emits map data from collection. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param \MongoDB\BSON\Javascript|string $reduce function that takes two arguments (the map key and the map values) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param string|array $out output collection name. It could be a string for simple output ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection']). You can pass ['inline' => true] to fetch the result at once without temporary collection usage. @param array $condition criteria for including a document in the aggregation. @param array $options additional optional parameters to the mapReduce command. Valid options include: - sort: array, key to sort the input documents. The sort key must be in an existing index for this collection. - limit: int, the maximum number of documents to return in the collection. - finalize: \MongoDB\BSON\Javascript|string, function, which follows the reduce method and modifies the output. - scope: array, specifies global variables that are accessible in the map, reduce and finalize functions. - jsMode: bool, specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions. - verbose: bool, specifies whether to include the timing information in the result information. @return string|array the map reduce output collection name or output results. @throws Exception on failure.
[ "Performs", "aggregation", "using", "MongoDB", "map", "-", "reduce", "mechanism", ".", "Note", ":", "this", "function", "will", "not", "return", "the", "aggregation", "result", "instead", "it", "will", "write", "it", "inside", "the", "another", "Mongo", "colle...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Collection.php#L432-L435
yiisoft/yii2-mongodb
src/Command.php
Command.getReadPreference
public function getReadPreference() { if (!is_object($this->_readPreference)) { if ($this->_readPreference === null) { $this->_readPreference = $this->db->manager->getReadPreference(); } elseif (is_scalar($this->_readPreference)) { $this->_readPreference = new ReadPreference($this->_readPreference); } } return $this->_readPreference; }
php
public function getReadPreference() { if (!is_object($this->_readPreference)) { if ($this->_readPreference === null) { $this->_readPreference = $this->db->manager->getReadPreference(); } elseif (is_scalar($this->_readPreference)) { $this->_readPreference = new ReadPreference($this->_readPreference); } } return $this->_readPreference; }
[ "public", "function", "getReadPreference", "(", ")", "{", "if", "(", "!", "is_object", "(", "$", "this", "->", "_readPreference", ")", ")", "{", "if", "(", "$", "this", "->", "_readPreference", "===", "null", ")", "{", "$", "this", "->", "_readPreference...
Returns read preference for this command. @return ReadPreference read preference.
[ "Returns", "read", "preference", "for", "this", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L94-L104
yiisoft/yii2-mongodb
src/Command.php
Command.getWriteConcern
public function getWriteConcern() { if ($this->_writeConcern !== null) { if (is_scalar($this->_writeConcern)) { $this->_writeConcern = new WriteConcern($this->_writeConcern); } } return $this->_writeConcern; }
php
public function getWriteConcern() { if ($this->_writeConcern !== null) { if (is_scalar($this->_writeConcern)) { $this->_writeConcern = new WriteConcern($this->_writeConcern); } } return $this->_writeConcern; }
[ "public", "function", "getWriteConcern", "(", ")", "{", "if", "(", "$", "this", "->", "_writeConcern", "!==", "null", ")", "{", "if", "(", "is_scalar", "(", "$", "this", "->", "_writeConcern", ")", ")", "{", "$", "this", "->", "_writeConcern", "=", "ne...
Returns write concern for this command. @return WriteConcern|null write concern to be used in this command.
[ "Returns", "write", "concern", "for", "this", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L122-L130
yiisoft/yii2-mongodb
src/Command.php
Command.getReadConcern
public function getReadConcern() { if ($this->_readConcern !== null) { if (is_scalar($this->_readConcern)) { $this->_readConcern = new ReadConcern($this->_readConcern); } } return $this->_readConcern; }
php
public function getReadConcern() { if ($this->_readConcern !== null) { if (is_scalar($this->_readConcern)) { $this->_readConcern = new ReadConcern($this->_readConcern); } } return $this->_readConcern; }
[ "public", "function", "getReadConcern", "(", ")", "{", "if", "(", "$", "this", "->", "_readConcern", "!==", "null", ")", "{", "if", "(", "is_scalar", "(", "$", "this", "->", "_readConcern", ")", ")", "{", "$", "this", "->", "_readConcern", "=", "new", ...
Retuns read concern for this command. @return ReadConcern|string read concern to be used in this command.
[ "Retuns", "read", "concern", "for", "this", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L148-L156
yiisoft/yii2-mongodb
src/Command.php
Command.execute
public function execute() { $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName; $token = $this->log([$databaseName, 'command'], $this->document, __METHOD__); try { $this->beginProfile($token, __METHOD__); $this->db->open(); $mongoCommand = new \MongoDB\Driver\Command($this->document); $cursor = $this->db->manager->executeCommand($databaseName, $mongoCommand, $this->getReadPreference()); $cursor->setTypeMap($this->db->typeMap); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); } return $cursor; }
php
public function execute() { $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName; $token = $this->log([$databaseName, 'command'], $this->document, __METHOD__); try { $this->beginProfile($token, __METHOD__); $this->db->open(); $mongoCommand = new \MongoDB\Driver\Command($this->document); $cursor = $this->db->manager->executeCommand($databaseName, $mongoCommand, $this->getReadPreference()); $cursor->setTypeMap($this->db->typeMap); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); } return $cursor; }
[ "public", "function", "execute", "(", ")", "{", "$", "databaseName", "=", "$", "this", "->", "databaseName", "===", "null", "?", "$", "this", "->", "db", "->", "defaultDatabaseName", ":", "$", "this", "->", "databaseName", ";", "$", "token", "=", "$", ...
Executes this command. @return \MongoDB\Driver\Cursor result cursor. @throws Exception on failure.
[ "Executes", "this", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L175-L196
yiisoft/yii2-mongodb
src/Command.php
Command.executeBatch
public function executeBatch($collectionName, $options = []) { $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName; $token = $this->log([$databaseName, $collectionName, 'bulkWrite'], $this->document, __METHOD__); try { $this->beginProfile($token, __METHOD__); $batch = new BulkWrite($options); $insertedIds = []; foreach ($this->document as $key => $operation) { switch ($operation['type']) { case 'insert': $insertedIds[$key] = $batch->insert($operation['document']); break; case 'update': $batch->update($operation['condition'], $operation['document'], $operation['options']); break; case 'delete': $batch->delete($operation['condition'], isset($operation['options']) ? $operation['options'] : []); break; default: throw new InvalidConfigException("Unsupported batch operation type '{$operation['type']}'"); } } $this->db->open(); $writeResult = $this->db->manager->executeBulkWrite($databaseName . '.' . $collectionName, $batch, $this->getWriteConcern()); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); } return [ 'insertedIds' => $insertedIds, 'result' => $writeResult, ]; }
php
public function executeBatch($collectionName, $options = []) { $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName; $token = $this->log([$databaseName, $collectionName, 'bulkWrite'], $this->document, __METHOD__); try { $this->beginProfile($token, __METHOD__); $batch = new BulkWrite($options); $insertedIds = []; foreach ($this->document as $key => $operation) { switch ($operation['type']) { case 'insert': $insertedIds[$key] = $batch->insert($operation['document']); break; case 'update': $batch->update($operation['condition'], $operation['document'], $operation['options']); break; case 'delete': $batch->delete($operation['condition'], isset($operation['options']) ? $operation['options'] : []); break; default: throw new InvalidConfigException("Unsupported batch operation type '{$operation['type']}'"); } } $this->db->open(); $writeResult = $this->db->manager->executeBulkWrite($databaseName . '.' . $collectionName, $batch, $this->getWriteConcern()); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); } return [ 'insertedIds' => $insertedIds, 'result' => $writeResult, ]; }
[ "public", "function", "executeBatch", "(", "$", "collectionName", ",", "$", "options", "=", "[", "]", ")", "{", "$", "databaseName", "=", "$", "this", "->", "databaseName", "===", "null", "?", "$", "this", "->", "db", "->", "defaultDatabaseName", ":", "$...
Execute commands batch (bulk). @param string $collectionName collection name. @param array $options batch options. @return array array of 2 elements: - 'insertedIds' - contains inserted IDs. - 'result' - [[\MongoDB\Driver\WriteResult]] instance. @throws Exception on failure. @throws InvalidConfigException on invalid [[document]] format.
[ "Execute", "commands", "batch", "(", "bulk", ")", ".", "@param", "string", "$collectionName", "collection", "name", ".", "@param", "array", "$options", "batch", "options", ".", "@return", "array", "array", "of", "2", "elements", ":" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L210-L251
yiisoft/yii2-mongodb
src/Command.php
Command.query
public function query($collectionName, $options = []) { $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName; $token = $this->log( 'find', array_merge( [ 'ns' => $databaseName . '.' . $collectionName, 'filter' => $this->document, ], $options ), __METHOD__ ); $readConcern = $this->getReadConcern(); if ($readConcern !== null) { $options['readConcern'] = $readConcern; } try { $this->beginProfile($token, __METHOD__); $query = new \MongoDB\Driver\Query($this->document, $options); $this->db->open(); $cursor = $this->db->manager->executeQuery($databaseName . '.' . $collectionName, $query, $this->getReadPreference()); $cursor->setTypeMap($this->db->typeMap); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); } return $cursor; }
php
public function query($collectionName, $options = []) { $databaseName = $this->databaseName === null ? $this->db->defaultDatabaseName : $this->databaseName; $token = $this->log( 'find', array_merge( [ 'ns' => $databaseName . '.' . $collectionName, 'filter' => $this->document, ], $options ), __METHOD__ ); $readConcern = $this->getReadConcern(); if ($readConcern !== null) { $options['readConcern'] = $readConcern; } try { $this->beginProfile($token, __METHOD__); $query = new \MongoDB\Driver\Query($this->document, $options); $this->db->open(); $cursor = $this->db->manager->executeQuery($databaseName . '.' . $collectionName, $query, $this->getReadPreference()); $cursor->setTypeMap($this->db->typeMap); $this->endProfile($token, __METHOD__); } catch (RuntimeException $e) { $this->endProfile($token, __METHOD__); throw new Exception($e->getMessage(), $e->getCode(), $e); } return $cursor; }
[ "public", "function", "query", "(", "$", "collectionName", ",", "$", "options", "=", "[", "]", ")", "{", "$", "databaseName", "=", "$", "this", "->", "databaseName", "===", "null", "?", "$", "this", "->", "db", "->", "defaultDatabaseName", ":", "$", "t...
Executes this command as a mongo query @param string $collectionName collection name @param array $options query options. @return \MongoDB\Driver\Cursor result cursor. @throws Exception on failure
[ "Executes", "this", "command", "as", "a", "mongo", "query" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L260-L296
yiisoft/yii2-mongodb
src/Command.php
Command.dropDatabase
public function dropDatabase() { $this->document = $this->db->getQueryBuilder()->dropDatabase(); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
php
public function dropDatabase() { $this->document = $this->db->getQueryBuilder()->dropDatabase(); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
[ "public", "function", "dropDatabase", "(", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "dropDatabase", "(", ")", ";", "$", "result", "=", "current", "(", "$", "this", "->", "execute", ...
Drops database associated with this command. @return bool whether operation was successful.
[ "Drops", "database", "associated", "with", "this", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L302-L308
yiisoft/yii2-mongodb
src/Command.php
Command.createCollection
public function createCollection($collectionName, array $options = []) { $this->document = $this->db->getQueryBuilder()->createCollection($collectionName, $options); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
php
public function createCollection($collectionName, array $options = []) { $this->document = $this->db->getQueryBuilder()->createCollection($collectionName, $options); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
[ "public", "function", "createCollection", "(", "$", "collectionName", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "createCollection", "(", "$...
Creates new collection in database associated with this command.s @param string $collectionName collection name @param array $options collection options in format: "name" => "value" @return bool whether operation was successful.
[ "Creates", "new", "collection", "in", "database", "associated", "with", "this", "command", ".", "s" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L316-L322
yiisoft/yii2-mongodb
src/Command.php
Command.dropCollection
public function dropCollection($collectionName) { $this->document = $this->db->getQueryBuilder()->dropCollection($collectionName); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
php
public function dropCollection($collectionName) { $this->document = $this->db->getQueryBuilder()->dropCollection($collectionName); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
[ "public", "function", "dropCollection", "(", "$", "collectionName", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "dropCollection", "(", "$", "collectionName", ")", ";", "$", "result", "=", ...
Drops specified collection. @param string $collectionName name of the collection to be dropped. @return bool whether operation was successful.
[ "Drops", "specified", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L329-L335
yiisoft/yii2-mongodb
src/Command.php
Command.createIndexes
public function createIndexes($collectionName, $indexes) { $this->document = $this->db->getQueryBuilder()->createIndexes($this->databaseName, $collectionName, $indexes); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
php
public function createIndexes($collectionName, $indexes) { $this->document = $this->db->getQueryBuilder()->createIndexes($this->databaseName, $collectionName, $indexes); $result = current($this->execute()->toArray()); return $result['ok'] > 0; }
[ "public", "function", "createIndexes", "(", "$", "collectionName", ",", "$", "indexes", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "createIndexes", "(", "$", "this", "->", "databaseName",...
Creates indexes in the collection. @param string $collectionName collection name. @param array[] $indexes indexes specification. Each specification should be an array in format: optionName => value The main options are: - keys: array, column names with sort order, to be indexed. This option is mandatory. - unique: bool, whether to create unique index. - name: string, the name of the index, if not set it will be generated automatically. - background: bool, whether to bind index in the background. - sparse: bool, whether index should reference only documents with the specified field. See [[https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#options-for-all-index-types]] for the full list of options. @return bool whether operation was successful.
[ "Creates", "indexes", "in", "the", "collection", ".", "@param", "string", "$collectionName", "collection", "name", ".", "@param", "array", "[]", "$indexes", "indexes", "specification", ".", "Each", "specification", "should", "be", "an", "array", "in", "format", ...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L353-L359
yiisoft/yii2-mongodb
src/Command.php
Command.dropIndexes
public function dropIndexes($collectionName, $indexes) { $this->document = $this->db->getQueryBuilder()->dropIndexes($collectionName, $indexes); return current($this->execute()->toArray()); }
php
public function dropIndexes($collectionName, $indexes) { $this->document = $this->db->getQueryBuilder()->dropIndexes($collectionName, $indexes); return current($this->execute()->toArray()); }
[ "public", "function", "dropIndexes", "(", "$", "collectionName", ",", "$", "indexes", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "dropIndexes", "(", "$", "collectionName", ",", "$", "in...
Drops collection indexes by name. @param string $collectionName collection name. @param string $indexes wildcard for name of the indexes to be dropped. @return array result data.
[ "Drops", "collection", "indexes", "by", "name", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L367-L372
yiisoft/yii2-mongodb
src/Command.php
Command.listIndexes
public function listIndexes($collectionName, $options = []) { $this->document = $this->db->getQueryBuilder()->listIndexes($collectionName, $options); try { $cursor = $this->execute(); } catch (Exception $e) { // The server may return an error if the collection does not exist. $notFoundCodes = [ 26, // namespace not found 60 // database not found ]; if (in_array($e->getCode(), $notFoundCodes, true)) { return []; } throw $e; } return $cursor->toArray(); }
php
public function listIndexes($collectionName, $options = []) { $this->document = $this->db->getQueryBuilder()->listIndexes($collectionName, $options); try { $cursor = $this->execute(); } catch (Exception $e) { // The server may return an error if the collection does not exist. $notFoundCodes = [ 26, // namespace not found 60 // database not found ]; if (in_array($e->getCode(), $notFoundCodes, true)) { return []; } throw $e; } return $cursor->toArray(); }
[ "public", "function", "listIndexes", "(", "$", "collectionName", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "listIndexes", "(", "$", "collectionName"...
Returns information about current collection indexes. @param string $collectionName collection name @param array $options list of options in format: optionName => optionValue. @return array list of indexes info. @throws Exception on failure.
[ "Returns", "information", "about", "current", "collection", "indexes", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L381-L401
yiisoft/yii2-mongodb
src/Command.php
Command.count
public function count($collectionName, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->count($collectionName, $condition, $options); $result = current($this->execute()->toArray()); return $result['n']; }
php
public function count($collectionName, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->count($collectionName, $condition, $options); $result = current($this->execute()->toArray()); return $result['n']; }
[ "public", "function", "count", "(", "$", "collectionName", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "co...
Counts records in specified collection. @param string $collectionName collection name @param array $condition filter condition @param array $options list of options in format: optionName => optionValue. @return int records count
[ "Counts", "records", "in", "specified", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L410-L416
yiisoft/yii2-mongodb
src/Command.php
Command.addUpdate
public function addUpdate($condition, $document, $options = []) { $options = array_merge( [ 'multi' => true, 'upsert' => false, ], $options ); if ($options['multi']) { $keys = array_keys($document); if (!empty($keys) && strncmp('$', $keys[0], 1) !== 0) { $document = ['$set' => $document]; } } $this->document[] = [ 'type' => 'update', 'condition' => $this->db->getQueryBuilder()->buildCondition($condition), 'document' => $document, 'options' => $options, ]; return $this; }
php
public function addUpdate($condition, $document, $options = []) { $options = array_merge( [ 'multi' => true, 'upsert' => false, ], $options ); if ($options['multi']) { $keys = array_keys($document); if (!empty($keys) && strncmp('$', $keys[0], 1) !== 0) { $document = ['$set' => $document]; } } $this->document[] = [ 'type' => 'update', 'condition' => $this->db->getQueryBuilder()->buildCondition($condition), 'document' => $document, 'options' => $options, ]; return $this; }
[ "public", "function", "addUpdate", "(", "$", "condition", ",", "$", "document", ",", "$", "options", "=", "[", "]", ")", "{", "$", "options", "=", "array_merge", "(", "[", "'multi'", "=>", "true", ",", "'upsert'", "=>", "false", ",", "]", ",", "$", ...
Adds the update operation to the batch command. @param array $condition filter condition @param array $document data to be updated @param array $options update options. @return $this self reference. @see executeBatch()
[ "Adds", "the", "update", "operation", "to", "the", "batch", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L441-L465
yiisoft/yii2-mongodb
src/Command.php
Command.addDelete
public function addDelete($condition, $options = []) { $this->document[] = [ 'type' => 'delete', 'condition' => $this->db->getQueryBuilder()->buildCondition($condition), 'options' => $options, ]; return $this; }
php
public function addDelete($condition, $options = []) { $this->document[] = [ 'type' => 'delete', 'condition' => $this->db->getQueryBuilder()->buildCondition($condition), 'options' => $options, ]; return $this; }
[ "public", "function", "addDelete", "(", "$", "condition", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "[", "]", "=", "[", "'type'", "=>", "'delete'", ",", "'condition'", "=>", "$", "this", "->", "db", "->", "getQueryB...
Adds the delete operation to the batch command. @param array $condition filter condition. @param array $options delete options. @return $this self reference. @see executeBatch()
[ "Adds", "the", "delete", "operation", "to", "the", "batch", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L474-L482
yiisoft/yii2-mongodb
src/Command.php
Command.insert
public function insert($collectionName, $document, $options = []) { $this->document = []; $this->addInsert($document); $result = $this->executeBatch($collectionName, $options); if ($result['result']->getInsertedCount() < 1) { return false; } return reset($result['insertedIds']); }
php
public function insert($collectionName, $document, $options = []) { $this->document = []; $this->addInsert($document); $result = $this->executeBatch($collectionName, $options); if ($result['result']->getInsertedCount() < 1) { return false; } return reset($result['insertedIds']); }
[ "public", "function", "insert", "(", "$", "collectionName", ",", "$", "document", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "[", "]", ";", "$", "this", "->", "addInsert", "(", "$", "document", ")", ";", "$", ...
Inserts new document into collection. @param string $collectionName collection name @param array $document document content @param array $options list of options in format: optionName => optionValue. @return ObjectID|bool inserted record ID, `false` - on failure.
[ "Inserts", "new", "document", "into", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L491-L502
yiisoft/yii2-mongodb
src/Command.php
Command.batchInsert
public function batchInsert($collectionName, $documents, $options = []) { $this->document = []; foreach ($documents as $key => $document) { $this->document[$key] = [ 'type' => 'insert', 'document' => $document ]; } $result = $this->executeBatch($collectionName, $options); if ($result['result']->getInsertedCount() < 1) { return false; } return $result['insertedIds']; }
php
public function batchInsert($collectionName, $documents, $options = []) { $this->document = []; foreach ($documents as $key => $document) { $this->document[$key] = [ 'type' => 'insert', 'document' => $document ]; } $result = $this->executeBatch($collectionName, $options); if ($result['result']->getInsertedCount() < 1) { return false; } return $result['insertedIds']; }
[ "public", "function", "batchInsert", "(", "$", "collectionName", ",", "$", "documents", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "[", "]", ";", "foreach", "(", "$", "documents", "as", "$", "key", "=>", "$", ...
Inserts batch of new documents into collection. @param string $collectionName collection name @param array[] $documents documents list @param array $options list of options in format: optionName => optionValue. @return array|false list of inserted IDs, `false` on failure.
[ "Inserts", "batch", "of", "new", "documents", "into", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L511-L528
yiisoft/yii2-mongodb
src/Command.php
Command.update
public function update($collectionName, $condition, $document, $options = []) { $batchOptions = []; foreach (['bypassDocumentValidation'] as $name) { if (isset($options[$name])) { $batchOptions[$name] = $options[$name]; unset($options[$name]); } } $this->document = []; $this->addUpdate($condition, $document, $options); $result = $this->executeBatch($collectionName, $batchOptions); return $result['result']; }
php
public function update($collectionName, $condition, $document, $options = []) { $batchOptions = []; foreach (['bypassDocumentValidation'] as $name) { if (isset($options[$name])) { $batchOptions[$name] = $options[$name]; unset($options[$name]); } } $this->document = []; $this->addUpdate($condition, $document, $options); $result = $this->executeBatch($collectionName, $batchOptions); return $result['result']; }
[ "public", "function", "update", "(", "$", "collectionName", ",", "$", "condition", ",", "$", "document", ",", "$", "options", "=", "[", "]", ")", "{", "$", "batchOptions", "=", "[", "]", ";", "foreach", "(", "[", "'bypassDocumentValidation'", "]", "as", ...
Update existing documents in the collection. @param string $collectionName collection name @param array $condition filter condition @param array $document data to be updated. @param array $options update options. @return WriteResult write result.
[ "Update", "existing", "documents", "in", "the", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L538-L553
yiisoft/yii2-mongodb
src/Command.php
Command.delete
public function delete($collectionName, $condition, $options = []) { $batchOptions = []; foreach (['bypassDocumentValidation'] as $name) { if (isset($options[$name])) { $batchOptions[$name] = $options[$name]; unset($options[$name]); } } $this->document = []; $this->addDelete($condition, $options); $result = $this->executeBatch($collectionName, $batchOptions); return $result['result']; }
php
public function delete($collectionName, $condition, $options = []) { $batchOptions = []; foreach (['bypassDocumentValidation'] as $name) { if (isset($options[$name])) { $batchOptions[$name] = $options[$name]; unset($options[$name]); } } $this->document = []; $this->addDelete($condition, $options); $result = $this->executeBatch($collectionName, $batchOptions); return $result['result']; }
[ "public", "function", "delete", "(", "$", "collectionName", ",", "$", "condition", ",", "$", "options", "=", "[", "]", ")", "{", "$", "batchOptions", "=", "[", "]", ";", "foreach", "(", "[", "'bypassDocumentValidation'", "]", "as", "$", "name", ")", "{...
Removes documents from the collection. @param string $collectionName collection name. @param array $condition filter condition. @param array $options delete options. @return WriteResult write result.
[ "Removes", "documents", "from", "the", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L562-L577
yiisoft/yii2-mongodb
src/Command.php
Command.find
public function find($collectionName, $condition, $options = []) { $queryBuilder = $this->db->getQueryBuilder(); $this->document = $queryBuilder->buildCondition($condition); if (isset($options['projection'])) { $options['projection'] = $queryBuilder->buildSelectFields($options['projection']); } if (isset($options['sort'])) { $options['sort'] = $queryBuilder->buildSortFields($options['sort']); } if (array_key_exists('limit', $options)) { if ($options['limit'] === null || !ctype_digit((string) $options['limit'])) { unset($options['limit']); } else { $options['limit'] = (int)$options['limit']; } } if (array_key_exists('skip', $options)) { if ($options['skip'] === null || !ctype_digit((string) $options['skip'])) { unset($options['skip']); } else { $options['skip'] = (int)$options['skip']; } } return $this->query($collectionName, $options); }
php
public function find($collectionName, $condition, $options = []) { $queryBuilder = $this->db->getQueryBuilder(); $this->document = $queryBuilder->buildCondition($condition); if (isset($options['projection'])) { $options['projection'] = $queryBuilder->buildSelectFields($options['projection']); } if (isset($options['sort'])) { $options['sort'] = $queryBuilder->buildSortFields($options['sort']); } if (array_key_exists('limit', $options)) { if ($options['limit'] === null || !ctype_digit((string) $options['limit'])) { unset($options['limit']); } else { $options['limit'] = (int)$options['limit']; } } if (array_key_exists('skip', $options)) { if ($options['skip'] === null || !ctype_digit((string) $options['skip'])) { unset($options['skip']); } else { $options['skip'] = (int)$options['skip']; } } return $this->query($collectionName, $options); }
[ "public", "function", "find", "(", "$", "collectionName", ",", "$", "condition", ",", "$", "options", "=", "[", "]", ")", "{", "$", "queryBuilder", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", ";", "$", "this", "->", "document", "...
Performs find query. @param string $collectionName collection name @param array $condition filter condition @param array $options query options. @return \MongoDB\Driver\Cursor result cursor.
[ "Performs", "find", "query", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L586-L616
yiisoft/yii2-mongodb
src/Command.php
Command.findAndModify
public function findAndModify($collectionName, $condition = [], $update = [], $options = []) { $this->document = $this->db->getQueryBuilder()->findAndModify($collectionName, $condition, $update, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (!isset($result['value'])) { return null; } return $result['value']; }
php
public function findAndModify($collectionName, $condition = [], $update = [], $options = []) { $this->document = $this->db->getQueryBuilder()->findAndModify($collectionName, $condition, $update, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (!isset($result['value'])) { return null; } return $result['value']; }
[ "public", "function", "findAndModify", "(", "$", "collectionName", ",", "$", "condition", "=", "[", "]", ",", "$", "update", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", ...
Updates a document and returns it. @param $collectionName @param array $condition query condition @param array $update update criteria @param array $options list of options in format: optionName => optionValue. @return array|null the original document, or the modified document when $options['new'] is set.
[ "Updates", "a", "document", "and", "returns", "it", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L626-L638
yiisoft/yii2-mongodb
src/Command.php
Command.distinct
public function distinct($collectionName, $fieldName, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->distinct($collectionName, $fieldName, $condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (!isset($result['values']) || !is_array($result['values'])) { return false; } return $result['values']; }
php
public function distinct($collectionName, $fieldName, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->distinct($collectionName, $fieldName, $condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (!isset($result['values']) || !is_array($result['values'])) { return false; } return $result['values']; }
[ "public", "function", "distinct", "(", "$", "collectionName", ",", "$", "fieldName", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuild...
Returns a list of distinct values for the given column across a collection. @param string $collectionName collection name. @param string $fieldName field name to use. @param array $condition query parameters. @param array $options list of options in format: optionName => optionValue. @return array array of distinct values, or "false" on failure.
[ "Returns", "a", "list", "of", "distinct", "values", "for", "the", "given", "column", "across", "a", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L648-L660
yiisoft/yii2-mongodb
src/Command.php
Command.group
public function group($collectionName, $keys, $initial, $reduce, $options = []) { $this->document = $this->db->getQueryBuilder()->group($collectionName, $keys, $initial, $reduce, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); return $result['retval']; }
php
public function group($collectionName, $keys, $initial, $reduce, $options = []) { $this->document = $this->db->getQueryBuilder()->group($collectionName, $keys, $initial, $reduce, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); return $result['retval']; }
[ "public", "function", "group", "(", "$", "collectionName", ",", "$", "keys", ",", "$", "initial", ",", "$", "reduce", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", ...
Performs aggregation using MongoDB "group" command. @param string $collectionName collection name. @param mixed $keys fields to group by. If an array or non-code object is passed, it will be the key used to group results. If instance of [[\MongoDB\BSON\Javascript]] passed, it will be treated as a function that returns the key to group by. @param array $initial Initial value of the aggregation counter object. @param \MongoDB\BSON\Javascript|string $reduce function that takes two arguments (the current document and the aggregation to this point) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param array $options optional parameters to the group command. Valid options include: - condition - criteria for including a document in the aggregation. - finalize - function called once per unique key that takes the final output of the reduce function. @return array the result of the aggregation.
[ "Performs", "aggregation", "using", "MongoDB", "group", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L677-L685
yiisoft/yii2-mongodb
src/Command.php
Command.mapReduce
public function mapReduce($collectionName, $map, $reduce, $out, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->mapReduce($collectionName, $map, $reduce, $out, $condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); return array_key_exists('results', $result) ? $result['results'] : $result['result']; }
php
public function mapReduce($collectionName, $map, $reduce, $out, $condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->mapReduce($collectionName, $map, $reduce, $out, $condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); return array_key_exists('results', $result) ? $result['results'] : $result['result']; }
[ "public", "function", "mapReduce", "(", "$", "collectionName", ",", "$", "map", ",", "$", "reduce", ",", "$", "out", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "thi...
Performs MongoDB "map-reduce" command. @param string $collectionName collection name. @param \MongoDB\BSON\Javascript|string $map function, which emits map data from collection. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param \MongoDB\BSON\Javascript|string $reduce function that takes two arguments (the map key and the map values) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param string|array $out output collection name. It could be a string for simple output ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection']). You can pass ['inline' => true] to fetch the result at once without temporary collection usage. @param array $condition filter condition for including a document in the aggregation. @param array $options additional optional parameters to the mapReduce command. Valid options include: - sort: array, key to sort the input documents. The sort key must be in an existing index for this collection. - limit: int, the maximum number of documents to return in the collection. - finalize: \MongoDB\BSON\Javascript|string, function, which follows the reduce method and modifies the output. - scope: array, specifies global variables that are accessible in the map, reduce and finalize functions. - jsMode: bool, specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions. - verbose: bool, specifies whether to include the timing information in the result information. @return string|array the map reduce output collection name or output results.
[ "Performs", "MongoDB", "map", "-", "reduce", "command", ".", "@param", "string", "$collectionName", "collection", "name", ".", "@param", "\\", "MongoDB", "\\", "BSON", "\\", "Javascript|string", "$map", "function", "which", "emits", "map", "data", "from", "colle...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L710-L718
yiisoft/yii2-mongodb
src/Command.php
Command.aggregate
public function aggregate($collectionName, $pipelines, $options = []) { if (empty($options['cursor'])) { $returnCursor = false; $options['cursor'] = new \stdClass(); } else { $returnCursor = true; } $this->document = $this->db->getQueryBuilder()->aggregate($collectionName, $pipelines, $options); $cursor = $this->execute(); if ($returnCursor) { return $cursor; } return $cursor->toArray(); }
php
public function aggregate($collectionName, $pipelines, $options = []) { if (empty($options['cursor'])) { $returnCursor = false; $options['cursor'] = new \stdClass(); } else { $returnCursor = true; } $this->document = $this->db->getQueryBuilder()->aggregate($collectionName, $pipelines, $options); $cursor = $this->execute(); if ($returnCursor) { return $cursor; } return $cursor->toArray(); }
[ "public", "function", "aggregate", "(", "$", "collectionName", ",", "$", "pipelines", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "options", "[", "'cursor'", "]", ")", ")", "{", "$", "returnCursor", "=", "false", ";", ...
Performs aggregation using MongoDB Aggregation Framework. In case 'cursor' option is specified [[\MongoDB\Driver\Cursor]] instance is returned, otherwise - an array of aggregation results. @param string $collectionName collection name @param array $pipelines list of pipeline operators. @param array $options optional parameters. @return array|\MongoDB\Driver\Cursor aggregation result.
[ "Performs", "aggregation", "using", "MongoDB", "Aggregation", "Framework", ".", "In", "case", "cursor", "option", "is", "specified", "[[", "\\", "MongoDB", "\\", "Driver", "\\", "Cursor", "]]", "instance", "is", "returned", "otherwise", "-", "an", "array", "of...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L729-L746
yiisoft/yii2-mongodb
src/Command.php
Command.explain
public function explain($collectionName, $query) { $this->document = $this->db->getQueryBuilder()->explain($collectionName, $query); $cursor = $this->execute(); return current($cursor->toArray()); }
php
public function explain($collectionName, $query) { $this->document = $this->db->getQueryBuilder()->explain($collectionName, $query); $cursor = $this->execute(); return current($cursor->toArray()); }
[ "public", "function", "explain", "(", "$", "collectionName", ",", "$", "query", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "explain", "(", "$", "collectionName", ",", "$", "query", ")...
Return an explanation of the query, often useful for optimization and debugging. @param string $collectionName collection name @param array $query query document. @return array explanation of the query.
[ "Return", "an", "explanation", "of", "the", "query", "often", "useful", "for", "optimization", "and", "debugging", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L754-L760
yiisoft/yii2-mongodb
src/Command.php
Command.listDatabases
public function listDatabases($condition = [], $options = []) { if ($this->databaseName === null) { $this->databaseName = 'admin'; } $this->document = $this->db->getQueryBuilder()->listDatabases($condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (empty($result['databases'])) { return []; } return $result['databases']; }
php
public function listDatabases($condition = [], $options = []) { if ($this->databaseName === null) { $this->databaseName = 'admin'; } $this->document = $this->db->getQueryBuilder()->listDatabases($condition, $options); $cursor = $this->execute(); $result = current($cursor->toArray()); if (empty($result['databases'])) { return []; } return $result['databases']; }
[ "public", "function", "listDatabases", "(", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "databaseName", "===", "null", ")", "{", "$", "this", "->", "databaseName", "=", "'admin'", ";", ...
Returns the list of available databases. @param array $condition filter condition. @param array $options options list. @return array database information
[ "Returns", "the", "list", "of", "available", "databases", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L768-L782
yiisoft/yii2-mongodb
src/Command.php
Command.listCollections
public function listCollections($condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->listCollections($condition, $options); $cursor = $this->execute(); return $cursor->toArray(); }
php
public function listCollections($condition = [], $options = []) { $this->document = $this->db->getQueryBuilder()->listCollections($condition, $options); $cursor = $this->execute(); return $cursor->toArray(); }
[ "public", "function", "listCollections", "(", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "this", "->", "document", "=", "$", "this", "->", "db", "->", "getQueryBuilder", "(", ")", "->", "listCollections", "(", ...
Returns the list of available collections. @param array $condition filter condition. @param array $options options list. @return array collections information.
[ "Returns", "the", "list", "of", "available", "collections", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L790-L796
yiisoft/yii2-mongodb
src/Command.php
Command.log
protected function log($namespace, $data, $category) { if ($this->db->enableLogging) { $token = $this->db->getLogBuilder()->generateToken($namespace, $data); Yii::info($token, $category); return $token; } return false; }
php
protected function log($namespace, $data, $category) { if ($this->db->enableLogging) { $token = $this->db->getLogBuilder()->generateToken($namespace, $data); Yii::info($token, $category); return $token; } return false; }
[ "protected", "function", "log", "(", "$", "namespace", ",", "$", "data", ",", "$", "category", ")", "{", "if", "(", "$", "this", "->", "db", "->", "enableLogging", ")", "{", "$", "token", "=", "$", "this", "->", "db", "->", "getLogBuilder", "(", ")...
Logs the command data if logging is enabled at [[db]]. @param array|string $namespace command namespace. @param array $data command data. @param string $category log category @return string|false log token, `false` if log is not enabled.
[ "Logs", "the", "command", "data", "if", "logging", "is", "enabled", "at", "[[", "db", "]]", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L807-L815
yiisoft/yii2-mongodb
src/Command.php
Command.beginProfile
protected function beginProfile($token, $category) { if ($token !== false && $this->db->enableProfiling) { Yii::beginProfile($token, $category); } }
php
protected function beginProfile($token, $category) { if ($token !== false && $this->db->enableProfiling) { Yii::beginProfile($token, $category); } }
[ "protected", "function", "beginProfile", "(", "$", "token", ",", "$", "category", ")", "{", "if", "(", "$", "token", "!==", "false", "&&", "$", "this", "->", "db", "->", "enableProfiling", ")", "{", "Yii", "::", "beginProfile", "(", "$", "token", ",", ...
Marks the beginning of a code block for profiling. @param string $token token for the code block @param string $category the category of this log message @see endProfile()
[ "Marks", "the", "beginning", "of", "a", "code", "block", "for", "profiling", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L823-L828
yiisoft/yii2-mongodb
src/Command.php
Command.endProfile
protected function endProfile($token, $category) { if ($token !== false && $this->db->enableProfiling) { Yii::endProfile($token, $category); } }
php
protected function endProfile($token, $category) { if ($token !== false && $this->db->enableProfiling) { Yii::endProfile($token, $category); } }
[ "protected", "function", "endProfile", "(", "$", "token", ",", "$", "category", ")", "{", "if", "(", "$", "token", "!==", "false", "&&", "$", "this", "->", "db", "->", "enableProfiling", ")", "{", "Yii", "::", "endProfile", "(", "$", "token", ",", "$...
Marks the end of a code block for profiling. @param string $token token for the code block @param string $category the category of this log message @see beginProfile()
[ "Marks", "the", "end", "of", "a", "code", "block", "for", "profiling", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Command.php#L836-L841
yiisoft/yii2-mongodb
src/Cache.php
Cache.getValue
protected function getValue($key) { $query = new Query; $row = $query->select(['data']) ->from($this->cacheCollection) ->where([ 'id' => $key, '$or' => [ [ 'expire' => 0 ], [ 'expire' => ['$gt' => time()] ], ], ]) ->one($this->db); if (empty($row)) { return false; } return $row['data']; }
php
protected function getValue($key) { $query = new Query; $row = $query->select(['data']) ->from($this->cacheCollection) ->where([ 'id' => $key, '$or' => [ [ 'expire' => 0 ], [ 'expire' => ['$gt' => time()] ], ], ]) ->one($this->db); if (empty($row)) { return false; } return $row['data']; }
[ "protected", "function", "getValue", "(", "$", "key", ")", "{", "$", "query", "=", "new", "Query", ";", "$", "row", "=", "$", "query", "->", "select", "(", "[", "'data'", "]", ")", "->", "from", "(", "$", "this", "->", "cacheCollection", ")", "->",...
Retrieves a value from cache with a specified key. This method should be implemented by child classes to retrieve the data from specific cache storage. @param string $key a unique key identifying the cached value @return string|bool the value stored in cache, false if the value is not in the cache or expired.
[ "Retrieves", "a", "value", "from", "cache", "with", "a", "specified", "key", ".", "This", "method", "should", "be", "implemented", "by", "child", "classes", "to", "retrieve", "the", "data", "from", "specific", "cache", "storage", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Cache.php#L77-L99
yiisoft/yii2-mongodb
src/Cache.php
Cache.setValue
protected function setValue($key, $value, $expire) { $result = $this->db->getCollection($this->cacheCollection) ->update(['id' => $key], [ 'expire' => $expire > 0 ? $expire + time() : 0, 'data' => $value, ]); if ($result) { $this->gc(); return true; } return $this->addValue($key, $value, $expire); }
php
protected function setValue($key, $value, $expire) { $result = $this->db->getCollection($this->cacheCollection) ->update(['id' => $key], [ 'expire' => $expire > 0 ? $expire + time() : 0, 'data' => $value, ]); if ($result) { $this->gc(); return true; } return $this->addValue($key, $value, $expire); }
[ "protected", "function", "setValue", "(", "$", "key", ",", "$", "value", ",", "$", "expire", ")", "{", "$", "result", "=", "$", "this", "->", "db", "->", "getCollection", "(", "$", "this", "->", "cacheCollection", ")", "->", "update", "(", "[", "'id'...
Stores a value identified by a key in cache. This method should be implemented by child classes to store the data in specific cache storage. @param string $key the key identifying the value to be cached @param string $value the value to be cached @param int $expire the number of seconds in which the cached value will expire. 0 means never expire. @return bool true if the value is successfully stored into cache, false otherwise
[ "Stores", "a", "value", "identified", "by", "a", "key", "in", "cache", ".", "This", "method", "should", "be", "implemented", "by", "child", "classes", "to", "store", "the", "data", "in", "specific", "cache", "storage", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Cache.php#L110-L123
yiisoft/yii2-mongodb
src/Cache.php
Cache.addValue
protected function addValue($key, $value, $expire) { $this->gc(); if ($expire > 0) { $expire += time(); } else { $expire = 0; } try { $this->db->getCollection($this->cacheCollection) ->insert([ 'id' => $key, 'expire' => $expire, 'data' => $value, ]); return true; } catch (\Exception $e) { return false; } }
php
protected function addValue($key, $value, $expire) { $this->gc(); if ($expire > 0) { $expire += time(); } else { $expire = 0; } try { $this->db->getCollection($this->cacheCollection) ->insert([ 'id' => $key, 'expire' => $expire, 'data' => $value, ]); return true; } catch (\Exception $e) { return false; } }
[ "protected", "function", "addValue", "(", "$", "key", ",", "$", "value", ",", "$", "expire", ")", "{", "$", "this", "->", "gc", "(", ")", ";", "if", "(", "$", "expire", ">", "0", ")", "{", "$", "expire", "+=", "time", "(", ")", ";", "}", "els...
Stores a value identified by a key into cache if the cache does not contain this key. This method should be implemented by child classes to store the data in specific cache storage. @param string $key the key identifying the value to be cached @param string $value the value to be cached @param int $expire the number of seconds in which the cached value will expire. 0 means never expire. @return bool true if the value is successfully stored into cache, false otherwise
[ "Stores", "a", "value", "identified", "by", "a", "key", "into", "cache", "if", "the", "cache", "does", "not", "contain", "this", "key", ".", "This", "method", "should", "be", "implemented", "by", "child", "classes", "to", "store", "the", "data", "in", "s...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Cache.php#L134-L156
yiisoft/yii2-mongodb
src/Cache.php
Cache.deleteValue
protected function deleteValue($key) { $this->db->getCollection($this->cacheCollection)->remove(['id' => $key]); return true; }
php
protected function deleteValue($key) { $this->db->getCollection($this->cacheCollection)->remove(['id' => $key]); return true; }
[ "protected", "function", "deleteValue", "(", "$", "key", ")", "{", "$", "this", "->", "db", "->", "getCollection", "(", "$", "this", "->", "cacheCollection", ")", "->", "remove", "(", "[", "'id'", "=>", "$", "key", "]", ")", ";", "return", "true", ";...
Deletes a value with the specified key from cache This method should be implemented by child classes to delete the data from actual cache storage. @param string $key the key of the value to be deleted @return bool if no error happens during deletion
[ "Deletes", "a", "value", "with", "the", "specified", "key", "from", "cache", "This", "method", "should", "be", "implemented", "by", "child", "classes", "to", "delete", "the", "data", "from", "actual", "cache", "storage", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Cache.php#L164-L168
yiisoft/yii2-mongodb
src/Cache.php
Cache.gc
public function gc($force = false) { if ($force || mt_rand(0, 1000000) < $this->gcProbability) { $this->db->getCollection($this->cacheCollection) ->remove([ 'expire' => [ '$gt' => 0, '$lt' => time(), ] ]); } }
php
public function gc($force = false) { if ($force || mt_rand(0, 1000000) < $this->gcProbability) { $this->db->getCollection($this->cacheCollection) ->remove([ 'expire' => [ '$gt' => 0, '$lt' => time(), ] ]); } }
[ "public", "function", "gc", "(", "$", "force", "=", "false", ")", "{", "if", "(", "$", "force", "||", "mt_rand", "(", "0", ",", "1000000", ")", "<", "$", "this", "->", "gcProbability", ")", "{", "$", "this", "->", "db", "->", "getCollection", "(", ...
Removes the expired data values. @param bool $force whether to enforce the garbage collection regardless of [[gcProbability]]. Defaults to false, meaning the actual deletion happens with the probability as specified by [[gcProbability]].
[ "Removes", "the", "expired", "data", "values", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Cache.php#L186-L197
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.register
public static function register($protocol = 'gridfs', $force = false) { if (in_array($protocol, stream_get_wrappers())) { if (!$force) { return; } stream_wrapper_unregister($protocol); } stream_wrapper_register($protocol, get_called_class(), STREAM_IS_URL); }
php
public static function register($protocol = 'gridfs', $force = false) { if (in_array($protocol, stream_get_wrappers())) { if (!$force) { return; } stream_wrapper_unregister($protocol); } stream_wrapper_register($protocol, get_called_class(), STREAM_IS_URL); }
[ "public", "static", "function", "register", "(", "$", "protocol", "=", "'gridfs'", ",", "$", "force", "=", "false", ")", "{", "if", "(", "in_array", "(", "$", "protocol", ",", "stream_get_wrappers", "(", ")", ")", ")", "{", "if", "(", "!", "$", "forc...
Registers this steam wrapper. @param string $protocol name of the protocol to be used. @param bool $force whether to register wrapper, even if protocol is already taken.
[ "Registers", "this", "steam", "wrapper", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L98-L108
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.getContextOptions
public function getContextOptions() { if ($this->_contextOptions === null) { $this->_contextOptions = stream_context_get_options($this->context); } return $this->_contextOptions; }
php
public function getContextOptions() { if ($this->_contextOptions === null) { $this->_contextOptions = stream_context_get_options($this->context); } return $this->_contextOptions; }
[ "public", "function", "getContextOptions", "(", ")", "{", "if", "(", "$", "this", "->", "_contextOptions", "===", "null", ")", "{", "$", "this", "->", "_contextOptions", "=", "stream_context_get_options", "(", "$", "this", "->", "context", ")", ";", "}", "...
Returns options associated with [[context]]. @return array context options.
[ "Returns", "options", "associated", "with", "[[", "context", "]]", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L114-L120
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.parsePath
private function parsePath($path) { $pathInfo = parse_url($path); $this->_protocol = $pathInfo['scheme']; $this->_namespace = $pathInfo['host']; parse_str($pathInfo['query'], $this->_queryParams); }
php
private function parsePath($path) { $pathInfo = parse_url($path); $this->_protocol = $pathInfo['scheme']; $this->_namespace = $pathInfo['host']; parse_str($pathInfo['query'], $this->_queryParams); }
[ "private", "function", "parsePath", "(", "$", "path", ")", "{", "$", "pathInfo", "=", "parse_url", "(", "$", "path", ")", ";", "$", "this", "->", "_protocol", "=", "$", "pathInfo", "[", "'scheme'", "]", ";", "$", "this", "->", "_namespace", "=", "$",...
Parses stream open path, initializes internal parameters. @param string $path stream open path.
[ "Parses", "stream", "open", "path", "initializes", "internal", "parameters", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L126-L133
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.prepareDownload
private function prepareDownload() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->_protocol]['download'])) { $download = $contextOptions[$this->_protocol]['download']; if (!$download instanceof Download) { throw new InvalidConfigException('"download" context option should be an instance of "' . Download::className() . '"'); } $this->_download = $download; return true; } $collection = $this->fetchCollection(); if (empty($this->_queryParams)) { return false; } $file = $collection->findOne($this->_queryParams); if (empty($file)) { throw new InvalidConfigException('Requested file does not exits.'); } $this->_download = $file['file']; return true; }
php
private function prepareDownload() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->_protocol]['download'])) { $download = $contextOptions[$this->_protocol]['download']; if (!$download instanceof Download) { throw new InvalidConfigException('"download" context option should be an instance of "' . Download::className() . '"'); } $this->_download = $download; return true; } $collection = $this->fetchCollection(); if (empty($this->_queryParams)) { return false; } $file = $collection->findOne($this->_queryParams); if (empty($file)) { throw new InvalidConfigException('Requested file does not exits.'); } $this->_download = $file['file']; return true; }
[ "private", "function", "prepareDownload", "(", ")", "{", "$", "contextOptions", "=", "$", "this", "->", "getContextOptions", "(", ")", ";", "if", "(", "isset", "(", "$", "contextOptions", "[", "$", "this", "->", "_protocol", "]", "[", "'download'", "]", ...
Prepares [[Download]] instance for the read operations. @return bool success. @throws InvalidConfigException on invalid context configuration.
[ "Prepares", "[[", "Download", "]]", "instance", "for", "the", "read", "operations", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L140-L163
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.prepareUpload
private function prepareUpload() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->_protocol]['upload'])) { $upload = $contextOptions[$this->_protocol]['upload']; if (!$upload instanceof Upload) { throw new InvalidConfigException('"upload" context option should be an instance of "' . Upload::className() . '"'); } $this->_upload = $upload; return true; } $collection = $this->fetchCollection(); $this->_upload = $collection->createUpload(['document' => $this->_queryParams]); return true; }
php
private function prepareUpload() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->_protocol]['upload'])) { $upload = $contextOptions[$this->_protocol]['upload']; if (!$upload instanceof Upload) { throw new InvalidConfigException('"upload" context option should be an instance of "' . Upload::className() . '"'); } $this->_upload = $upload; return true; } $collection = $this->fetchCollection(); $this->_upload = $collection->createUpload(['document' => $this->_queryParams]); return true; }
[ "private", "function", "prepareUpload", "(", ")", "{", "$", "contextOptions", "=", "$", "this", "->", "getContextOptions", "(", ")", ";", "if", "(", "isset", "(", "$", "contextOptions", "[", "$", "this", "->", "_protocol", "]", "[", "'upload'", "]", ")",...
Prepares [[Upload]] instance for the write operations. @return bool success. @throws InvalidConfigException on invalid context configuration.
[ "Prepares", "[[", "Upload", "]]", "instance", "for", "the", "write", "operations", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L170-L185
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.fetchCollection
private function fetchCollection() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->_protocol]['collection'])) { $collection = $contextOptions[$this->_protocol]['collection']; if ($collection instanceof Collection) { throw new InvalidConfigException('"collection" context option should be an instance of "' . Collection::className() . '"'); } return $collection; } $connection = isset($contextOptions[$this->_protocol]['db']) ? $contextOptions[$this->_protocol]['db'] : 'mongodb'; /* @var $connection Connection */ $connection = Instance::ensure($connection, Connection::className()); list($databaseName, $collectionPrefix) = explode('.', $this->_namespace, 2); return $connection->getDatabase($databaseName)->getFileCollection($collectionPrefix); }
php
private function fetchCollection() { $contextOptions = $this->getContextOptions(); if (isset($contextOptions[$this->_protocol]['collection'])) { $collection = $contextOptions[$this->_protocol]['collection']; if ($collection instanceof Collection) { throw new InvalidConfigException('"collection" context option should be an instance of "' . Collection::className() . '"'); } return $collection; } $connection = isset($contextOptions[$this->_protocol]['db']) ? $contextOptions[$this->_protocol]['db'] : 'mongodb'; /* @var $connection Connection */ $connection = Instance::ensure($connection, Connection::className()); list($databaseName, $collectionPrefix) = explode('.', $this->_namespace, 2); return $connection->getDatabase($databaseName)->getFileCollection($collectionPrefix); }
[ "private", "function", "fetchCollection", "(", ")", "{", "$", "contextOptions", "=", "$", "this", "->", "getContextOptions", "(", ")", ";", "if", "(", "isset", "(", "$", "contextOptions", "[", "$", "this", "->", "_protocol", "]", "[", "'collection'", "]", ...
Fetches associated file collection from stream options. @return Collection file collection instance. @throws InvalidConfigException on invalid stream options.
[ "Fetches", "associated", "file", "collection", "from", "stream", "options", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L192-L214
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_close
public function stream_close() { if ($this->_upload !== null) { $this->_upload->complete(); $this->_upload = null; } if ($this->_download !== null) { $this->_download = null; } }
php
public function stream_close() { if ($this->_upload !== null) { $this->_upload->complete(); $this->_upload = null; } if ($this->_download !== null) { $this->_download = null; } }
[ "public", "function", "stream_close", "(", ")", "{", "if", "(", "$", "this", "->", "_upload", "!==", "null", ")", "{", "$", "this", "->", "_upload", "->", "complete", "(", ")", ";", "$", "this", "->", "_upload", "=", "null", ";", "}", "if", "(", ...
Closes a resource. This method is called in response to `fclose()`. @see fclose()
[ "Closes", "a", "resource", ".", "This", "method", "is", "called", "in", "response", "to", "fclose", "()", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L247-L256
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_eof
public function stream_eof() { return $this->_download !== null ? ($this->_pointerOffset >= $this->_download->getSize()) : true; }
php
public function stream_eof() { return $this->_download !== null ? ($this->_pointerOffset >= $this->_download->getSize()) : true; }
[ "public", "function", "stream_eof", "(", ")", "{", "return", "$", "this", "->", "_download", "!==", "null", "?", "(", "$", "this", "->", "_pointerOffset", ">=", "$", "this", "->", "_download", "->", "getSize", "(", ")", ")", ":", "true", ";", "}" ]
Tests for end-of-file on a file pointer. This method is called in response to `feof()`. @see feof() @return bool `true` if the read/write position is at the end of the stream and if no more data is available to be read, or `false` otherwise.
[ "Tests", "for", "end", "-", "of", "-", "file", "on", "a", "file", "pointer", ".", "This", "method", "is", "called", "in", "response", "to", "feof", "()", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L265-L270
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_open
public function stream_open($path, $mode, $options, &$openedPath) { if ($options & STREAM_USE_PATH) { $openedPath = $path; } $this->parsePath($path); switch ($mode) { case 'r': return $this->prepareDownload(); case 'w': return $this->prepareUpload(); } return false; }
php
public function stream_open($path, $mode, $options, &$openedPath) { if ($options & STREAM_USE_PATH) { $openedPath = $path; } $this->parsePath($path); switch ($mode) { case 'r': return $this->prepareDownload(); case 'w': return $this->prepareUpload(); } return false; }
[ "public", "function", "stream_open", "(", "$", "path", ",", "$", "mode", ",", "$", "options", ",", "&", "$", "openedPath", ")", "{", "if", "(", "$", "options", "&", "STREAM_USE_PATH", ")", "{", "$", "openedPath", "=", "$", "path", ";", "}", "$", "t...
Opens file. This method is called immediately after the wrapper is initialized (f.e. by `fopen()` and `file_get_contents()`). @see fopen() @param string $path specifies the URL that was passed to the original function. @param string $mode mode used to open the file, as detailed for `fopen()`. @param int $options additional flags set by the streams API. @param string $openedPath real opened path. @return bool whether operation is successful.
[ "Opens", "file", ".", "This", "method", "is", "called", "immediately", "after", "the", "wrapper", "is", "initialized", "(", "f", ".", "e", ".", "by", "fopen", "()", "and", "file_get_contents", "()", ")", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L282-L297
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_read
public function stream_read($count) { if ($this->_download === null) { return false; } $result = $this->_download->substr($this->_pointerOffset, $count); $this->_pointerOffset += $count; return $result; }
php
public function stream_read($count) { if ($this->_download === null) { return false; } $result = $this->_download->substr($this->_pointerOffset, $count); $this->_pointerOffset += $count; return $result; }
[ "public", "function", "stream_read", "(", "$", "count", ")", "{", "if", "(", "$", "this", "->", "_download", "===", "null", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "this", "->", "_download", "->", "substr", "(", "$", "this", ...
Reads from stream. This method is called in response to `fread()` and `fgets()`. @see fread() @param int $count count of bytes of data from the current position should be returned. @return string|false if there are less than count bytes available, return as many as are available. If no more data is available, return `false`.
[ "Reads", "from", "stream", ".", "This", "method", "is", "called", "in", "response", "to", "fread", "()", "and", "fgets", "()", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L307-L315
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_write
public function stream_write($data) { if ($this->_upload === null) { return false; } $this->_upload->addContent($data); $result = StringHelper::byteLength($data); $this->_pointerOffset += $result; return $result; }
php
public function stream_write($data) { if ($this->_upload === null) { return false; } $this->_upload->addContent($data); $result = StringHelper::byteLength($data); $this->_pointerOffset += $result; return $result; }
[ "public", "function", "stream_write", "(", "$", "data", ")", "{", "if", "(", "$", "this", "->", "_upload", "===", "null", ")", "{", "return", "false", ";", "}", "$", "this", "->", "_upload", "->", "addContent", "(", "$", "data", ")", ";", "$", "res...
Writes to stream. This method is called in response to `fwrite()`. @see fwrite() @param string $data string to be stored into the underlying stream. @return int the number of bytes that were successfully stored.
[ "Writes", "to", "stream", ".", "This", "method", "is", "called", "in", "response", "to", "fwrite", "()", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L324-L333
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_stat
public function stream_stat() { $statistics = $this->fileStatisticsTemplate(); if ($this->_download !== null) { $statistics[7] = $statistics['size'] = $this->_download->getSize(); } if ($this->_upload !== null) { $statistics[7] = $statistics['size'] = $this->_pointerOffset; } return $statistics; }
php
public function stream_stat() { $statistics = $this->fileStatisticsTemplate(); if ($this->_download !== null) { $statistics[7] = $statistics['size'] = $this->_download->getSize(); } if ($this->_upload !== null) { $statistics[7] = $statistics['size'] = $this->_pointerOffset; } return $statistics; }
[ "public", "function", "stream_stat", "(", ")", "{", "$", "statistics", "=", "$", "this", "->", "fileStatisticsTemplate", "(", ")", ";", "if", "(", "$", "this", "->", "_download", "!==", "null", ")", "{", "$", "statistics", "[", "7", "]", "=", "$", "s...
Retrieve information about a file resource. This method is called in response to `stat()`. @see stat() @return array file statistic information.
[ "Retrieve", "information", "about", "a", "file", "resource", ".", "This", "method", "is", "called", "in", "response", "to", "stat", "()", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L352-L364
yiisoft/yii2-mongodb
src/file/StreamWrapper.php
StreamWrapper.stream_seek
public function stream_seek($offset, $whence = SEEK_SET) { switch ($whence) { case SEEK_SET: if ($offset < $this->_download->getSize() && $offset >= 0) { $this->_pointerOffset = $offset; return true; } return false; case SEEK_CUR: if ($offset >= 0) { $this->_pointerOffset += $offset; return true; } return false; case SEEK_END: if ($this->_download->getSize() + $offset >= 0) { $this->_pointerOffset = $this->_download->getSize() + $offset; return true; } return false; } return false; }
php
public function stream_seek($offset, $whence = SEEK_SET) { switch ($whence) { case SEEK_SET: if ($offset < $this->_download->getSize() && $offset >= 0) { $this->_pointerOffset = $offset; return true; } return false; case SEEK_CUR: if ($offset >= 0) { $this->_pointerOffset += $offset; return true; } return false; case SEEK_END: if ($this->_download->getSize() + $offset >= 0) { $this->_pointerOffset = $this->_download->getSize() + $offset; return true; } return false; } return false; }
[ "public", "function", "stream_seek", "(", "$", "offset", ",", "$", "whence", "=", "SEEK_SET", ")", "{", "switch", "(", "$", "whence", ")", "{", "case", "SEEK_SET", ":", "if", "(", "$", "offset", "<", "$", "this", "->", "_download", "->", "getSize", "...
Seeks to specific location in a stream. This method is called in response to `fseek()`. @see fseek() @param int $offset The stream offset to seek to. @param int $whence Possible values: - SEEK_SET - Set position equal to offset bytes. - SEEK_CUR - Set position to current location plus offset. - SEEK_END - Set position to end-of-file plus offset. @return bool Return true if the position was updated, false otherwise.
[ "Seeks", "to", "specific", "location", "in", "a", "stream", ".", "This", "method", "is", "called", "in", "response", "to", "fseek", "()", ".", "@see", "fseek", "()", "@param", "int", "$offset", "The", "stream", "offset", "to", "seek", "to", ".", "@param"...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/file/StreamWrapper.php#L380-L403
yiisoft/yii2-mongodb
src/ActiveFixture.php
ActiveFixture.init
public function init() { parent::init(); if (!isset($this->modelClass) && !isset($this->collectionName)) { throw new InvalidConfigException('Either "modelClass" or "collectionName" must be set.'); } }
php
public function init() { parent::init(); if (!isset($this->modelClass) && !isset($this->collectionName)) { throw new InvalidConfigException('Either "modelClass" or "collectionName" must be set.'); } }
[ "public", "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "modelClass", ")", "&&", "!", "isset", "(", "$", "this", "->", "collectionName", ")", ")", "{", "throw", "new", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/ActiveFixture.php#L46-L52
yiisoft/yii2-mongodb
src/ActiveFixture.php
ActiveFixture.load
public function load() { $this->resetCollection(); $this->data = []; $data = $this->getData(); if (empty($data)) { return; } $this->getCollection()->batchInsert($data); foreach ($data as $alias => $row) { $this->data[$alias] = $row; } }
php
public function load() { $this->resetCollection(); $this->data = []; $data = $this->getData(); if (empty($data)) { return; } $this->getCollection()->batchInsert($data); foreach ($data as $alias => $row) { $this->data[$alias] = $row; } }
[ "public", "function", "load", "(", ")", "{", "$", "this", "->", "resetCollection", "(", ")", ";", "$", "this", "->", "data", "=", "[", "]", ";", "$", "data", "=", "$", "this", "->", "getData", "(", ")", ";", "if", "(", "empty", "(", "$", "data"...
Loads the fixture data. The default implementation will first reset the MongoDB collection and then populate it with the data returned by [[getData()]].
[ "Loads", "the", "fixture", "data", ".", "The", "default", "implementation", "will", "first", "reset", "the", "MongoDB", "collection", "and", "then", "populate", "it", "with", "the", "data", "returned", "by", "[[", "getData", "()", "]]", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/ActiveFixture.php#L59-L71
yiisoft/yii2-mongodb
src/ActiveFixture.php
ActiveFixture.getCollectionName
protected function getCollectionName() { if ($this->collectionName) { return $this->collectionName; } /* @var $modelClass ActiveRecord */ $modelClass = $this->modelClass; return $modelClass::collectionName(); }
php
protected function getCollectionName() { if ($this->collectionName) { return $this->collectionName; } /* @var $modelClass ActiveRecord */ $modelClass = $this->modelClass; return $modelClass::collectionName(); }
[ "protected", "function", "getCollectionName", "(", ")", "{", "if", "(", "$", "this", "->", "collectionName", ")", "{", "return", "$", "this", "->", "collectionName", ";", "}", "/* @var $modelClass ActiveRecord */", "$", "modelClass", "=", "$", "this", "->", "m...
Returns collection name used by this fixture. @return array|string related collection name
[ "Returns", "collection", "name", "used", "by", "this", "fixture", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/ActiveFixture.php#L86-L95
yiisoft/yii2-mongodb
src/ActiveFixture.php
ActiveFixture.getData
protected function getData() { if ($this->dataFile === null) { $class = new \ReflectionClass($this); $collectionName = $this->getCollectionName(); $dataFile = dirname($class->getFileName()) . '/data/' . (is_array($collectionName) ? implode('.', $collectionName) : $collectionName) . '.php'; return is_file($dataFile) ? require($dataFile) : []; } return parent::getData(); }
php
protected function getData() { if ($this->dataFile === null) { $class = new \ReflectionClass($this); $collectionName = $this->getCollectionName(); $dataFile = dirname($class->getFileName()) . '/data/' . (is_array($collectionName) ? implode('.', $collectionName) : $collectionName) . '.php'; return is_file($dataFile) ? require($dataFile) : []; } return parent::getData(); }
[ "protected", "function", "getData", "(", ")", "{", "if", "(", "$", "this", "->", "dataFile", "===", "null", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "this", ")", ";", "$", "collectionName", "=", "$", "this", "->", "getCo...
Returns the fixture data. This method is called by [[loadData()]] to get the needed fixture data. The default implementation will try to return the fixture data by including the external file specified by [[dataFile]]. The file should return an array of data rows (column name => column value), each corresponding to a row in the collection. If the data file does not exist, an empty array will be returned. @return array the data rows to be inserted into the collection.
[ "Returns", "the", "fixture", "data", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/ActiveFixture.php#L109-L121
yiisoft/yii2-mongodb
src/i18n/MongoDbMessageSource.php
MongoDbMessageSource.loadMessagesFromDb
protected function loadMessagesFromDb($category, $language) { $fallbackLanguage = substr($language, 0, 2); $fallbackSourceLanguage = substr($this->sourceLanguage, 0, 2); $languages = [ $language, $fallbackLanguage, $fallbackSourceLanguage ]; $rows = (new Query()) ->select(['language', 'messages']) ->from($this->collection) ->andWhere(['category' => $category]) ->andWhere(['language' => array_unique($languages)]) ->all($this->db); if (count($rows) > 1) { $languagePriorities = [ $language => 1 ]; $languagePriorities[$fallbackLanguage] = 2; // language key may be already taken $languagePriorities[$fallbackSourceLanguage] = 3; // language key may be already taken usort($rows, function ($a, $b) use ($languagePriorities) { $languageA = $a['language']; $languageB = $b['language']; if ($languageA === $languageB) { return 0; } if ($languagePriorities[$languageA] < $languagePriorities[$languageB]) { return +1; } return -1; }); } $messages = []; foreach ($rows as $row) { foreach ($row['messages'] as $key => $value) { // @todo drop message as key specification at 2.2 if (is_array($value)) { $messages[$value['message']] = $value['translation']; } else { $messages[$key] = $value; } } } return $messages; }
php
protected function loadMessagesFromDb($category, $language) { $fallbackLanguage = substr($language, 0, 2); $fallbackSourceLanguage = substr($this->sourceLanguage, 0, 2); $languages = [ $language, $fallbackLanguage, $fallbackSourceLanguage ]; $rows = (new Query()) ->select(['language', 'messages']) ->from($this->collection) ->andWhere(['category' => $category]) ->andWhere(['language' => array_unique($languages)]) ->all($this->db); if (count($rows) > 1) { $languagePriorities = [ $language => 1 ]; $languagePriorities[$fallbackLanguage] = 2; // language key may be already taken $languagePriorities[$fallbackSourceLanguage] = 3; // language key may be already taken usort($rows, function ($a, $b) use ($languagePriorities) { $languageA = $a['language']; $languageB = $b['language']; if ($languageA === $languageB) { return 0; } if ($languagePriorities[$languageA] < $languagePriorities[$languageB]) { return +1; } return -1; }); } $messages = []; foreach ($rows as $row) { foreach ($row['messages'] as $key => $value) { // @todo drop message as key specification at 2.2 if (is_array($value)) { $messages[$value['message']] = $value['translation']; } else { $messages[$key] = $value; } } } return $messages; }
[ "protected", "function", "loadMessagesFromDb", "(", "$", "category", ",", "$", "language", ")", "{", "$", "fallbackLanguage", "=", "substr", "(", "$", "language", ",", "0", ",", "2", ")", ";", "$", "fallbackSourceLanguage", "=", "substr", "(", "$", "this",...
Loads the messages from MongoDB. You may override this method to customize the message storage in the MongoDB. @param string $category the message category. @param string $language the target language. @return array the messages loaded from database.
[ "Loads", "the", "messages", "from", "MongoDB", ".", "You", "may", "override", "this", "method", "to", "customize", "the", "message", "storage", "in", "the", "MongoDB", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/i18n/MongoDbMessageSource.php#L162-L214
yiisoft/yii2-mongodb
src/Query.php
Query.getCollection
public function getCollection($db = null) { if ($db === null) { $db = Yii::$app->get('mongodb'); } return $db->getCollection($this->from); }
php
public function getCollection($db = null) { if ($db === null) { $db = Yii::$app->get('mongodb'); } return $db->getCollection($this->from); }
[ "public", "function", "getCollection", "(", "$", "db", "=", "null", ")", "{", "if", "(", "$", "db", "===", "null", ")", "{", "$", "db", "=", "Yii", "::", "$", "app", "->", "get", "(", "'mongodb'", ")", ";", "}", "return", "$", "db", "->", "getC...
Returns the Mongo collection for this query. @param Connection $db Mongo connection. @return Collection collection instance.
[ "Returns", "the", "Mongo", "collection", "for", "this", "query", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L69-L76
yiisoft/yii2-mongodb
src/Query.php
Query.addOptions
public function addOptions($options) { if (is_array($this->options)) { $this->options = array_merge($this->options, $options); } else { $this->options = $options; } return $this; }
php
public function addOptions($options) { if (is_array($this->options)) { $this->options = array_merge($this->options, $options); } else { $this->options = $options; } return $this; }
[ "public", "function", "addOptions", "(", "$", "options", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "options", ")", ")", "{", "$", "this", "->", "options", "=", "array_merge", "(", "$", "this", "->", "options", ",", "$", "options", ")",...
Adds additional cursor options. @param array $options cursor options in format: optionName => optionValue @return $this the query object itself @see options()
[ "Adds", "additional", "cursor", "options", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L123-L132
yiisoft/yii2-mongodb
src/Query.php
Query.andFilterCompare
public function andFilterCompare($name, $value, $defaultOperator = '=') { $matches = []; if (preg_match('/^(<>|>=|>|<=|<|=)/', $value, $matches)) { $op = $matches[1]; $value = substr($value, strlen($op)); } else { $op = $defaultOperator; } return $this->andFilterWhere([$op, $name, $value]); }
php
public function andFilterCompare($name, $value, $defaultOperator = '=') { $matches = []; if (preg_match('/^(<>|>=|>|<=|<|=)/', $value, $matches)) { $op = $matches[1]; $value = substr($value, strlen($op)); } else { $op = $defaultOperator; } return $this->andFilterWhere([$op, $name, $value]); }
[ "public", "function", "andFilterCompare", "(", "$", "name", ",", "$", "value", ",", "$", "defaultOperator", "=", "'='", ")", "{", "$", "matches", "=", "[", "]", ";", "if", "(", "preg_match", "(", "'/^(<>|>=|>|<=|<|=)/'", ",", "$", "value", ",", "$", "m...
Helper method for easy querying on values containing some common operators. The comparison operator is intelligently determined based on the first few characters in the given value and internally translated to a MongoDB operator. In particular, it recognizes the following operators if they appear as the leading characters in the given value: <: the column must be less than the given value ($lt). >: the column must be greater than the given value ($gt). <=: the column must be less than or equal to the given value ($lte). >=: the column must be greater than or equal to the given value ($gte). <>: the column must not be the same as the given value ($ne). Note that when $partialMatch is true, this would mean the value must not be a substring of the column. =: the column must be equal to the given value ($eq). none of the above: use the $defaultOperator Note that when the value is empty, no comparison expression will be added to the search condition. @param string $name column name @param string $value column value @param string $defaultOperator Defaults to =, performing an exact match. For example: use 'LIKE' or 'REGEX' for partial cq regex matching @see Collection::buildCondition() @return $this the query object itself. @since 2.0.5
[ "Helper", "method", "for", "easy", "querying", "on", "values", "containing", "some", "common", "operators", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L158-L169
yiisoft/yii2-mongodb
src/Query.php
Query.buildCursor
public function buildCursor($db = null) { $this->prepare(); $options = $this->options; if (!empty($this->orderBy)) { $options['sort'] = $this->orderBy; } $options['limit'] = $this->limit; $options['skip'] = $this->offset; $cursor = $this->getCollection($db)->find($this->composeCondition(), $this->select, $options); return $cursor; }
php
public function buildCursor($db = null) { $this->prepare(); $options = $this->options; if (!empty($this->orderBy)) { $options['sort'] = $this->orderBy; } $options['limit'] = $this->limit; $options['skip'] = $this->offset; $cursor = $this->getCollection($db)->find($this->composeCondition(), $this->select, $options); return $cursor; }
[ "public", "function", "buildCursor", "(", "$", "db", "=", "null", ")", "{", "$", "this", "->", "prepare", "(", ")", ";", "$", "options", "=", "$", "this", "->", "options", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "orderBy", ")", ")",...
Builds the MongoDB cursor for this query. @param Connection $db the MongoDB connection used to execute the query. @return \MongoDB\Driver\Cursor mongo cursor instance.
[ "Builds", "the", "MongoDB", "cursor", "for", "this", "query", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L188-L202
yiisoft/yii2-mongodb
src/Query.php
Query.fetchRows
protected function fetchRows($cursor, $all = true, $indexBy = null) { $token = 'fetch cursor id = ' . $cursor->getId(); Yii::info($token, __METHOD__); try { Yii::beginProfile($token, __METHOD__); $result = $this->fetchRowsInternal($cursor, $all); Yii::endProfile($token, __METHOD__); return $result; } catch (\Exception $e) { Yii::endProfile($token, __METHOD__); throw new Exception($e->getMessage(), (int) $e->getCode(), $e); } }
php
protected function fetchRows($cursor, $all = true, $indexBy = null) { $token = 'fetch cursor id = ' . $cursor->getId(); Yii::info($token, __METHOD__); try { Yii::beginProfile($token, __METHOD__); $result = $this->fetchRowsInternal($cursor, $all); Yii::endProfile($token, __METHOD__); return $result; } catch (\Exception $e) { Yii::endProfile($token, __METHOD__); throw new Exception($e->getMessage(), (int) $e->getCode(), $e); } }
[ "protected", "function", "fetchRows", "(", "$", "cursor", ",", "$", "all", "=", "true", ",", "$", "indexBy", "=", "null", ")", "{", "$", "token", "=", "'fetch cursor id = '", ".", "$", "cursor", "->", "getId", "(", ")", ";", "Yii", "::", "info", "(",...
Fetches rows from the given Mongo cursor. @param \MongoDB\Driver\Cursor $cursor Mongo cursor instance to fetch data from. @param bool $all whether to fetch all rows or only first one. @param string|callable $indexBy the column name or PHP callback, by which the query results should be indexed by. @throws Exception on failure. @return array|bool result.
[ "Fetches", "rows", "from", "the", "given", "Mongo", "cursor", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L213-L227
yiisoft/yii2-mongodb
src/Query.php
Query.all
public function all($db = null) { if (!empty($this->emulateExecution)) { return []; } $cursor = $this->buildCursor($db); $rows = $this->fetchRows($cursor, true, $this->indexBy); return $this->populate($rows); }
php
public function all($db = null) { if (!empty($this->emulateExecution)) { return []; } $cursor = $this->buildCursor($db); $rows = $this->fetchRows($cursor, true, $this->indexBy); return $this->populate($rows); }
[ "public", "function", "all", "(", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "[", "]", ";", "}", "$", "cursor", "=", "$", "this", "->", "buildCursor", "(", "$", ...
Executes the query and returns all results as an array. @param Connection $db the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return array the query results. If the query results in nothing, an empty array will be returned.
[ "Executes", "the", "query", "and", "returns", "all", "results", "as", "an", "array", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L320-L328
yiisoft/yii2-mongodb
src/Query.php
Query.one
public function one($db = null) { if (!empty($this->emulateExecution)) { return false; } $cursor = $this->buildCursor($db); return $this->fetchRows($cursor, false); }
php
public function one($db = null) { if (!empty($this->emulateExecution)) { return false; } $cursor = $this->buildCursor($db); return $this->fetchRows($cursor, false); }
[ "public", "function", "one", "(", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "false", ";", "}", "$", "cursor", "=", "$", "this", "->", "buildCursor", "(", "$", "...
Executes the query and returns a single row of result. @param Connection $db the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return array|false the first row (in terms of an array) of the query result. `false` is returned if the query results in nothing.
[ "Executes", "the", "query", "and", "returns", "a", "single", "row", "of", "result", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L356-L363
yiisoft/yii2-mongodb
src/Query.php
Query.scalar
public function scalar($db = null) { if (!empty($this->emulateExecution)) { return null; } $originSelect = (array)$this->select; if (!isset($originSelect['_id']) && array_search('_id', $originSelect, true) === false) { $this->select['_id'] = false; } $cursor = $this->buildCursor($db); $row = $this->fetchRows($cursor, false); if (empty($row)) { return false; } return reset($row); }
php
public function scalar($db = null) { if (!empty($this->emulateExecution)) { return null; } $originSelect = (array)$this->select; if (!isset($originSelect['_id']) && array_search('_id', $originSelect, true) === false) { $this->select['_id'] = false; } $cursor = $this->buildCursor($db); $row = $this->fetchRows($cursor, false); if (empty($row)) { return false; } return reset($row); }
[ "public", "function", "scalar", "(", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "null", ";", "}", "$", "originSelect", "=", "(", "array", ")", "$", "this", "->", ...
Returns the query result as a scalar value. The value returned will be the first column in the first row of the query results. Column `_id` will be automatically excluded from select fields, if [[select]] is not empty and `_id` is not selected explicitly. @param Connection $db the MongoDB connection used to generate the query. If this parameter is not given, the `mongodb` application component will be used. @return string|null|false the value of the first column in the first row of the query result. `false` is returned if the query result is empty. @since 2.1.2
[ "Returns", "the", "query", "result", "as", "a", "scalar", "value", ".", "The", "value", "returned", "will", "be", "the", "first", "column", "in", "the", "first", "row", "of", "the", "query", "results", ".", "Column", "_id", "will", "be", "automatically", ...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L376-L395
yiisoft/yii2-mongodb
src/Query.php
Query.column
public function column($db = null) { if (!empty($this->emulateExecution)) { return []; } $originSelect = (array)$this->select; if (!isset($originSelect['_id']) && array_search('_id', $originSelect, true) === false) { $this->select['_id'] = false; } if (is_string($this->indexBy) && $originSelect && count($originSelect) === 1) { $this->select[] = $this->indexBy; } $cursor = $this->buildCursor($db); $rows = $this->fetchRows($cursor, true); if (empty($rows)) { return []; } $results = []; foreach ($rows as $row) { $value = reset($row); if ($this->indexBy === null) { $results[] = $value; } else { if ($this->indexBy instanceof \Closure) { $results[call_user_func($this->indexBy, $row)] = $value; } else { $results[$row[$this->indexBy]] = $value; } } } return $results; }
php
public function column($db = null) { if (!empty($this->emulateExecution)) { return []; } $originSelect = (array)$this->select; if (!isset($originSelect['_id']) && array_search('_id', $originSelect, true) === false) { $this->select['_id'] = false; } if (is_string($this->indexBy) && $originSelect && count($originSelect) === 1) { $this->select[] = $this->indexBy; } $cursor = $this->buildCursor($db); $rows = $this->fetchRows($cursor, true); if (empty($rows)) { return []; } $results = []; foreach ($rows as $row) { $value = reset($row); if ($this->indexBy === null) { $results[] = $value; } else { if ($this->indexBy instanceof \Closure) { $results[call_user_func($this->indexBy, $row)] = $value; } else { $results[$row[$this->indexBy]] = $value; } } } return $results; }
[ "public", "function", "column", "(", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "[", "]", ";", "}", "$", "originSelect", "=", "(", "array", ")", "$", "this", "->...
Executes the query and returns the first column of the result. Column `_id` will be automatically excluded from select fields, if [[select]] is not empty and `_id` is not selected explicitly. @param Connection $db the MongoDB connection used to generate the query. If this parameter is not given, the `mongodb` application component will be used. @return array the first column of the query result. An empty array is returned if the query results in nothing. @since 2.1.2
[ "Executes", "the", "query", "and", "returns", "the", "first", "column", "of", "the", "result", ".", "Column", "_id", "will", "be", "automatically", "excluded", "from", "select", "fields", "if", "[[", "select", "]]", "is", "not", "empty", "and", "_id", "is"...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L406-L443
yiisoft/yii2-mongodb
src/Query.php
Query.modify
public function modify($update, $options = [], $db = null) { if (!empty($this->emulateExecution)) { return null; } $this->prepare(); $collection = $this->getCollection($db); if (!empty($this->orderBy)) { $options['sort'] = $this->orderBy; } $options['fields'] = $this->select; return $collection->findAndModify($this->composeCondition(), $update, $options); }
php
public function modify($update, $options = [], $db = null) { if (!empty($this->emulateExecution)) { return null; } $this->prepare(); $collection = $this->getCollection($db); if (!empty($this->orderBy)) { $options['sort'] = $this->orderBy; } $options['fields'] = $this->select; return $collection->findAndModify($this->composeCondition(), $update, $options); }
[ "public", "function", "modify", "(", "$", "update", ",", "$", "options", "=", "[", "]", ",", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "null", ";", "}", "$", ...
Performs 'findAndModify' query and returns a single row of result. @param array $update update criteria @param array $options list of options in format: optionName => optionValue. @param Connection $db the Mongo connection used to execute the query. @return array|null the original document, or the modified document when $options['new'] is set.
[ "Performs", "findAndModify", "query", "and", "returns", "a", "single", "row", "of", "result", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L452-L467
yiisoft/yii2-mongodb
src/Query.php
Query.count
public function count($q = '*', $db = null) { if (!empty($this->emulateExecution)) { return 0; } $this->prepare(); $collection = $this->getCollection($db); return $collection->count($this->where, $this->options); }
php
public function count($q = '*', $db = null) { if (!empty($this->emulateExecution)) { return 0; } $this->prepare(); $collection = $this->getCollection($db); return $collection->count($this->where, $this->options); }
[ "public", "function", "count", "(", "$", "q", "=", "'*'", ",", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "0", ";", "}", "$", "this", "->", "prepare", "(", ")"...
Returns the number of records. @param string $q kept to match [[QueryInterface]], its value is ignored. @param Connection $db the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return int number of records @throws Exception on failure.
[ "Returns", "the", "number", "of", "records", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L477-L485
yiisoft/yii2-mongodb
src/Query.php
Query.exists
public function exists($db = null) { if (!empty($this->emulateExecution)) { return false; } $cursor = $this->buildCursor($db); foreach ($cursor as $row) { return true; } return false; }
php
public function exists($db = null) { if (!empty($this->emulateExecution)) { return false; } $cursor = $this->buildCursor($db); foreach ($cursor as $row) { return true; } return false; }
[ "public", "function", "exists", "(", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "false", ";", "}", "$", "cursor", "=", "$", "this", "->", "buildCursor", "(", "$", ...
Returns a value indicating whether the query result contains any row of data. @param Connection $db the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return bool whether the query result contains any row of data.
[ "Returns", "a", "value", "indicating", "whether", "the", "query", "result", "contains", "any", "row", "of", "data", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L493-L503
yiisoft/yii2-mongodb
src/Query.php
Query.sum
public function sum($q, $db = null) { if (!empty($this->emulateExecution)) { return 0; } return $this->aggregate($q, 'sum', $db); }
php
public function sum($q, $db = null) { if (!empty($this->emulateExecution)) { return 0; } return $this->aggregate($q, 'sum', $db); }
[ "public", "function", "sum", "(", "$", "q", ",", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "0", ";", "}", "return", "$", "this", "->", "aggregate", "(", "$", ...
Returns the sum of the specified column values. @param string $q the column name. Make sure you properly quote column names in the expression. @param Connection $db the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return int the sum of the specified column values
[ "Returns", "the", "sum", "of", "the", "specified", "column", "values", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L513-L519
yiisoft/yii2-mongodb
src/Query.php
Query.average
public function average($q, $db = null) { if (!empty($this->emulateExecution)) { return 0; } return $this->aggregate($q, 'avg', $db); }
php
public function average($q, $db = null) { if (!empty($this->emulateExecution)) { return 0; } return $this->aggregate($q, 'avg', $db); }
[ "public", "function", "average", "(", "$", "q", ",", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "0", ";", "}", "return", "$", "this", "->", "aggregate", "(", "$"...
Returns the average of the specified column values. @param string $q the column name. Make sure you properly quote column names in the expression. @param Connection $db the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return int the average of the specified column values.
[ "Returns", "the", "average", "of", "the", "specified", "column", "values", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L529-L535
yiisoft/yii2-mongodb
src/Query.php
Query.aggregate
protected function aggregate($column, $operator, $db) { if (!empty($this->emulateExecution)) { return null; } $this->prepare(); $collection = $this->getCollection($db); $pipelines = []; if ($this->where !== null) { $pipelines[] = ['$match' => $this->where]; } $pipelines[] = [ '$group' => [ '_id' => '1', 'total' => [ '$' . $operator => '$' . $column ], ] ]; $result = $collection->aggregate($pipelines); if (array_key_exists(0, $result)) { return $result[0]['total']; } return null; }
php
protected function aggregate($column, $operator, $db) { if (!empty($this->emulateExecution)) { return null; } $this->prepare(); $collection = $this->getCollection($db); $pipelines = []; if ($this->where !== null) { $pipelines[] = ['$match' => $this->where]; } $pipelines[] = [ '$group' => [ '_id' => '1', 'total' => [ '$' . $operator => '$' . $column ], ] ]; $result = $collection->aggregate($pipelines); if (array_key_exists(0, $result)) { return $result[0]['total']; } return null; }
[ "protected", "function", "aggregate", "(", "$", "column", ",", "$", "operator", ",", "$", "db", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "prepare", ...
Performs the aggregation for the given column. @param string $column column name. @param string $operator aggregation operator. @param Connection $db the database connection used to execute the query. @return int aggregation result.
[ "Performs", "the", "aggregation", "for", "the", "given", "column", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L570-L595
yiisoft/yii2-mongodb
src/Query.php
Query.distinct
public function distinct($q, $db = null) { if (!empty($this->emulateExecution)) { return []; } $this->prepare(); $collection = $this->getCollection($db); if ($this->where !== null) { $condition = $this->where; } else { $condition = []; } $result = $collection->distinct($q, $condition); if ($result === false) { return []; } return $result; }
php
public function distinct($q, $db = null) { if (!empty($this->emulateExecution)) { return []; } $this->prepare(); $collection = $this->getCollection($db); if ($this->where !== null) { $condition = $this->where; } else { $condition = []; } $result = $collection->distinct($q, $condition); if ($result === false) { return []; } return $result; }
[ "public", "function", "distinct", "(", "$", "q", ",", "$", "db", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "emulateExecution", ")", ")", "{", "return", "[", "]", ";", "}", "$", "this", "->", "prepare", "(", ")", ";...
Returns a list of distinct values for the given column across a collection. @param string $q column to use. @param Connection $db the MongoDB connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used. @return array array of distinct values
[ "Returns", "a", "list", "of", "distinct", "values", "for", "the", "given", "column", "across", "a", "collection", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/Query.php#L604-L622
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.createCollection
public function createCollection($collectionName, array $options = []) { $document = array_merge(['create' => $collectionName], $options); if (isset($document['indexOptionDefaults'])) { $document['indexOptionDefaults'] = (object) $document['indexOptionDefaults']; } if (isset($document['storageEngine'])) { $document['storageEngine'] = (object) $document['storageEngine']; } if (isset($document['validator'])) { $document['validator'] = (object) $document['validator']; } return $document; }
php
public function createCollection($collectionName, array $options = []) { $document = array_merge(['create' => $collectionName], $options); if (isset($document['indexOptionDefaults'])) { $document['indexOptionDefaults'] = (object) $document['indexOptionDefaults']; } if (isset($document['storageEngine'])) { $document['storageEngine'] = (object) $document['storageEngine']; } if (isset($document['validator'])) { $document['validator'] = (object) $document['validator']; } return $document; }
[ "public", "function", "createCollection", "(", "$", "collectionName", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "document", "=", "array_merge", "(", "[", "'create'", "=>", "$", "collectionName", "]", ",", "$", "options", ")", ";", "if",...
Generates 'create collection' command. https://docs.mongodb.com/manual/reference/method/db.createCollection/ @param string $collectionName collection name. @param array $options collection options in format: "name" => "value" @return array command document.
[ "Generates", "create", "collection", "command", ".", "https", ":", "//", "docs", ".", "mongodb", ".", "com", "/", "manual", "/", "reference", "/", "method", "/", "db", ".", "createCollection", "/" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L85-L100
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.createIndexes
public function createIndexes($databaseName, $collectionName, $indexes) { $normalizedIndexes = []; foreach ($indexes as $index) { if (!isset($index['key'])) { throw new InvalidParamException('"key" is required for index specification'); } $index['key'] = $this->buildSortFields($index['key']); if (!isset($index['ns'])) { if ($databaseName === null) { $databaseName = $this->db->getDefaultDatabaseName(); } $index['ns'] = $databaseName . '.' . $collectionName; } if (!isset($index['name'])) { $index['name'] = $this->generateIndexName($index['key']); } $normalizedIndexes[] = $index; } return [ 'createIndexes' => $collectionName, 'indexes' => $normalizedIndexes, ]; }
php
public function createIndexes($databaseName, $collectionName, $indexes) { $normalizedIndexes = []; foreach ($indexes as $index) { if (!isset($index['key'])) { throw new InvalidParamException('"key" is required for index specification'); } $index['key'] = $this->buildSortFields($index['key']); if (!isset($index['ns'])) { if ($databaseName === null) { $databaseName = $this->db->getDefaultDatabaseName(); } $index['ns'] = $databaseName . '.' . $collectionName; } if (!isset($index['name'])) { $index['name'] = $this->generateIndexName($index['key']); } $normalizedIndexes[] = $index; } return [ 'createIndexes' => $collectionName, 'indexes' => $normalizedIndexes, ]; }
[ "public", "function", "createIndexes", "(", "$", "databaseName", ",", "$", "collectionName", ",", "$", "indexes", ")", "{", "$", "normalizedIndexes", "=", "[", "]", ";", "foreach", "(", "$", "indexes", "as", "$", "index", ")", "{", "if", "(", "!", "iss...
Generates create indexes command. @see https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/ @param string|null $databaseName database name. @param string $collectionName collection name. @param array[] $indexes indexes specification. Each specification should be an array in format: optionName => value The main options are: - keys: array, column names with sort order, to be indexed. This option is mandatory. - unique: bool, whether to create unique index. - name: string, the name of the index, if not set it will be generated automatically. - background: bool, whether to bind index in the background. - sparse: bool, whether index should reference only documents with the specified field. See [[https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#options-for-all-index-types]] for the full list of options. @return array command document.
[ "Generates", "create", "indexes", "command", ".", "@see", "https", ":", "//", "docs", ".", "mongodb", ".", "com", "/", "manual", "/", "reference", "/", "method", "/", "db", ".", "collection", ".", "createIndex", "/", "@param", "string|null", "$databaseName",...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L141-L170
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.generateIndexName
public function generateIndexName($columns) { $parts = []; foreach ($columns as $column => $order) { $parts[] = $column . '_' . $order; } return implode('_', $parts); }
php
public function generateIndexName($columns) { $parts = []; foreach ($columns as $column => $order) { $parts[] = $column . '_' . $order; } return implode('_', $parts); }
[ "public", "function", "generateIndexName", "(", "$", "columns", ")", "{", "$", "parts", "=", "[", "]", ";", "foreach", "(", "$", "columns", "as", "$", "column", "=>", "$", "order", ")", "{", "$", "parts", "[", "]", "=", "$", "column", ".", "'_'", ...
Generates index name for the given column orders. Columns should be normalized using [[buildSortFields()]] before being passed to this method. @param array $columns columns with sort order. @return string index name.
[ "Generates", "index", "name", "for", "the", "given", "column", "orders", ".", "Columns", "should", "be", "normalized", "using", "[[", "buildSortFields", "()", "]]", "before", "being", "passed", "to", "this", "method", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L178-L185
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.count
public function count($collectionName, $condition = [], $options = []) { $document = ['count' => $collectionName]; if (!empty($condition)) { $document['query'] = (object) $this->buildCondition($condition); } return array_merge($document, $options); }
php
public function count($collectionName, $condition = [], $options = []) { $document = ['count' => $collectionName]; if (!empty($condition)) { $document['query'] = (object) $this->buildCondition($condition); } return array_merge($document, $options); }
[ "public", "function", "count", "(", "$", "collectionName", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "document", "=", "[", "'count'", "=>", "$", "collectionName", "]", ";", "if", "(", "!", "empty", "("...
Generates count command @param string $collectionName @param array $condition @param array $options @return array command document.
[ "Generates", "count", "command" ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L223-L232
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.findAndModify
public function findAndModify($collectionName, $condition = [], $update = [], $options = []) { $document = array_merge(['findAndModify' => $collectionName], $options); if (!empty($condition)) { $options['query'] = $this->buildCondition($condition); } if (!empty($update)) { $options['update'] = $update; } if (isset($options['fields'])) { $options['fields'] = $this->buildSelectFields($options['fields']); } if (isset($options['sort'])) { $options['sort'] = $this->buildSortFields($options['sort']); } foreach (['fields', 'query', 'sort', 'update'] as $name) { if (isset($options[$name])) { $document[$name] = (object) $options[$name]; } } return $document; }
php
public function findAndModify($collectionName, $condition = [], $update = [], $options = []) { $document = array_merge(['findAndModify' => $collectionName], $options); if (!empty($condition)) { $options['query'] = $this->buildCondition($condition); } if (!empty($update)) { $options['update'] = $update; } if (isset($options['fields'])) { $options['fields'] = $this->buildSelectFields($options['fields']); } if (isset($options['sort'])) { $options['sort'] = $this->buildSortFields($options['sort']); } foreach (['fields', 'query', 'sort', 'update'] as $name) { if (isset($options[$name])) { $document[$name] = (object) $options[$name]; } } return $document; }
[ "public", "function", "findAndModify", "(", "$", "collectionName", ",", "$", "condition", "=", "[", "]", ",", "$", "update", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "document", "=", "array_merge", "(", "[", "'findAndModify'", ...
Generates 'find and modify' command. @param string $collectionName collection name @param array $condition filter condition @param array $update update criteria @param array $options list of options in format: optionName => optionValue. @return array command document.
[ "Generates", "find", "and", "modify", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L242-L269
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.distinct
public function distinct($collectionName, $fieldName, $condition = [], $options = []) { $document = array_merge( [ 'distinct' => $collectionName, 'key' => $fieldName, ], $options ); if (!empty($condition)) { $document['query'] = $this->buildCondition($condition); } return $document; }
php
public function distinct($collectionName, $fieldName, $condition = [], $options = []) { $document = array_merge( [ 'distinct' => $collectionName, 'key' => $fieldName, ], $options ); if (!empty($condition)) { $document['query'] = $this->buildCondition($condition); } return $document; }
[ "public", "function", "distinct", "(", "$", "collectionName", ",", "$", "fieldName", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "document", "=", "array_merge", "(", "[", "'distinct'", "=>", "$", "collection...
Generates 'distinct' command. @param string $collectionName collection name. @param string $fieldName target field name. @param array $condition filter condition @param array $options list of options in format: optionName => optionValue. @return array command document.
[ "Generates", "distinct", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L279-L294
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.group
public function group($collectionName, $keys, $initial, $reduce, $options = []) { if (!($reduce instanceof Javascript)) { $reduce = new Javascript((string) $reduce); } if (isset($options['condition'])) { $options['cond'] = $this->buildCondition($options['condition']); unset($options['condition']); } if (isset($options['finalize'])) { if (!($options['finalize'] instanceof Javascript)) { $options['finalize'] = new Javascript((string) $options['finalize']); } } if (isset($options['keyf'])) { $options['$keyf'] = $options['keyf']; unset($options['keyf']); } if (isset($options['$keyf'])) { if (!($options['$keyf'] instanceof Javascript)) { $options['$keyf'] = new Javascript((string) $options['$keyf']); } } $document = [ 'group' => array_merge( [ 'ns' => $collectionName, 'key' => $keys, 'initial' => $initial, '$reduce' => $reduce, ], $options ) ]; return $document; }
php
public function group($collectionName, $keys, $initial, $reduce, $options = []) { if (!($reduce instanceof Javascript)) { $reduce = new Javascript((string) $reduce); } if (isset($options['condition'])) { $options['cond'] = $this->buildCondition($options['condition']); unset($options['condition']); } if (isset($options['finalize'])) { if (!($options['finalize'] instanceof Javascript)) { $options['finalize'] = new Javascript((string) $options['finalize']); } } if (isset($options['keyf'])) { $options['$keyf'] = $options['keyf']; unset($options['keyf']); } if (isset($options['$keyf'])) { if (!($options['$keyf'] instanceof Javascript)) { $options['$keyf'] = new Javascript((string) $options['$keyf']); } } $document = [ 'group' => array_merge( [ 'ns' => $collectionName, 'key' => $keys, 'initial' => $initial, '$reduce' => $reduce, ], $options ) ]; return $document; }
[ "public", "function", "group", "(", "$", "collectionName", ",", "$", "keys", ",", "$", "initial", ",", "$", "reduce", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "(", "$", "reduce", "instanceof", "Javascript", ")", ")", "{", "$", ...
Generates 'group' command. @param string $collectionName @@param mixed $keys fields to group by. If an array or non-code object is passed, it will be the key used to group results. If instance of [[Javascript]] passed, it will be treated as a function that returns the key to group by. @param array $initial Initial value of the aggregation counter object. @param Javascript|string $reduce function that takes two arguments (the current document and the aggregation to this point) and does the aggregation. Argument will be automatically cast to [[Javascript]]. @param array $options optional parameters to the group command. Valid options include: - condition - criteria for including a document in the aggregation. - finalize - function called once per unique key that takes the final output of the reduce function. @return array command document.
[ "Generates", "group", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L311-L351
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.mapReduce
public function mapReduce($collectionName, $map, $reduce, $out, $condition = [], $options = []) { if (!($map instanceof Javascript)) { $map = new Javascript((string) $map); } if (!($reduce instanceof Javascript)) { $reduce = new Javascript((string) $reduce); } $document = [ 'mapReduce' => $collectionName, 'map' => $map, 'reduce' => $reduce, 'out' => $out ]; if (!empty($condition)) { $document['query'] = $this->buildCondition($condition); } if (!empty($options)) { $document = array_merge($document, $options); } return $document; }
php
public function mapReduce($collectionName, $map, $reduce, $out, $condition = [], $options = []) { if (!($map instanceof Javascript)) { $map = new Javascript((string) $map); } if (!($reduce instanceof Javascript)) { $reduce = new Javascript((string) $reduce); } $document = [ 'mapReduce' => $collectionName, 'map' => $map, 'reduce' => $reduce, 'out' => $out ]; if (!empty($condition)) { $document['query'] = $this->buildCondition($condition); } if (!empty($options)) { $document = array_merge($document, $options); } return $document; }
[ "public", "function", "mapReduce", "(", "$", "collectionName", ",", "$", "map", ",", "$", "reduce", ",", "$", "out", ",", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "!", "(", "$", "map", "instanceof"...
Generates 'map-reduce' command. @see https://docs.mongodb.com/manual/core/map-reduce/ @param string $collectionName collection name. @param \MongoDB\BSON\Javascript|string $map function, which emits map data from collection. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param \MongoDB\BSON\Javascript|string $reduce function that takes two arguments (the map key and the map values) and does the aggregation. Argument will be automatically cast to [[\MongoDB\BSON\Javascript]]. @param string|array $out output collection name. It could be a string for simple output ('outputCollection'), or an array for parametrized output (['merge' => 'outputCollection']). You can pass ['inline' => true] to fetch the result at once without temporary collection usage. @param array $condition filter condition for including a document in the aggregation. @param array $options additional optional parameters to the mapReduce command. Valid options include: - sort: array, key to sort the input documents. The sort key must be in an existing index for this collection. - limit: int, the maximum number of documents to return in the collection. - finalize: \MongoDB\BSON\Javascript|string, function, which follows the reduce method and modifies the output. - scope: array, specifies global variables that are accessible in the map, reduce and finalize functions. - jsMode: bool, specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions. - verbose: bool, specifies whether to include the timing information in the result information. @return array command document.
[ "Generates", "map", "-", "reduce", "command", ".", "@see", "https", ":", "//", "docs", ".", "mongodb", ".", "com", "/", "manual", "/", "core", "/", "map", "-", "reduce", "/", "@param", "string", "$collectionName", "collection", "name", ".", "@param", "\\...
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L377-L402
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.aggregate
public function aggregate($collectionName, $pipelines, $options = []) { foreach ($pipelines as $key => $pipeline) { if (isset($pipeline['$match'])) { $pipelines[$key]['$match'] = $this->buildCondition($pipeline['$match']); } } $document = array_merge( [ 'aggregate' => $collectionName, 'pipeline' => $pipelines, 'allowDiskUse' => false, ], $options ); return $document; }
php
public function aggregate($collectionName, $pipelines, $options = []) { foreach ($pipelines as $key => $pipeline) { if (isset($pipeline['$match'])) { $pipelines[$key]['$match'] = $this->buildCondition($pipeline['$match']); } } $document = array_merge( [ 'aggregate' => $collectionName, 'pipeline' => $pipelines, 'allowDiskUse' => false, ], $options ); return $document; }
[ "public", "function", "aggregate", "(", "$", "collectionName", ",", "$", "pipelines", ",", "$", "options", "=", "[", "]", ")", "{", "foreach", "(", "$", "pipelines", "as", "$", "key", "=>", "$", "pipeline", ")", "{", "if", "(", "isset", "(", "$", "...
Generates 'aggregate' command. @param string $collectionName collection name @param array $pipelines list of pipeline operators. @param array $options optional parameters. @return array command document.
[ "Generates", "aggregate", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L411-L429
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.explain
public function explain($collectionName, $query) { $query = array_merge( ['find' => $collectionName], $query ); if (isset($query['filter'])) { $query['filter'] = (object) $this->buildCondition($query['filter']); } if (isset($query['projection'])) { $query['projection'] = $this->buildSelectFields($query['projection']); } if (isset($query['sort'])) { $query['sort'] = $this->buildSortFields($query['sort']); } return [ 'explain' => $query, ]; }
php
public function explain($collectionName, $query) { $query = array_merge( ['find' => $collectionName], $query ); if (isset($query['filter'])) { $query['filter'] = (object) $this->buildCondition($query['filter']); } if (isset($query['projection'])) { $query['projection'] = $this->buildSelectFields($query['projection']); } if (isset($query['sort'])) { $query['sort'] = $this->buildSortFields($query['sort']); } return [ 'explain' => $query, ]; }
[ "public", "function", "explain", "(", "$", "collectionName", ",", "$", "query", ")", "{", "$", "query", "=", "array_merge", "(", "[", "'find'", "=>", "$", "collectionName", "]", ",", "$", "query", ")", ";", "if", "(", "isset", "(", "$", "query", "[",...
Generates 'explain' command. @param string $collectionName collection name. @param array $query query options. @return array command document.
[ "Generates", "explain", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L437-L457
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.listDatabases
public function listDatabases($condition = [], $options = []) { $document = array_merge(['listDatabases' => 1], $options); if (!empty($condition)) { $document['filter'] = (object)$this->buildCondition($condition); } return $document; }
php
public function listDatabases($condition = [], $options = []) { $document = array_merge(['listDatabases' => 1], $options); if (!empty($condition)) { $document['filter'] = (object)$this->buildCondition($condition); } return $document; }
[ "public", "function", "listDatabases", "(", "$", "condition", "=", "[", "]", ",", "$", "options", "=", "[", "]", ")", "{", "$", "document", "=", "array_merge", "(", "[", "'listDatabases'", "=>", "1", "]", ",", "$", "options", ")", ";", "if", "(", "...
Generates 'listDatabases' command. @param array $condition filter condition. @param array $options command options. @return array command document.
[ "Generates", "listDatabases", "command", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L465-L472
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.buildSelectFields
public function buildSelectFields($fields) { $selectFields = []; foreach ((array)$fields as $key => $value) { if (is_int($key)) { $selectFields[$value] = true; } else { $selectFields[$key] = is_scalar($value) ? (bool)$value : $value; } } return $selectFields; }
php
public function buildSelectFields($fields) { $selectFields = []; foreach ((array)$fields as $key => $value) { if (is_int($key)) { $selectFields[$value] = true; } else { $selectFields[$key] = is_scalar($value) ? (bool)$value : $value; } } return $selectFields; }
[ "public", "function", "buildSelectFields", "(", "$", "fields", ")", "{", "$", "selectFields", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "fields", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key"...
Normalizes fields list for the MongoDB select composition. @param array|string $fields raw fields. @return array normalized select fields.
[ "Normalizes", "fields", "list", "for", "the", "MongoDB", "select", "composition", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L496-L507
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.buildSortFields
public function buildSortFields($fields) { $sortFields = []; foreach ((array)$fields as $key => $value) { if (is_int($key)) { $sortFields[$value] = +1; } else { if ($value === SORT_ASC) { $value = +1; } elseif ($value === SORT_DESC) { $value = -1; } $sortFields[$key] = $value; } } return $sortFields; }
php
public function buildSortFields($fields) { $sortFields = []; foreach ((array)$fields as $key => $value) { if (is_int($key)) { $sortFields[$value] = +1; } else { if ($value === SORT_ASC) { $value = +1; } elseif ($value === SORT_DESC) { $value = -1; } $sortFields[$key] = $value; } } return $sortFields; }
[ "public", "function", "buildSortFields", "(", "$", "fields", ")", "{", "$", "sortFields", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "fields", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "key", ...
Normalizes fields list for the MongoDB sort composition. @param array|string $fields raw fields. @return array normalized sort fields.
[ "Normalizes", "fields", "list", "for", "the", "MongoDB", "sort", "composition", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L514-L530
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.normalizeConditionKeyword
protected function normalizeConditionKeyword($key) { static $map = [ 'AND' => '$and', 'OR' => '$or', 'IN' => '$in', 'NOT IN' => '$nin', ]; $matchKey = strtoupper($key); if (array_key_exists($matchKey, $map)) { return $map[$matchKey]; } return $key; }
php
protected function normalizeConditionKeyword($key) { static $map = [ 'AND' => '$and', 'OR' => '$or', 'IN' => '$in', 'NOT IN' => '$nin', ]; $matchKey = strtoupper($key); if (array_key_exists($matchKey, $map)) { return $map[$matchKey]; } return $key; }
[ "protected", "function", "normalizeConditionKeyword", "(", "$", "key", ")", "{", "static", "$", "map", "=", "[", "'AND'", "=>", "'$and'", ",", "'OR'", "=>", "'$or'", ",", "'IN'", "=>", "'$in'", ",", "'NOT IN'", "=>", "'$nin'", ",", "]", ";", "$", "matc...
Converts "\yii\db\*" quick condition keyword into actual Mongo condition keyword. @param string $key raw condition key. @return string actual key.
[ "Converts", "\\", "yii", "\\", "db", "\\", "*", "quick", "condition", "keyword", "into", "actual", "Mongo", "condition", "keyword", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L537-L550
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.ensureMongoId
protected function ensureMongoId($rawId) { if (is_array($rawId)) { $result = []; foreach ($rawId as $key => $value) { $result[$key] = $this->ensureMongoId($value); } return $result; } elseif (is_object($rawId)) { if ($rawId instanceof ObjectID) { return $rawId; } else { $rawId = (string) $rawId; } } try { $mongoId = new ObjectID($rawId); } catch (InvalidArgumentException $e) { // invalid id format $mongoId = $rawId; } return $mongoId; }
php
protected function ensureMongoId($rawId) { if (is_array($rawId)) { $result = []; foreach ($rawId as $key => $value) { $result[$key] = $this->ensureMongoId($value); } return $result; } elseif (is_object($rawId)) { if ($rawId instanceof ObjectID) { return $rawId; } else { $rawId = (string) $rawId; } } try { $mongoId = new ObjectID($rawId); } catch (InvalidArgumentException $e) { // invalid id format $mongoId = $rawId; } return $mongoId; }
[ "protected", "function", "ensureMongoId", "(", "$", "rawId", ")", "{", "if", "(", "is_array", "(", "$", "rawId", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "rawId", "as", "$", "key", "=>", "$", "value", ")", "{", "$", ...
Converts given value into [[ObjectID]] instance. If array given, each element of it will be processed. @param mixed $rawId raw id(s). @return array|ObjectID normalized id(s).
[ "Converts", "given", "value", "into", "[[", "ObjectID", "]]", "instance", ".", "If", "array", "given", "each", "element", "of", "it", "will", "be", "processed", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L558-L582
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.buildCondition
public function buildCondition($condition) { static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => 'buildAndCondition', 'OR' => 'buildOrCondition', 'BETWEEN' => 'buildBetweenCondition', 'NOT BETWEEN' => 'buildBetweenCondition', 'IN' => 'buildInCondition', 'NOT IN' => 'buildInCondition', 'REGEX' => 'buildRegexCondition', 'LIKE' => 'buildLikeCondition', ]; if (!is_array($condition)) { throw new InvalidParamException('Condition should be an array.'); } elseif (empty($condition)) { return []; } if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ... $operator = strtoupper($condition[0]); if (isset($builders[$operator])) { $method = $builders[$operator]; } else { $operator = $condition[0]; $method = 'buildSimpleCondition'; } array_shift($condition); return $this->$method($operator, $condition); } // hash format: 'column1' => 'value1', 'column2' => 'value2', ... return $this->buildHashCondition($condition); }
php
public function buildCondition($condition) { static $builders = [ 'NOT' => 'buildNotCondition', 'AND' => 'buildAndCondition', 'OR' => 'buildOrCondition', 'BETWEEN' => 'buildBetweenCondition', 'NOT BETWEEN' => 'buildBetweenCondition', 'IN' => 'buildInCondition', 'NOT IN' => 'buildInCondition', 'REGEX' => 'buildRegexCondition', 'LIKE' => 'buildLikeCondition', ]; if (!is_array($condition)) { throw new InvalidParamException('Condition should be an array.'); } elseif (empty($condition)) { return []; } if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ... $operator = strtoupper($condition[0]); if (isset($builders[$operator])) { $method = $builders[$operator]; } else { $operator = $condition[0]; $method = 'buildSimpleCondition'; } array_shift($condition); return $this->$method($operator, $condition); } // hash format: 'column1' => 'value1', 'column2' => 'value2', ... return $this->buildHashCondition($condition); }
[ "public", "function", "buildCondition", "(", "$", "condition", ")", "{", "static", "$", "builders", "=", "[", "'NOT'", "=>", "'buildNotCondition'", ",", "'AND'", "=>", "'buildAndCondition'", ",", "'OR'", "=>", "'buildOrCondition'", ",", "'BETWEEN'", "=>", "'buil...
Parses the condition specification and generates the corresponding Mongo condition. @param array $condition the condition specification. Please refer to [[Query::where()]] on how to specify a condition. @return array the generated Mongo condition @throws InvalidParamException if the condition is in bad format
[ "Parses", "the", "condition", "specification", "and", "generates", "the", "corresponding", "Mongo", "condition", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L591-L623
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.buildHashCondition
public function buildHashCondition($condition) { $result = []; foreach ($condition as $name => $value) { if (strncmp('$', $name, 1) === 0) { // Native Mongo condition: $result[$name] = $value; } else { if (is_array($value)) { if (ArrayHelper::isIndexed($value)) { // Quick IN condition: $result = array_merge($result, $this->buildInCondition('IN', [$name, $value])); } else { // Mongo complex condition: $result[$name] = $value; } } else { // Direct match: if ($name == '_id') { $value = $this->ensureMongoId($value); } $result[$name] = $value; } } } return $result; }
php
public function buildHashCondition($condition) { $result = []; foreach ($condition as $name => $value) { if (strncmp('$', $name, 1) === 0) { // Native Mongo condition: $result[$name] = $value; } else { if (is_array($value)) { if (ArrayHelper::isIndexed($value)) { // Quick IN condition: $result = array_merge($result, $this->buildInCondition('IN', [$name, $value])); } else { // Mongo complex condition: $result[$name] = $value; } } else { // Direct match: if ($name == '_id') { $value = $this->ensureMongoId($value); } $result[$name] = $value; } } } return $result; }
[ "public", "function", "buildHashCondition", "(", "$", "condition", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "condition", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "strncmp", "(", "'$'", ",", "$", "name", "...
Creates a condition based on column-value pairs. @param array $condition the condition specification. @return array the generated Mongo condition.
[ "Creates", "a", "condition", "based", "on", "column", "-", "value", "pairs", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L630-L657
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.buildNotCondition
public function buildNotCondition($operator, $operands) { if (count($operands) !== 2) { throw new InvalidParamException("Operator '$operator' requires two operands."); } list($name, $value) = $operands; $result = []; if (is_array($value)) { $result[$name] = ['$not' => $this->buildCondition($value)]; } else { if ($name == '_id') { $value = $this->ensureMongoId($value); } $result[$name] = ['$ne' => $value]; } return $result; }
php
public function buildNotCondition($operator, $operands) { if (count($operands) !== 2) { throw new InvalidParamException("Operator '$operator' requires two operands."); } list($name, $value) = $operands; $result = []; if (is_array($value)) { $result[$name] = ['$not' => $this->buildCondition($value)]; } else { if ($name == '_id') { $value = $this->ensureMongoId($value); } $result[$name] = ['$ne' => $value]; } return $result; }
[ "public", "function", "buildNotCondition", "(", "$", "operator", ",", "$", "operands", ")", "{", "if", "(", "count", "(", "$", "operands", ")", "!==", "2", ")", "{", "throw", "new", "InvalidParamException", "(", "\"Operator '$operator' requires two operands.\"", ...
Composes `NOT` condition. @param string $operator the operator to use for connecting the given operands @param array $operands the Mongo conditions to connect. @return array the generated Mongo condition. @throws InvalidParamException if wrong number of operands have been given.
[ "Composes", "NOT", "condition", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L666-L685
yiisoft/yii2-mongodb
src/QueryBuilder.php
QueryBuilder.buildAndCondition
public function buildAndCondition($operator, $operands) { $operator = $this->normalizeConditionKeyword($operator); $parts = []; foreach ($operands as $operand) { $parts[] = $this->buildCondition($operand); } return [$operator => $parts]; }
php
public function buildAndCondition($operator, $operands) { $operator = $this->normalizeConditionKeyword($operator); $parts = []; foreach ($operands as $operand) { $parts[] = $this->buildCondition($operand); } return [$operator => $parts]; }
[ "public", "function", "buildAndCondition", "(", "$", "operator", ",", "$", "operands", ")", "{", "$", "operator", "=", "$", "this", "->", "normalizeConditionKeyword", "(", "$", "operator", ")", ";", "$", "parts", "=", "[", "]", ";", "foreach", "(", "$", ...
Connects two or more conditions with the `AND` operator. @param string $operator the operator to use for connecting the given operands @param array $operands the Mongo conditions to connect. @return array the generated Mongo condition.
[ "Connects", "two", "or", "more", "conditions", "with", "the", "AND", "operator", "." ]
train
https://github.com/yiisoft/yii2-mongodb/blob/7f8d9862ac6c133d63afda171860ca9b61563d27/src/QueryBuilder.php#L693-L702