Finite\StateMachine\StateMachine::initialize PHP Method

initialize() public method

public initialize ( )
    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));
    }

Usage Example

 protected function initialize()
 {
     $this->addStates();
     $this->addTransitions();
     $this->object->setObject($this->getStatefulObjectMock());
     $this->object->initialize();
 }
All Usage Examples Of Finite\StateMachine\StateMachine::initialize