WIP: PHP-875 aggregation cursor take 2

So far, this is basically all the things from the other branch without the cursor aggregation stuff in there.