Wrap all the PHP craziness in nice(ish) OO libraries