芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/giga.mgaplay.com.br/vendor/mongodb/mongodb/src/Operation/MapReduce.php
isDefault()) { unset($options['readConcern']); } if (isset($options['writeConcern']) && $options['writeConcern']->isDefault()) { unset($options['writeConcern']); } // Handle deprecation of CodeWScope if ($map->getScope() !== null) { @trigger_error('Use of Javascript with scope in "$map" argument for MapReduce is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.', E_USER_DEPRECATED); } if ($reduce->getScope() !== null) { @trigger_error('Use of Javascript with scope in "$reduce" argument for MapReduce is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.', E_USER_DEPRECATED); } if (isset($options['finalize']) && $options['finalize']->getScope() !== null) { @trigger_error('Use of Javascript with scope in "finalize" option for MapReduce is deprecated. Put all scope variables in the "scope" option of the MapReduce operation.', E_USER_DEPRECATED); } $this->checkOutDeprecations($out); $this->databaseName = (string) $databaseName; $this->collectionName = (string) $collectionName; $this->map = $map; $this->reduce = $reduce; $this->out = $out; $this->options = $options; } /** * Execute the operation. * * @see Executable::execute() * @param Server $server * @return MapReduceResult * @throws UnexpectedValueException if the command response was malformed * @throws UnsupportedException if collation, read concern, or write concern is used and unsupported * @throws DriverRuntimeException for other driver errors (e.g. connection errors) */ public function execute(Server $server) { if (isset($this->options['collation']) && ! server_supports_feature($server, self::$wireVersionForCollation)) { throw UnsupportedException::collationNotSupported(); } if (isset($this->options['readConcern']) && ! server_supports_feature($server, self::$wireVersionForReadConcern)) { throw UnsupportedException::readConcernNotSupported(); } if (isset($this->options['writeConcern']) && ! server_supports_feature($server, self::$wireVersionForWriteConcern)) { throw UnsupportedException::writeConcernNotSupported(); } $inTransaction = isset($this->options['session']) && $this->options['session']->isInTransaction(); if ($inTransaction) { if (isset($this->options['readConcern'])) { throw UnsupportedException::readConcernNotSupportedInTransaction(); } if (isset($this->options['writeConcern'])) { throw UnsupportedException::writeConcernNotSupportedInTransaction(); } } $hasOutputCollection = ! is_mapreduce_output_inline($this->out); $command = $this->createCommand($server); $options = $this->createOptions($hasOutputCollection); /* If the mapReduce operation results in a write, use * executeReadWriteCommand to ensure we're handling the writeConcern * option. * In other cases, we use executeCommand as this will prevent the * mapReduce operation from being retried when retryReads is enabled. * See https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#unsupported-read-operations. */ $cursor = $hasOutputCollection ? $server->executeReadWriteCommand($this->databaseName, $command, $options) : $server->executeCommand($this->databaseName, $command, $options); if (isset($this->options['typeMap']) && ! $hasOutputCollection) { $cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'results.$')); } $result = current($cursor->toArray()); $getIterator = $this->createGetIteratorCallable($result, $server); return new MapReduceResult($getIterator, $result); } /** * @param string|array|object $out * @return void */ private function checkOutDeprecations($out) { if (is_string($out)) { return; } $out = (array) $out; if (isset($out['nonAtomic']) && ! $out['nonAtomic']) { @trigger_error('Specifying false for "out.nonAtomic" is deprecated.', E_USER_DEPRECATED); } if (isset($out['sharded']) && ! $out['sharded']) { @trigger_error('Specifying false for "out.sharded" is deprecated.', E_USER_DEPRECATED); } } /** * Create the mapReduce command. * * @param Server $server * @return Command */ private function createCommand(Server $server) { $cmd = [ 'mapReduce' => $this->collectionName, 'map' => $this->map, 'reduce' => $this->reduce, 'out' => $this->out, ]; foreach (['finalize', 'jsMode', 'limit', 'maxTimeMS', 'verbose'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } foreach (['collation', 'query', 'scope', 'sort'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = (object) $this->options[$option]; } } if ( ! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation) ) { $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } return new Command($cmd); } /** * Creates a callable for MapReduceResult::getIterator(). * * @param stdClass $result * @param Server $server * @return callable * @throws UnexpectedValueException if the command response was malformed */ private function createGetIteratorCallable(stdClass $result, Server $server) { // Inline results can be wrapped with an ArrayIterator if (isset($result->results) && is_array($result->results)) { $results = $result->results; return function () use ($results) { return new ArrayIterator($results); }; } if (isset($result->result) && (is_string($result->result) || is_object($result->result))) { $options = isset($this->options['typeMap']) ? ['typeMap' => $this->options['typeMap']] : []; $find = is_string($result->result) ? new Find($this->databaseName, $result->result, [], $options) : new Find($result->result->db, $result->result->collection, [], $options); return function () use ($find, $server) { return $find->execute($server); }; } throw new UnexpectedValueException('mapReduce command did not return inline results or an output collection'); } /** * Create options for executing the command. * * @see http://php.net/manual/en/mongodb-driver-server.executereadcommand.php * @see http://php.net/manual/en/mongodb-driver-server.executereadwritecommand.php * @param boolean $hasOutputCollection * @return array */ private function createOptions($hasOutputCollection) { $options = []; if (isset($this->options['readConcern'])) { $options['readConcern'] = $this->options['readConcern']; } if (! $hasOutputCollection && isset($this->options['readPreference'])) { $options['readPreference'] = $this->options['readPreference']; } if (isset($this->options['session'])) { $options['session'] = $this->options['session']; } if ($hasOutputCollection && isset($this->options['writeConcern'])) { $options['writeConcern'] = $this->options['writeConcern']; } return $options; } }