Firestore/src/Query.php
private function snapshotPosition(DocumentSnapshot $snapshot, array $orderBy)
    {
        $appendName = true;
        foreach ($orderBy as $order) {
            if ($order['field']['fieldPath'] === self::DOCUMENT_ID) {
                $appendName = false;
                break;
            }
        }

        if ($appendName) {
            // If there is inequality filter (anything other than equals),
            // append orderBy(the last inequality filter’s path, ascending).
            if (!$orderBy && $this->queryHas('where')) {
                $filters = $this->query['where']['compositeFilter']['filters'];
                $inequality = array_filter($filters, function ($filter) {
                    $type = array_keys($filter)[0];
                    return !in_array($filter[$type]['op'], [
                        self::OP_EQUAL,
                        self::OP_ARRAY_CONTAINS
                    ]);
                });

                if ($inequality) {
                    $filter = end($inequality);
                    $type = array_keys($filter)[0];
                    $orderBy[] = [
                        'field' => [
                            'fieldPath' => $filter[$type]['field']['fieldPath'],
                        ],
                        'direction' => self::DIR_ASCENDING
                    ];
                }
            }

            // If the query has existing orderBy constraints
            if ($orderBy) {
                // Append orderBy(__name__, direction of last orderBy clause)
                $lastOrderDirection = end($orderBy)['direction'];
                $orderBy[] = [
                    'field' => [
                        'fieldPath' => self::DOCUMENT_ID
                    ],
                    'direction' => $lastOrderDirection
                ];
            } else {
                // no existing orderBy constraints
                // Otherwise append orderBy(__name__, ‘asc’)
                $orderBy[] = [
                    'field' => [
                        'fieldPath' => self::DOCUMENT_ID
                    ],
                    'direction' => self::DIR_ASCENDING
                ];
            }
        }

        $fieldValues = $this->snapshotCursorValues($snapshot, $orderBy);

        return [
            $fieldValues,
            $orderBy
        ];
    }
private function snapshotPosition(DocumentSnapshot $snapshot, array $orderBy)
    {
        $appendName = true;
        foreach ($orderBy as $order) {
            if ($order['field']['fieldPath'] === self::DOCUMENT_ID) {
                $appendName = false;
                break;
            }
        }

        if ($appendName) {
            // If there is inequality filter (anything other than equals),
            // append orderBy(the last inequality filter’s path, ascending).
            if (!$orderBy && $this->queryHas('where')) {
                $filters = $this->query['where']['compositeFilter']['filters'];
                $inequality = array_filter($filters, function ($filter) {
                    $type = array_keys($filter)[0];
                    return !in_array($filter[$type]['op'], [
                        self::OP_EQUAL,
                        self::OP_ARRAY_CONTAINS
                    ]);
                });

                if ($inequality) {
                    $filter = end($inequality);
                    $type = array_keys($filter)[0];
                    $orderBy[] = [
                        'field' => [
                            'fieldPath' => $filter[$type]['field']['fieldPath'],
                        ],
                        'direction' => self::DIR_ASCENDING
                    ];
                }
            }

            // If the query has existing orderBy constraints
            if ($orderBy) {
                // Append orderBy(__name__, direction of last orderBy clause)
                $lastOrderDirection = end($orderBy)['direction'];
                $orderBy[] = [
                    'field' => [
                        'fieldPath' => self::DOCUMENT_ID
                    ],
                    'direction' => $lastOrderDirection
                ];
            } else {
                // no existing orderBy constraints
                // Otherwise append orderBy(__name__, ‘asc’)
                $orderBy[] = [
                    'field' => [
                        'fieldPath' => self::DOCUMENT_ID
                    ],
                    'direction' => self::DIR_ASCENDING
                ];
            }
        }

        $fieldValues = $this->snapshotCursorValues($snapshot, $orderBy);

        return [
            $fieldValues,
            $orderBy
        ];
    }
private function snapshotPosition ( DocumentSnapshot $ snapshot , array $ orderBy ) { $ appendName = true ; foreach ( $ orderBy as $ order ) { if ( $ order [ 'field' ] [ 'fieldPath' ] === self :: DOCUMENT_ID ) { $ appendName = false ; break ; } } if ( $ appendName ) { // If there is inequality filter (anything other than equals), // append orderBy(the last inequality filter’s path, ascending). if ( ! $ orderBy && $ this -> queryHas ( 'where' ) ) { $ filters = $ this -> query [ 'where' ] [ 'compositeFilter' ] [ 'filters' ] ; $ inequality = array_filter ( $ filters , function ( $ filter ) { $ type = array_keys ( $ filter ) [ 0 ] ; return ! in_array ( $ filter [ $ type ] [ 'op' ] , [ self :: OP_EQUAL , self :: OP_ARRAY_CONTAINS ] ) ; } ) ; if ( $ inequality ) { $ filter = end ( $ inequality ) ; $ type = array_keys ( $ filter ) [ 0 ] ; $ orderBy [ ] = [ 'field' => [ 'fieldPath' => $ filter [ $ type ] [ 'field' ] [ 'fieldPath' ] , ] , 'direction' => self :: DIR_ASCENDING ] ; } } // If the query has existing orderBy constraints if ( $ orderBy ) { // Append orderBy(__name__, direction of last orderBy clause) $ lastOrderDirection = end ( $ orderBy ) [ 'direction' ] ; $ orderBy [ ] = [ 'field' => [ 'fieldPath' => self :: DOCUMENT_ID ] , 'direction' => $ lastOrderDirection ] ; } else { // no existing orderBy constraints // Otherwise append orderBy(__name__, ‘asc’) $ orderBy [ ] = [ 'field' => [ 'fieldPath' => self :: DOCUMENT_ID ] , 'direction' => self :: DIR_ASCENDING ] ; } } $ fieldValues = $ this -> snapshotCursorValues ( $ snapshot , $ orderBy ) ; return [ $ fieldValues , $ orderBy ] ; }
Build cursors for document snapshots.

@param DocumentSnapshot $snapshot The document snapshot
@param array $orderBy A list of orderBy clauses.
@return array A list, where position 0 is fieldValues and position 1 is orderBy.
Build cursors for document snapshots .