izzum\statemachine\Context::add PHP Method

add() public method

Used to mark the initial construction of a statemachine at a certain point in time. subsequent calls to 'add' will not have any effect if it has already been persisted.
public add ( string $state, string $message = null ) : boolean
$state string
$message string optional message. this can be used by the persistence adapter to be part of the transition history to provide extra information about the transition.
return boolean true if it was added, false if it was already there
    public function add($state, $message = null)
    {
        return $this->getPersistenceAdapter()->add($this->getIdentifier(), $state, $message);
    }

Usage Example

 /**
  * @test
  */
 public function shouldLoadAndWriteViaDelegator()
 {
     $loader = XML::createFromFile(__DIR__ . '/../loader/fixture-example.xml');
     $writer = new Memory();
     $identifier = new Identifier('readerwriter-test', 'test-machine');
     $delegator = new ReaderWriterDelegator($loader, $writer);
     $context = new Context($identifier, null, $delegator);
     $machine = new StateMachine($context);
     $this->assertCount(0, $machine->getTransitions());
     $count = $delegator->load($machine);
     //add to the backend
     $this->assertTrue($context->add('a'));
     $this->assertCount(4, $machine->getTransitions(), 'there is a regex transition that adds 2 transitions (a-c and b-c)');
     $this->assertEquals(4, $count);
     $this->assertTrue($machine->ab());
     //get the data from the memory storage facility
     $data = $writer->getStorageFromRegistry($machine->getContext()->getIdentifier());
     $this->assertEquals('b', $data->state);
     $this->assertEquals('b', $machine->getCurrentState()->getName());
     $this->assertTrue($machine->bdone());
     $data = $writer->getStorageFromRegistry($machine->getContext()->getIdentifier());
     $this->assertEquals('done', $data->state);
 }
All Usage Examples Of izzum\statemachine\Context::add