Finite state machine for php.