芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/atvcmsTRASH.com.br/maisqtv2/vendor/mongodb/mongodb/src/ChangeStream.php
resumeCallable = $resumeCallable; $this->csIt = new IteratorIterator($cursor); } /** * @see http://php.net/iterator.current * @return mixed */ public function current() { return $this->csIt->current(); } /** * @return \MongoDB\Driver\CursorId */ public function getCursorId() { return $this->csIt->getInnerIterator()->getId(); } /** * @see http://php.net/iterator.key * @return mixed */ public function key() { if ($this->valid()) { return $this->key; } return null; } /** * @see http://php.net/iterator.next * @return void */ public function next() { try { $this->csIt->next(); $this->onIteration($this->hasAdvanced); } catch (RuntimeException $e) { if ($this->isResumableError($e)) { $this->resume(); } } } /** * @see http://php.net/iterator.rewind * @return void */ public function rewind() { try { $this->csIt->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) { if ($this->isResumableError($e)) { $this->resume(); } } } /** * @see http://php.net/iterator.valid * @return boolean */ public function valid() { return $this->csIt->valid(); } /** * Extracts the resume token (i.e. "_id" field) from the change document. * * @param array|object $document Change document * @return mixed * @throws InvalidArgumentException * @throws ResumeTokenException if the resume token is not found or invalid */ private function extractResumeToken($document) { if ( ! is_array($document) && ! is_object($document)) { throw InvalidArgumentException::invalidType('$document', $document, 'array or object'); } if ($document instanceof Serializable) { return $this->extractResumeToken($document->bsonSerialize()); } $resumeToken = is_array($document) ? (isset($document['_id']) ? $document['_id'] : null) : (isset($document->_id) ? $document->_id : null); if ( ! isset($resumeToken)) { throw ResumeTokenException::notFound(); } if ( ! is_array($resumeToken) && ! is_object($resumeToken)) { throw ResumeTokenException::invalidType($resumeToken); } return $resumeToken; } /** * 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 (in_array($exception->getCode(), [self::$errorCodeCappedPositionLost, self::$errorCodeCursorKilled, self::$errorCodeInterrupted])) { return false; } return true; } /** * 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 or extract a resume token */ if (!$this->valid()) { return; } if ($incrementKey) { $this->key++; } $this->hasAdvanced = true; $this->resumeToken = $this->extractResumeToken($this->csIt->current()); } /** * Creates a new changeStream after a resumable server error. * * @return void */ private function resume() { $newChangeStream = call_user_func($this->resumeCallable, $this->resumeToken); $this->csIt = $newChangeStream->csIt; $this->csIt->rewind(); /* Note: if we are resuming after a call to ChangeStream::rewind(), * $hasAdvanced will always be false. For it to be true, rewind() would * need to have thrown a RuntimeException with a resumable error, which * can only happen during the first call to IteratorIterator::rewind() * before onIteration() has a chance to set $hasAdvanced to true. * Otherwise, IteratorIterator::rewind() would either NOP (consecutive * rewinds) or throw a LogicException (rewind after next), neither of * which would result in a call to resume(). */ $this->onIteration($this->hasAdvanced); } }