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

cursorToOffset() public static method

public static cursorToOffset ( $cursor ) : integer | null
$cursor string
return integer | null
    public static function cursorToOffset($cursor)
    {
        if ($decoded = base64_decode($cursor)) {
            return (int) substr($decoded, strlen(self::PREFIX));
        }
        return null;
    }

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));
 }