public function form($form, $submissionToDtoMapping = null)
    {
        $stagedForm = null;

        if ($form instanceof FormBuilder) {
            $form = $form->build();
        } elseif ($form instanceof StagedFormBuilder) {
            $form = $form->build();
        }

        if ($form instanceof IForm) {
            $stagedForm = $form->asStagedForm();
        } elseif ($form instanceof IStagedForm) {
            $stagedForm = $form;
        } else {
            throw InvalidArgumentException::format(
                'Invalid form supplied to %s: expecting %s, %s given',
                __METHOD__, implode('|', [IForm::class, IStagedForm::class, FormBuilder::class, StagedFormBuilder::class]),
                Debug::getType($form)
            );
        }

        $this->formDtoMappingCallback = function ($handlerParameterType) use ($form, $stagedForm, $submissionToDtoMapping) {

            if ($form instanceof FormObject) {
                $mapping = new FormObjectMapping($form);
            } elseif ($form instanceof StagedFormObject) {
                $mapping = new StagedFormObjectMapping($form);
            } elseif ($submissionToDtoMapping instanceof IStagedFormDtoMapping) {
                $mapping = $submissionToDtoMapping;
            } elseif (is_callable($submissionToDtoMapping)) {
                $mapping = new CustomStagedFormDtoMapping($stagedForm, $handlerParameterType, $submissionToDtoMapping);
            } else {
                $mapping = new ArrayDataObjectFormMapping($stagedForm);
            }

            return $mapping;
        };


        return $this;
    }
public function form($form, $submissionToDtoMapping = null)
    {
        $stagedForm = null;

        if ($form instanceof FormBuilder) {
            $form = $form->build();
        } elseif ($form instanceof StagedFormBuilder) {
            $form = $form->build();
        }

        if ($form instanceof IForm) {
            $stagedForm = $form->asStagedForm();
        } elseif ($form instanceof IStagedForm) {
            $stagedForm = $form;
        } else {
            throw InvalidArgumentException::format(
                'Invalid form supplied to %s: expecting %s, %s given',
                __METHOD__, implode('|', [IForm::class, IStagedForm::class, FormBuilder::class, StagedFormBuilder::class]),
                Debug::getType($form)
            );
        }

        $this->formDtoMappingCallback = function ($handlerParameterType) use ($form, $stagedForm, $submissionToDtoMapping) {

            if ($form instanceof FormObject) {
                $mapping = new FormObjectMapping($form);
            } elseif ($form instanceof StagedFormObject) {
                $mapping = new StagedFormObjectMapping($form);
            } elseif ($submissionToDtoMapping instanceof IStagedFormDtoMapping) {
                $mapping = $submissionToDtoMapping;
            } elseif (is_callable($submissionToDtoMapping)) {
                $mapping = new CustomStagedFormDtoMapping($stagedForm, $handlerParameterType, $submissionToDtoMapping);
            } else {
                $mapping = new ArrayDataObjectFormMapping($stagedForm);
            }

            return $mapping;
        };


        return $this;
    }
public function form ( $ form , $ submissionToDtoMapping = null ) { $ stagedForm = null ; if ( $ form instanceof FormBuilder ) { $ form = $ form -> build ( ) ; } elseif ( $ form instanceof StagedFormBuilder ) { $ form = $ form -> build ( ) ; } if ( $ form instanceof IForm ) { $ stagedForm = $ form -> asStagedForm ( ) ; } elseif ( $ form instanceof IStagedForm ) { $ stagedForm = $ form ; } else { throw InvalidArgumentException :: format ( 'Invalid form supplied to %s: expecting %s, %s given' , __METHOD__ , implode ( '|' , [ IForm :: class , IStagedForm :: class , FormBuilder :: class , StagedFormBuilder :: class ] ) , Debug :: getType ( $ form ) ) ; } $ this -> formDtoMappingCallback = function ( $ handlerParameterType ) use ( $ form , $ stagedForm , $ submissionToDtoMapping ) { if ( $ form instanceof FormObject ) { $ mapping = new FormObjectMapping ( $ form ) ; } elseif ( $ form instanceof StagedFormObject ) { $ mapping = new StagedFormObjectMapping ( $ form ) ; } elseif ( $ submissionToDtoMapping instanceof IStagedFormDtoMapping ) { $ mapping = $ submissionToDtoMapping ; } elseif ( is_callable ( $ submissionToDtoMapping ) ) { $ mapping = new CustomStagedFormDtoMapping ( $ stagedForm , $ handlerParameterType , $ submissionToDtoMapping ) ; } else { $ mapping = new ArrayDataObjectFormMapping ( $ stagedForm ) ; } return $ mapping ; } ; return $ this ; }
Sets the required form to be submitted for the action.

If the supplied forms are an instance of {@see FormObject} or {@see StagedFormObject}
the form submission will be bound to an instance of the form object.

Example:
<code>
->form(new SomeFormObject())
->handler(function (SomeFormObject $input) {
// ...
})
</code>

If however the supplied form is just a plain {@see IForm} or {@see IStagedForm},
you can supply your own custom form submission mapping as the second parameter.

Example:
<code>
->form(
Form::create()->section('Section', [
// Fields...
]),
function (array $input) {
return new SomeDto($input['data']);
}
)->handler(function (SomeDto $input) {
// ...
})
</code>

If no mapping is supplied, the form submission will automatically mapped to an
instance of {@see ArrayDataObject} containing the supplied form data. This can
be used just as a normal array.

Example:
<code>
->form(Form::create()->section('Section', [
// Fields...
]))->handler(function (ArrayDataObject $input) {
// ...
})
</code>

@param IForm|IStagedForm|FormObject|StagedFormObject|FormBuilder|StagedFormBuilder $form
@param IStagedFormDtoMapping|callable|null                                         $submissionToDtoMapping

@return static
@throws InvalidArgumentException
Sets the required form to be submitted for the action .