public function initialize()
{
if (null === $this->object) {
throw new Exception\ObjectException('No object bound to the State Machine');
}
try {
$initialState = $this->stateAccessor->getState($this->object);
} catch (Exception\NoSuchPropertyException $e) {
throw new Exception\ObjectException(sprintf('StateMachine can\'t be initialized because the defined property_path of object "%s" does not exist.', get_class($this->object)), $e->getCode(), $e);
}
if (null === $initialState) {
$initialState = $this->findInitialState();
$this->stateAccessor->setState($this->object, $initialState);
$this->dispatcher->dispatch(FiniteEvents::SET_INITIAL_STATE, new StateMachineEvent($this));
}
$this->currentState = $this->getState($initialState);
$this->dispatcher->dispatch(FiniteEvents::INITIALIZE, new StateMachineEvent($this));
}