Youshido\GraphQL\Relay\Connection\ArrayConnection::offsetToCursor PHP Method

offsetToCursor() public static method

public static offsetToCursor ( $offset ) : string
$offset int
return string
    public static function offsetToCursor($offset)
    {
        return base64_encode(self::PREFIX . $offset);
    }

Usage Example

Example #1
0
 public function testCursors()
 {
     $offset = 3;
     $data = ['a', 'b', 'c', 'd', 'e'];
     $cursor = ArrayConnection::offsetToCursor($offset);
     $this->assertEquals($offset, ArrayConnection::cursorToOffset($cursor));
     $this->assertEquals($cursor, ArrayConnection::cursorForObjectInConnection($data, 'd'));
     $this->assertNull(null, ArrayConnection::cursorToOffset(null));
     $this->assertEquals($offset, ArrayConnection::cursorToOffsetWithDefault($cursor, 2));
     $this->assertEquals(2, ArrayConnection::cursorToOffsetWithDefault(null, 2));
 }