WIP internal refactoring to make shard cleaner, simpler and faster

I've put php mess detector across the code which has been very helpful.

Lots of good refactoring done so far. Almost no changes to external api. The changes that have been made are:

* There is now an unserializer service, split off from the serializer.
* Rather than the validator creating INVALID_CREATE and INVALID_UPDATE events, there is now a single INVALID_OBJECT event.

The serializer still needs quite a lot more work to tidy it up, but it's getting there.