### Composer Installation for winzou/state-machine Source: https://github.com/winzou/state-machine/blob/master/README.md Specifies the dependency requirement for the winzou/state-machine library in a composer.json file. This ensures the library is correctly installed via Composer. ```js { "require": { "winzou/state-machine": "~0.1" } } ``` -------------------------------- ### PHP State Machine Configuration with States, Transitions, and Callbacks Source: https://github.com/winzou/state-machine/blob/master/README.md Defines a state machine graph configuration in PHP, including states, transitions, and various types of callbacks (guard, before, after). This configuration is attached to a domain object to manage its state. ```php $config = array( 'graph' => 'myGraphA', // Name of the current graph - there can be many of them attached to the same object 'property_path' => 'stateA', // Property path of the object actually holding the state 'states' => array( 'checkout', 'pending', 'confirmed', 'cancelled' ), 'transitions' => array( 'create' => array( 'from' => array('checkout'), 'to' => 'pending' ), 'confirm' => array( 'from' => array('checkout', 'pending'), 'to' => 'confirmed' ), 'cancel' => array( 'from' => array('confirmed'), 'to' => 'cancelled' ) ), 'callbacks' => array( 'guard' => array( 'guard-cancel' => array( 'to' => array('cancelled'), // Will be called only for transitions going to this state 'do' => function() { var_dump('guarding to cancelled state'); return false; } ) ), 'before' => array( 'from-checkout' => array( 'from' => array('checkout'), // Will be called only for transitions coming from this state 'do' => function() { var_dump('from checkout transition'); } ) ), 'after' => array( 'on-confirm' => array( 'on' => array('confirm'), // Will be called only on this transition 'do' => function() { var_dump('on confirm transition'); } ), 'to-cancelled' => array( 'to' => array('cancelled'), // Will be called only for transitions going to this state 'do' => function() { var_dump('to cancel transition'); } ), 'cancel-date' => array( 'to' => array('cancelled'), 'do' => array('object', 'setCancelled'), ) ) ) ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.