Download the PHP package azyouness/request-to-form-bundle without Composer

On this page you can find all versions of the php package azyouness/request-to-form-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package request-to-form-bundle

Request To Form Bundle

Request To Form Bundle submits the current Symfony request to a Symfony Form directly from a controller argument.

Symfony already provides attributes such as #[MapRequestPayload] to map request data into typed objects like DTOs. This bundle provides a similar controller experience for applications that use Symfony Forms to submit and validate request data.

With #[MapRequestToForm], the request payload is submitted to a form. If the form is valid, the controller receives the mapped form data or the submitted form itself. If the form is invalid, an exception is thrown before the controller is called.

Here, $post is already the submitted and validated form data. The controller does not need to decode the request, create the form, submit it, check validity, or extract the data manually.

Requirements

Installation

Register the bundle manually if Symfony Flex did not do it automatically:

Basic Usage

Add #[MapRequestToForm] to a controller argument.

The form type can be inferred when exactly one registered form type uses the controller argument class as its data_class.

If the form type cannot be inferred or multiple form types use the same data_class, pass it explicitly:

Automatic inference works when the form type exposes a data_class that can be inspected. If your form type needs runtime options, pass formType explicitly and provide formOptions, or use the RequestToFormMapper service.

If the form can return null data, the controller argument should be nullable:

Existing Data

When another Symfony resolver has already resolved the controller argument, the bundle submits the request into that object.

This is useful when submitting the request into existing data:

MapRequestToForm can also be combined with other argument attributes, such as Doctrine's MapEntity:

For nested create endpoints, disable entity resolution on the new entity argument:

Without #[MapEntity(disabled: true)], Symfony may also try to resolve Comment $comment from the same {id} route parameter before the form is submitted.

For PATCH and GET query requests, missing fields are kept by default. For other methods, missing fields are cleared by default. You can override this behavior with clearMissing.

Receiving The Form

If the controller argument type is FormInterface, the controller receives the submitted form.

This is useful when the controller needs access to the form object, not only its data.

You can also use another controller argument as the form data:

Root Scalar Forms

Root scalar form types are supported when the controller argument type matches the submitted form data.

Supported Request Formats

By default, json, form, and query request formats are accepted:

The supported formats are:

You can also limit an action to one format:

Example using the query format:

Options

The same options are available on the mapper service where they make sense.

Option Available On Description
formType attribute, mapper Symfony form type class. Required when it cannot be inferred.
dataArgument attribute Name of another controller argument to use as the form data.
data mapper Initial form data. Use it to submit into an existing object.
formOptions attribute, mapper Options passed to FormFactoryInterface::create().
clearMissing attribute, mapper Value passed to FormInterface::submit(). Defaults to false for PATCH and GET query requests, true otherwise.
acceptFormat attribute, mapper Accepted request formats: json, form, query, or a list of them.
throwOnInvalid mapper Set to false to receive an invalid form instead of throwing.
validationFailedStatusCode attribute, mapper HTTP status code used when validation fails. Default is 422.

Mapper Service

Use RequestToFormMapper directly when you need more control than the attribute gives you.

A common use case is preparing the form data before submitting the current request:

You can also pass the request explicitly:

The mapper throws when the form is invalid by default, like the attribute.

Disable this behavior when you want to handle the invalid form yourself:

Validation Failures

When validation fails, the bundle throws an HTTP exception with status code 422 by default.

The previous exception is FormValidationFailedException, which gives access to the invalid form.


All versions of request-to-form-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
symfony/dependency-injection Version ^7.4 || ^8.0
symfony/event-dispatcher Version ^7.4 || ^8.0
symfony/form Version ^7.4 || ^8.0
symfony/framework-bundle Version ^7.4 || ^8.0
symfony/http-foundation Version ^7.4 || ^8.0
symfony/http-kernel Version ^7.4 || ^8.0
symfony/options-resolver Version ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package azyouness/request-to-form-bundle contains the following files

Loading the files please wait ...