izzum\statemachine\Context::toString PHP Method

toString() public method

get the toString representation
public toString ( ) : string
return string
    public function toString()
    {
        return get_class($this) . "(" . $this->getId(true) . ")";
    }

Usage Example

Example #1
0
 /**
  * returns the associated Command for the entry/exit/transition action on a
  * State or a Transition.
  * the Command will be configured with the 'reference' of the stateful
  * object
  *
  * @param string $command_name
  *            entry~,exit~ or transition command name.
  *            multiple commands can be split by a ',' in which case a
  *            composite command will be returned.
  * @param Context $context
  *            to be able to get the entity
  * @return ICommand
  * @throws Exception
  */
 public static function getCommand($command_name, Context $context)
 {
     // it's oke to have no command, as there might be 'marker' states, where
     // we just need to transition something to a next state (according to a
     // rule)
     // where useful work can be done (eg: from the 'initial' type state to
     // a 'shortcut' state for special cases.
     if ($command_name === '' || $command_name === null) {
         // return a command without side effects
         return new Null();
     }
     $output = new Composite();
     // a command string can be made up of multiple commands seperated by a
     // comma
     $all_commands = explode(',', $command_name);
     // get the correct object to inject in the command(s)
     $entity = $context->getEntity();
     foreach ($all_commands as $single_command) {
         if (!class_exists($single_command)) {
             $e = new Exception(sprintf("failed command creation, class does not exist: (%s) for Context (%s)", $single_command, $context->toString()), Exception::COMMAND_CREATION_FAILURE);
             throw $e;
         }
         try {
             $command = new $single_command($entity);
             $output->add($command);
         } catch (\Exception $e) {
             $e = new Exception(sprintf("command (%s) objects to construction for Context (%s). message: '%s'", $single_command, $context->toString(), $e->getMessage()), Exception::COMMAND_CREATION_FAILURE);
             throw $e;
         }
     }
     return $output;
 }
All Usage Examples Of izzum\statemachine\Context::toString