src/DynamoDb/Pagination/DynamoDbPaginator.php
public function paginate(
        array $query,
        int $limit,
        string $order,
        CursorStrategyInterface $cursorStrategy,
        string $cursor = null,
        string $direction = null
    ): PaginationResult {
        Assertion::greaterOrEqualThan($limit, 1, 'Limit must be greater or equal than 1');
        Assertion::choice($order, [self::ORDER_ASC, self::ORDER_DESC], 'Order must be either ASC or DESC');

        // Setup ordering, true for ASC and false for DESC
        $query['ScanIndexForward'] = self::ORDER_ASC === $order;

        // If no cursor is present, then get the first page
        if (null === $cursor) {
            $result = $this->runQuery($query, $limit);

            return new PaginationResult(
                $this->unmarshalResources($result),
                null,
                $this->buildCursorFromLastItem($cursorStrategy, $result)
            );
        }

        // Otherwise, set exclusive start key from cursor
        $query['ExclusiveStartKey'] = $this->marshaler->marshalItem($cursorStrategy->buildKeyFromCursor($cursor));

        if (self::DIRECTION_PREVIOUS === $direction) {
            // Reverse query ordering when paginating to previous page
            $query['ScanIndexForward'] = ! $query['ScanIndexForward'];

            $result = $this->runQuery($query, $limit);

            return new PaginationResult(
                array_reverse($this->unmarshalResources($result)),
                $this->buildCursorFromLastItem($cursorStrategy, $result),
                $this->buildCursorFromFirstItem($cursorStrategy, $result)
            );
        }

        if (self::DIRECTION_NEXT === $direction) {
            $result = $this->runQuery($query, $limit);

            return new PaginationResult(
                $this->unmarshalResources($result),
                $this->buildCursorFromFirstItem($cursorStrategy, $result),
                $this->buildCursorFromLastItem($cursorStrategy, $result)
            );
        }

        throw new InvalidArgumentException('Invalid pagination direction, it must be either previous or next');
    }
public function paginate(
        array $query,
        int $limit,
        string $order,
        CursorStrategyInterface $cursorStrategy,
        string $cursor = null,
        string $direction = null
    ): PaginationResult {
        Assertion::greaterOrEqualThan($limit, 1, 'Limit must be greater or equal than 1');
        Assertion::choice($order, [self::ORDER_ASC, self::ORDER_DESC], 'Order must be either ASC or DESC');

        // Setup ordering, true for ASC and false for DESC
        $query['ScanIndexForward'] = self::ORDER_ASC === $order;

        // If no cursor is present, then get the first page
        if (null === $cursor) {
            $result = $this->runQuery($query, $limit);

            return new PaginationResult(
                $this->unmarshalResources($result),
                null,
                $this->buildCursorFromLastItem($cursorStrategy, $result)
            );
        }

        // Otherwise, set exclusive start key from cursor
        $query['ExclusiveStartKey'] = $this->marshaler->marshalItem($cursorStrategy->buildKeyFromCursor($cursor));

        if (self::DIRECTION_PREVIOUS === $direction) {
            // Reverse query ordering when paginating to previous page
            $query['ScanIndexForward'] = ! $query['ScanIndexForward'];

            $result = $this->runQuery($query, $limit);

            return new PaginationResult(
                array_reverse($this->unmarshalResources($result)),
                $this->buildCursorFromLastItem($cursorStrategy, $result),
                $this->buildCursorFromFirstItem($cursorStrategy, $result)
            );
        }

        if (self::DIRECTION_NEXT === $direction) {
            $result = $this->runQuery($query, $limit);

            return new PaginationResult(
                $this->unmarshalResources($result),
                $this->buildCursorFromFirstItem($cursorStrategy, $result),
                $this->buildCursorFromLastItem($cursorStrategy, $result)
            );
        }

        throw new InvalidArgumentException('Invalid pagination direction, it must be either previous or next');
    }
@param array                     $query
@param int                       $limit
@param string                    $order
@param CursorStrategyInterface   $cursorStrategy
@param string|null               $cursor
@param string|null               $direction

@return PaginationResult