Beispiel #1
0
 /**
  * @param SimpleXMLElement $xml
  * @param StateMachine $sm
  * @param StateMachineState $state
  * @return static
  */
 public static function fromXml(SimpleXMLElement $xml, StateMachine $sm, StateMachineState $state)
 {
     /** @var Timeout $rVal */
     $rVal = parent::fromXml($xml, $sm, $state);
     $dt = new \DateTime();
     $days = (int) @$xml->attributes()->days;
     $hours = (int) @$xml->attributes()->hours;
     $minutes = (int) @$xml->attributes()->minutes;
     $seconds = 0;
     //@$state->attributes()->seconds;
     $interval = sprintf('P0000-00-%02dT%02d:%02d:%02d', $days, $hours, $minutes, $seconds);
     $dt->add(new \DateInterval($interval));
     $rVal->expiresAt = $dt->getTimestamp();
     return $rVal;
 }
Beispiel #2
0
 /**
  * @param SimpleXMLElement $xml
  * @param StateMachine $sm
  * @return static
  */
 public static function fromXml(SimpleXMLElement $xml, StateMachine $sm)
 {
     $rVal = new static();
     // Attach the statemachine
     $rVal->sm = $sm;
     // Value and Label
     $rVal->value = (string) $xml->attributes()->value;
     $rVal->label = (string) $xml->attributes()->label;
     // Load events
     foreach ($xml->event as $eventXml) {
         $rVal->events[] = Event::fromXml($eventXml, $sm, $rVal);
     }
     // Load timeouts
     foreach ($xml->timeout as $timeoutXml) {
         $rVal->timeouts[] = Timeout::fromXml($timeoutXml, $sm, $rVal);
     }
     // Enter Commands XML fragments
     $enterXml = !empty($xml->enter) ? $xml->enter[0]->command : [];
     foreach ($enterXml as $item) {
         $rVal->enter[] = $item;
     }
     // Exit Commands XML fragments
     $exitXml = !empty($xml->exit) ? $xml->exit[0]->command : [];
     foreach ($exitXml as $item) {
         $rVal->exit[] = $item;
     }
     $rVal->isInitial = $sm->getInitialStateValue() === $rVal->value;
     $rVal->isFinal = empty($rVal->events);
     return $rVal;
 }