public static function generator(int $numberOfStages, callable $formStagesGeneratorFunction) : ActualStagedForm
    {
        $generator = $formStagesGeneratorFunction();

        if (!($generator instanceof \Generator)) {
            throw InvalidArgumentException::format(
                    'Invalid call to %s: first argument must be a generator function, function returned %s instead',
                    Debug::getType($generator)
            );
        }

        $builder                 = self::begin($generator->current());
        $numberOfDependentStages = $numberOfStages - 1;

        for ($i = 1; $i <= $numberOfDependentStages; $i++) {
            // TODO: Don't recreate generator for every form stage. (low-pri)
            $builder->then(function (array $data) use ($formStagesGeneratorFunction, $i) {
                /** @var \Generator $generator */
                $generator = $formStagesGeneratorFunction();
                for ($current = 1; $current <= $i; $current++) {
                    $generator->send($data);
                }

                return $generator->current();
            });
        }

        return $builder->build();
    }
public static function generator(int $numberOfStages, callable $formStagesGeneratorFunction) : ActualStagedForm
    {
        $generator = $formStagesGeneratorFunction();

        if (!($generator instanceof \Generator)) {
            throw InvalidArgumentException::format(
                    'Invalid call to %s: first argument must be a generator function, function returned %s instead',
                    Debug::getType($generator)
            );
        }

        $builder                 = self::begin($generator->current());
        $numberOfDependentStages = $numberOfStages - 1;

        for ($i = 1; $i <= $numberOfDependentStages; $i++) {
            // TODO: Don't recreate generator for every form stage. (low-pri)
            $builder->then(function (array $data) use ($formStagesGeneratorFunction, $i) {
                /** @var \Generator $generator */
                $generator = $formStagesGeneratorFunction();
                for ($current = 1; $current <= $i; $current++) {
                    $generator->send($data);
                }

                return $generator->current();
            });
        }

        return $builder->build();
    }
public static function generator ( int $ numberOfStages , callable $ formStagesGeneratorFunction ) : ActualStagedForm { $ generator = $ formStagesGeneratorFunction ( ) ; if ( ! ( $ generator instanceof \ Generator ) ) { throw InvalidArgumentException :: format ( 'Invalid call to %s: first argument must be a generator function, function returned %s instead' , Debug :: getType ( $ generator ) ) ; } $ builder = self :: begin ( $ generator -> current ( ) ) ; $ numberOfDependentStages = $ numberOfStages - 1 ; for ( $ i = 1 ; $ i <= $ numberOfDependentStages ; $ i ++ ) { // TODO: Don't recreate generator for every form stage. (low-pri) $ builder -> then ( function ( array $ data ) use ( $ formStagesGeneratorFunction , $ i ) { /** @var \Generator $generator */ $ generator = $ formStagesGeneratorFunction ( ) ; for ( $ current = 1 ; $ current <= $ i ; $ current ++ ) { $ generator -> send ( $ data ) ; } return $ generator -> current ( ) ; } ) ; } return $ builder -> build ( ) ; }
Constructs a staged from from a generator function.
This function must yield the form for each stage and
the previously submitted data will be sent.

Example:
<code>
$stagedFrom = StagedFrom::create(2, function () {
$data = (yield Form::create()
->section('First Stage', [...]));

$data = (yield Form::create()
->section('Second Stage', [...]));
});
</code>

@param int      $numberOfStages
@param callable $formStagesGeneratorFunction

@return ActualStagedForm
@throws InvalidArgumentException
Constructs a staged from from a generator function . This function must yield the form for each stage and the previously submitted data will be sent .