public function whenProvider() : \Generator { foreach (['before', 'on', 'after'] as $when) { $eventNames = []; if ($when !== 'on') { $eventNames = [sprintf('%s %s %s', $when, FlyweightInput::named('WHITE_MOVES')->getName(), FlyweightState::named('WHITES_TURN')->getName()), sprintf('%s %s %s', $when, FlyweightInput::any()->getName(), FlyweightState::named('WHITES_TURN')->getName()), sprintf('%s %s %s', $when, FlyweightInput::named('WHITE_MOVES')->getName(), FlyweightState::any()->getName())]; } $eventNames[] = sprintf('%s %s %s', $when, FlyweightInput::any()->getName(), FlyweightState::any()->getName()); (yield [$when, $eventNames]); } }
/** * Returns events to be emitted whenever a state transition is attempted * * @param Input $input * @param State $currentState * * @return Generator */ private function eventProvider(Input $input, State $currentState) : Generator { $anyInput = FlyweightInput::any(); $anyState = FlyweightState::any(); (yield Event::named($this->getEventName('before', $input, $currentState))); (yield Event::named($this->getEventName('before', $anyInput, $currentState))); (yield Event::named($this->getEventName('before', $input, $anyState))); (yield Event::named($this->getEventName('before', $anyInput, $anyState))); (yield Event::named($this->getEventName('on', $anyInput, $anyState))); (yield Event::named($this->getEventName('after', $input, $currentState))); (yield Event::named($this->getEventName('after', $anyInput, $currentState))); (yield Event::named($this->getEventName('after', $input, $anyState))); (yield Event::named($this->getEventName('after', $anyInput, $anyState))); }