Example #1
0
 /**
  * @param $name
  *
  * @return \MetaborStd\Statemachine\StateInterface
  *
  * @throws \Exception
  */
 public function findOrCreateState($name)
 {
     if (!$this->stateCollection->hasState($name)) {
         if ($this->stateCollection instanceof StateCollection) {
             $this->stateCollection->addState($this->createState($name));
         } else {
             throw new \InvalidArgumentException('Overwrite this method to implement a different type!');
         }
     }
     return $this->stateCollection->getState($name);
 }
 /**
  * @param StateInterface $state
  *
  * @throws \InvalidArgumentException
  */
 protected function addState(StateInterface $state)
 {
     if ($this->targetCollection instanceof StateCollection) {
         $this->targetCollection->addState($state);
     } else {
         throw new \InvalidArgumentException('TargetCollection has to be a StateCollection. Overwrite this method to implement a different type!');
     }
 }