izzum\statemachine\utils\Utils::checkConfiguration PHP Метод

checkConfiguration() публичный статический Метод

This is useful in a debug situation so you can check for the validity of rules, commands and callables in guard logic, transition logic and state entry/exit logic before they hit a This does not instantiate any objects. It just checks if callables can be found and if classes for rules and commands can be found
public static checkConfiguration ( StateMachine $machine ) : Exception[]
$machine izzum\statemachine\StateMachine
Результат izzum\statemachine\Exception[] an array of exceptions if anything is wrong with the configuration
    public static function checkConfiguration(StateMachine $machine)
    {
        //TODO: also check the rules and commands
        $exceptions = array();
        $output = array();
        //check state callables
        foreach ($machine->getStates() as $state) {
            $exceptions[] = self::getExceptionForCheckingCallable($state->getExitCallable(), State::CALLABLE_ENTRY, $state);
            $exceptions[] = self::getExceptionForCheckingCallable($state->getEntryCallable(), State::CALLABLE_ENTRY, $state);
        }
        //check transition callables
        foreach ($machine->getTransitions() as $transition) {
            $exceptions[] = self::getExceptionForCheckingCallable($transition->getGuardCallable(), Transition::CALLABLE_GUARD, $transition);
            $exceptions[] = self::getExceptionForCheckingCallable($transition->getTransitionCallable(), Transition::CALLABLE_TRANSITION, $transition);
        }
        //get the exceptions
        foreach ($exceptions as $e) {
            if (is_a($e, '\\Exception')) {
                $output[] = $e;
            }
        }
        return $output;
    }

Usage Example

 /**
  * https://github.com/rolfvreijdenberger/izzum-statemachine/issues/7
  * @test
  */
 public function shouldFailConfigurationCheckForMachineWithBadCallables()
 {
     $transitions = array();
     $s1 = new State("1");
     $s1->setEntryCallable('foobar');
     $s2 = new State("2");
     $s2->setEntryCallable('foobar');
     $s3 = new State("3");
     $s3->setEntryCallable('foobar');
     $transitions[] = new Transition($s1, $s2);
     $transitions[] = new Transition($s2, $s3);
     //3 states, 3 bad callables
     //2 transitions, 4 bad callables
     //total of 7
     foreach ($transitions as $transition) {
         $transition->setGuardCallable('foobar');
         $transition->setTransitionCallable('foobar');
     }
     $loader = new LoaderArray($transitions);
     $context = new Context(new Identifier(Identifier::NULL_ENTITY_ID, Identifier::NULL_STATEMACHINE));
     $machine = new StateMachine($context);
     $loader->load($machine);
     $exceptions = Utils::checkConfiguration($machine);
     $this->assertEquals(7, count($exceptions));
     $this->assertTrue(true, 'basic machine with bad callables will be configured incorrectly');
 }