An elegant implementation of a state machine in PHP.