1. Go to this page and download the library: Download michaelmoussa/noodle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
michaelmoussa / noodle example snippets
declare (strict_types = 1);
ition;
use Noodle\Transition\Table\DefaultTransitionTable;
use Noodle\State\FlyweightState;
use Noodle\Stateful\Stateful;
use Noodle\Stateful\StateMaintainer;
use Noodle\Statemachine\Statemachine;
use Noodle\Transition\Input\FlyweightInput;
/*
* Create a Transition table to describe the rules for state transitions. For convenience, the
* DefaultTransition creates transitions based on a pattern, in this
* case: <CURRENT_STATE> + <INPUT> = <NEXT_STATE>. If you'd like to use a different pattern,
* you can pass a regex to DefaultTransition::usePattern(...) to substitute your own. The only
* hine must implement the Stateful interface. For
* convenience, the StateMaintainer trait is available to satisfy the bare minimum
*
use League\Event\EventInterface;
use Noodle\Listener\InvokableListener;
use Noodle\State\State;
use Noodle\Stateful\Stateful;
use Noodle\Transition\Input\Input;
class LightChangingAnnouncement extends InvokableListener
{
public function __invoke(
EventInterface $event,
Stateful $object,
\ArrayObject $context,
Input $input,
State $nextState
) {
echo sprintf('Hey everyone, the light is about to turn %s!', $nextState->getName());
}
}
/*
* $statemachine is from the previous example. Note the FlyweightState::any() here. This is
* a "wildcard" state that, for the purposes of the statemachine event system, will match any
* current state. This is useful in cases where you don't care what the state is, and you
* know that you want to execute the event every time there's a state change.
*/
$statemachine->before(
FlyweightInput::named('CHANGE_COLOR'),
FlyweightState::any(),
new LightChangingAnnouncement()
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.