Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

(no description)

File Size: 308 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ChangeStreamIterator:: (15 methods):
  __construct()
  commandFailed()
  commandStarted()
  commandSucceeded()
  current()
  getInnerIterator()
  getResumeToken()
  getServer()
  key()
  next()
  rewind()
  valid()
  extractResumeToken()
  isAtEndOfBatch()
  onIteration()


Class: ChangeStreamIterator  - X-Ref

ChangeStreamIterator wraps a change stream's tailable cursor.

This iterator tracks the size of each batch in order to determine when the
postBatchResumeToken is applicable. It also ensures that initial calls to
rewind() do not execute getMore commands.

__construct(Cursor $cursor, int $firstBatchSize, $initialResumeToken, ?object $postBatchResumeToken)   X-Ref

param: array|object|null $initialResumeToken

commandFailed(CommandFailedEvent $event)   X-Ref
No description

commandStarted(CommandStartedEvent $event)   X-Ref
No description

commandSucceeded(CommandSucceededEvent $event)   X-Ref
No description

current()   X-Ref

return: mixed

getInnerIterator()   X-Ref
Necessary to let psalm know that we're always expecting a cursor as inner
iterator. This could be side-stepped due to the class not being final,
but it's very much an invalid use-case. This method can be dropped in 2.0
once the class is final.


getResumeToken()   X-Ref
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

getServer()   X-Ref
Returns the server the cursor is running on.


key()   X-Ref

return: mixed

next()   X-Ref


rewind()   X-Ref


valid()   X-Ref


extractResumeToken($document)   X-Ref
Extracts the resume token (i.e. "_id" field) from a change document.

param: array|object $document Change document
return: array|object

isAtEndOfBatch()   X-Ref
Return whether the iterator is positioned at the end of the batch.


onIteration(bool $incrementBatchPosition)   X-Ref
Perform housekeeping after an iteration event.