This is a demo for the Yii2-StateMachine extension.

The panel on the left shows you the graph representing the state machine.

The panel on the right allows you to modify the state of the object. The available visible events change according to the current object attribute state and the role of the user (ie. your role). For the shake of simplicity on the demo, you will not need to login but you can rather just click the role (on the far right) and change your current role.

At the bottom of the page you can see the xml file that represents this state machine. The source code of this demo site can be found at github - yii2-statemachine-demo.

State Machine - account

G draft draft onEnter: ReportStateTransition SendVerificationEmail onExit: ReportStateTransition draft->draft resend.verification.email verified verified onEnter: ReportStateTransition onExit: ReportStateTransition draft->verified verify cancelled cancelled onEnter: ReportStateTransition onExit: ReportStateTransition draft->cancelled delete.account verified->cancelled delete.account cancelled->draft recover cleanup cleanup onEnter: ReportStateTransition cancelled->cleanup timeout
These are the possible events (triggers) for the state verified and role

    No events for guest in state verified. Try changing the role.

Transition Log

State Machine Graph Source Code

<?xml version="1.0"?>
<state-machine name="account" initialState="draft">
    <!-- Property was just created -->
    <state value="draft" label="Draft">
        <enter>
            <command class="ReportStateTransition"/>
            <command class="SendVerificationEmail"/>
        </enter>

        <event target="verified" label="verify">
            <role>owner</role>
        </event>
        <event target="draft" label="resend.verification.email">
            <role>owner</role>
        </event>
        <event target="cancelled" label="delete.account">
            <role>owner</role>
        </event>

        <exit>
            <command class="ReportStateTransition" verb="Leaving"/>
        </exit>
    </state>

    <state value="verified">
        <enter>
            <command class="ReportStateTransition"/>
        </enter>

        <event target="cancelled" label="delete.account">
            <role>owner</role>
        </event>

        <exit>
            <command class="ReportStateTransition" verb="Leaving"/>
        </exit>
    </state>

    <state value="cancelled">
        <enter>
            <command class="ReportStateTransition"/>
        </enter>

        <event target="draft" label="recover">
            <role>owner</role>
        </event>
        <timeout target="cleanup" label="timeout" days="1">
            <role>system</role>
        </timeout>

        <exit>
            <command class="ReportStateTransition" verb="Leaving"/>
        </exit>
    </state>

    <state value="cleanup" label="clean.up">
        <enter>
            <command class="ReportStateTransition"/>
        </enter>
    </state>
</state-machine>