芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/public_html/cepali/cache/stores/mongodb/MongoDB/Operation/MapReduce.php
isDefault()) { unset($options['readConcern']); } if (isset($options['writeConcern']) && $options['writeConcern']->isDefault()) { unset($options['writeConcern']); } $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']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForCollation)) { throw UnsupportedException::collationNotSupported(); } if (isset($this->options['readConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForReadConcern)) { throw UnsupportedException::readConcernNotSupported(); } if (isset($this->options['writeConcern']) && ! \MongoDB\server_supports_feature($server, self::$wireVersionForWriteConcern)) { throw UnsupportedException::writeConcernNotSupported(); } $hasOutputCollection = ! \MongoDB\is_mapreduce_output_inline($this->out); $command = $this->createCommand($server); $options = $this->createOptions($hasOutputCollection); $cursor = $hasOutputCollection ? $server->executeReadWriteCommand($this->databaseName, $command, $options) : $server->executeReadCommand($this->databaseName, $command, $options); $result = current($cursor->toArray()); $getIterator = $this->createGetIteratorCallable($result, $server); return new MapReduceResult($getIterator, $result); } /** * 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 (isset($this->options['bypassDocumentValidation']) && \MongoDB\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) { if (isset($this->options['typeMap'])) { return new TypeMapArrayIterator($results, $this->options['typeMap']); } 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; } }