芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/giga.mgaplay.com.br/vendor/mongodb/mongodb/src/Operation/Aggregate.php
$operation) { if ($i !== $expectedIndex) { throw new InvalidArgumentException(sprintf('$pipeline is not a list (unexpected index: "%s")', $i)); } if (! is_array($operation) && ! is_object($operation)) { throw InvalidArgumentException::invalidType(sprintf('$pipeline[%d]', $i), $operation, 'array or object'); } $expectedIndex += 1; } $options += [ 'allowDiskUse' => false, 'useCursor' => true, ]; if (! is_bool($options['allowDiskUse'])) { throw InvalidArgumentException::invalidType('"allowDiskUse" option', $options['allowDiskUse'], 'boolean'); } if (isset($options['batchSize']) && ! is_integer($options['batchSize'])) { throw InvalidArgumentException::invalidType('"batchSize" option', $options['batchSize'], 'integer'); } if (isset($options['bypassDocumentValidation']) && ! is_bool($options['bypassDocumentValidation'])) { throw InvalidArgumentException::invalidType('"bypassDocumentValidation" option', $options['bypassDocumentValidation'], 'boolean'); } if (isset($options['collation']) && ! is_array($options['collation']) && ! is_object($options['collation'])) { throw InvalidArgumentException::invalidType('"collation" option', $options['collation'], 'array or object'); } if (isset($options['comment']) && ! is_string($options['comment'])) { throw InvalidArgumentException::invalidType('"comment" option', $options['comment'], 'string'); } if (isset($options['explain']) && ! is_bool($options['explain'])) { throw InvalidArgumentException::invalidType('"explain" option', $options['explain'], 'boolean'); } if (isset($options['hint']) && ! is_string($options['hint']) && ! is_array($options['hint']) && ! is_object($options['hint'])) { throw InvalidArgumentException::invalidType('"hint" option', $options['hint'], 'string or array or object'); } if (isset($options['let']) && ! is_array($options['let']) && ! is_object($options['let'])) { throw InvalidArgumentException::invalidType('"let" option', $options['let'], ['array', 'object']); } if (isset($options['maxAwaitTimeMS']) && ! is_integer($options['maxAwaitTimeMS'])) { throw InvalidArgumentException::invalidType('"maxAwaitTimeMS" option', $options['maxAwaitTimeMS'], 'integer'); } if (isset($options['maxTimeMS']) && ! is_integer($options['maxTimeMS'])) { throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer'); } if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) { throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], ReadConcern::class); } if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) { throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], ReadPreference::class); } if (isset($options['session']) && ! $options['session'] instanceof Session) { throw InvalidArgumentException::invalidType('"session" option', $options['session'], Session::class); } if (isset($options['typeMap']) && ! is_array($options['typeMap'])) { throw InvalidArgumentException::invalidType('"typeMap" option', $options['typeMap'], 'array'); } if (! is_bool($options['useCursor'])) { throw InvalidArgumentException::invalidType('"useCursor" option', $options['useCursor'], 'boolean'); } if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) { throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], WriteConcern::class); } if (isset($options['batchSize']) && ! $options['useCursor']) { throw new InvalidArgumentException('"batchSize" option should not be used if "useCursor" is false'); } if (isset($options['readConcern']) && $options['readConcern']->isDefault()) { unset($options['readConcern']); } if (isset($options['writeConcern']) && $options['writeConcern']->isDefault()) { unset($options['writeConcern']); } $this->isExplain = ! empty($options['explain']); $this->isWrite = is_last_pipeline_operator_write($pipeline) && ! $this->isExplain; // Explain does not use a cursor if ($this->isExplain) { $options['useCursor'] = false; unset($options['batchSize']); } /* Ignore batchSize for writes, since no documents are returned and a * batchSize of zero could prevent the pipeline from executing. */ if ($this->isWrite) { unset($options['batchSize']); } $this->databaseName = (string) $databaseName; $this->collectionName = isset($collectionName) ? (string) $collectionName : null; $this->pipeline = $pipeline; $this->options = $options; } /** * Execute the operation. * * @see Executable::execute() * @param Server $server * @return Traversable * @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(); } } $command = new Command( $this->createCommandDocument($server), $this->createCommandOptions() ); $cursor = $this->executeCommand($server, $command); if ($this->options['useCursor'] || $this->isExplain) { if (isset($this->options['typeMap'])) { $cursor->setTypeMap($this->options['typeMap']); } return $cursor; } if (isset($this->options['typeMap'])) { $cursor->setTypeMap(create_field_path_type_map($this->options['typeMap'], 'result.$')); } $result = current($cursor->toArray()); if (! isset($result->result) || ! is_array($result->result)) { throw new UnexpectedValueException('aggregate command did not return a "result" array'); } return new ArrayIterator($result->result); } /** * Returns the command document for this operation. * * @see Explainable::getCommandDocument() * @param Server $server * @return array */ public function getCommandDocument(Server $server) { return $this->createCommandDocument($server); } private function createCommandDocument(Server $server): array { $cmd = [ 'aggregate' => $this->collectionName ?? 1, 'pipeline' => $this->pipeline, ]; $cmd['allowDiskUse'] = $this->options['allowDiskUse']; if ( ! empty($this->options['bypassDocumentValidation']) && server_supports_feature($server, self::$wireVersionForDocumentLevelValidation) ) { $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } foreach (['comment', 'explain', 'maxTimeMS'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } foreach (['collation', 'let'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = (object) $this->options[$option]; } } if (isset($this->options['hint'])) { $cmd['hint'] = is_array($this->options['hint']) ? (object) $this->options['hint'] : $this->options['hint']; } if ($this->options['useCursor']) { $cmd['cursor'] = isset($this->options["batchSize"]) ? ['batchSize' => $this->options["batchSize"]] : new stdClass(); } return $cmd; } private function createCommandOptions(): array { $cmdOptions = []; if (isset($this->options['maxAwaitTimeMS'])) { $cmdOptions['maxAwaitTimeMS'] = $this->options['maxAwaitTimeMS']; } return $cmdOptions; } /** * Execute the aggregate command using the appropriate Server method. * * @see http://php.net/manual/en/mongodb-driver-server.executecommand.php * @see http://php.net/manual/en/mongodb-driver-server.executereadcommand.php * @see http://php.net/manual/en/mongodb-driver-server.executereadwritecommand.php */ private function executeCommand(Server $server, Command $command): Cursor { $options = []; foreach (['readConcern', 'readPreference', 'session'] as $option) { if (isset($this->options[$option])) { $options[$option] = $this->options[$option]; } } if ($this->isWrite && isset($this->options['writeConcern'])) { $options['writeConcern'] = $this->options['writeConcern']; } if (! $this->isWrite) { return $server->executeReadCommand($this->databaseName, $command, $options); } /* Server::executeReadWriteCommand() does not support a "readPreference" * option, so fall back to executeCommand(). This means that libmongoc * will not apply any client-level options (e.g. writeConcern), but that * should not be an issue as PHPLIB handles inheritance on its own. */ if (isset($options['readPreference'])) { return $server->executeCommand($this->databaseName, $command, $options); } return $server->executeReadWriteCommand($this->databaseName, $command, $options); } }