芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/giga.mgaplay.com.br/vendor/mongodb/mongodb/src/ChangeStream.php
iterator = $iterator; $this->resumeCallable = $resumeCallable; } /** * @see http://php.net/iterator.current * @return mixed */ #[ReturnTypeWillChange] public function current() { return $this->iterator->current(); } /** * @return CursorId */ public function getCursorId() { return $this->iterator->getInnerIterator()->getId(); } /** * Returns the resume token for the iterator's current position. * * Null may be returned if no change documents have been iterated and the * server did not include a postBatchResumeToken in its aggregate or getMore * command response. * * @return array|object|null */ public function getResumeToken() { return $this->iterator->getResumeToken(); } /** * @see http://php.net/iterator.key * @return mixed */ #[ReturnTypeWillChange] public function key() { if ($this->valid()) { return $this->key; } return null; } /** * @see http://php.net/iterator.next * @return void * @throws ResumeTokenException */ #[ReturnTypeWillChange] public function next() { try { $this->iterator->next(); $this->onIteration($this->hasAdvanced); } catch (RuntimeException $e) { $this->resumeOrThrow($e); } } /** * @see http://php.net/iterator.rewind * @return void * @throws ResumeTokenException */ #[ReturnTypeWillChange] public function rewind() { try { $this->iterator->rewind(); /* Unlike next() and resume(), the decision to increment the key * does not depend on whether the change stream has advanced. This * ensures that multiple calls to rewind() do not alter state. */ $this->onIteration(false); } catch (RuntimeException $e) { $this->resumeOrThrow($e); } } /** * @see http://php.net/iterator.valid * @return boolean */ #[ReturnTypeWillChange] public function valid() { return $this->iterator->valid(); } /** * Determines if an exception is a resumable error. * * @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#resumable-error * @param RuntimeException $exception * @return boolean */ private function isResumableError(RuntimeException $exception) { if ($exception instanceof ConnectionException) { return true; } if (! $exception instanceof ServerException) { return false; } if ($exception->getCode() === self::$cursorNotFound) { return true; } if (server_supports_feature($this->iterator->getServer(), self::$wireVersionForResumableChangeStreamError)) { return $exception->hasErrorLabel('ResumableChangeStreamError'); } return in_array($exception->getCode(), self::$resumableErrorCodes); } /** * Perform housekeeping after an iteration event. * * @param boolean $incrementKey Increment $key if there is a current result * @throws ResumeTokenException */ private function onIteration($incrementKey) { /* If the cursorId is 0, the server has invalidated the cursor and we * will never perform another getMore nor need to resume since any * remaining results (up to and including the invalidate event) will * have been received in the last response. Therefore, we can unset the * resumeCallable. This will free any reference to Watch as well as the * only reference to any implicit session created therein. */ if ((string) $this->getCursorId() === '0') { $this->resumeCallable = null; } /* Return early if there is not a current result. Avoid any attempt to * increment the iterator's key. */ if (! $this->valid()) { return; } if ($incrementKey) { $this->key++; } $this->hasAdvanced = true; } /** * Recreates the ChangeStreamIterator after a resumable server error. * * @return void */ private function resume() { $this->iterator = call_user_func($this->resumeCallable, $this->getResumeToken(), $this->hasAdvanced); $this->iterator->rewind(); $this->onIteration($this->hasAdvanced); } /** * Either resumes after a resumable error or re-throws the exception. * * @param RuntimeException $exception * @throws RuntimeException */ private function resumeOrThrow(RuntimeException $exception) { if ($this->isResumableError($exception)) { $this->resume(); return; } throw $exception; } }