Download the PHP package somnambulist/form-request-bundle without Composer

On this page you can find all versions of the php package somnambulist/form-request-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 form-request-bundle

Somnambulist Form Request Bundle

GitHub Actions Build Status Issues License PHP Version Current Version

An implementation of form requests from Laravel for Symfony based on the original work by Adam Sapraliev.

Requirements

Installation

Install using composer, or checkout / pull the files from github.com.

Usage

Add the SomnambulistFormRequestBundle to your bundles.php list and add a config file in packages if you wish to configure the bundle. The following options can be set:

authorization registers an event subscriber that will convert AccessDeniedExceptions to a JSON response. form_validation registers an event subscriber that will convert FormValidationException to a JSON response including the fields that failed validation and the rules and message that failed.

Note: the subscribers are enabled by default.

Custom Rules

This package includes overrides for the following rules:

Property Pass-Through

The following ParameterBags can be accessed via property accessors or method calls:

In addition, the following properties are also available:

Making a Form Request

To make a form request, extend the base Somnambulist\Bundles\FormRequestBundle\Http\FormRequest class and override the rules() method to add your own validation rules. The rules method has access to the current request via the source property so rules can be constructed using request information.

The validation rules use somnambulist/validation instead of Symfony's validation component to allow for easier setup and extension.

For example: to make a form request specifically for validating the data to make a new user you could create the following:

Validated data is stored in the data property and is accessible directly from the controller. From version 1.5.0 this is a ValidatedDataBag, previously it was a ParameterBag. The data bag supports dot notation access to keys (with the same restrictions as the main FormRequest) along with nullOrValue and several other methods for keys, values, and filtering by callback.

Alternatively: the original request data can be accessed via property pass-through or by calling source() to get the request object.

Using the Form Request

In your controller, instead of type-hinting the standard request, type-hint your form request. If validation succeeds, then the data in the request will be suitable for the controller to use.

For example:

FormRequests support dot notation access to get to nested values. This can be used for single values, to check for deeply nested values easily or to extract a set of values into a value object or set.

For example: to get a single value: $form->get('user.address.line_1') would get line_1 from a user array that contains an address array.

The behaviour of dot notation has several edge cases:

Additionally:

When using dot notation with only the result will be similar to nullOrValue with subNull as false however it may contain values from the request, query, or files. nullOrValue will only work with a single data source. If you require fine control use nullOrValue.

When using dot notation with without the result will contain data from request, query, and files. As a ParameterBag is returned, there are no dot accessors.

Optionally:

If you make use of api-bundle and document query arguments that should not be treated as part of the validated data (e.g. page/per_page etc); these can be excluded from the validated data by overriding the $ignore property with the set of key names that should be excluded from the validated data.

Authorizing a Form Request

Form requests can have custom authorization checks; however this feature requires that Symfony Security has been implemented as the security service is required.

To add custom auth checks override the authorize() method and add the necessary checks.

The authorize method receives the current Security service that has access to the current user and the isGranted() method.

For example, to require new users can only be made by an Admin user:

Adding Validator Rules

Custom validators can be added by creating a new Rule that extends Somnambulist\Components\Validation\Rule, implementing the logic for validation (and any custom messages) and then creating a new service. Rules will be automatically assigned to the validator using the class name without namespace converted to snake_case. Alternatively individual rules can be tagged with somnambulist.form_request_bundle.rule and the attribute rule_name to set a specific alias for the rule:

For example:

Without the tag, this rule would be registered as: uuid_rule.

As rules are registered as services you can use other services for database or API checks etc.

See the documentation for more details on how to pass arguments, the available rules, and how to handle translation of messages.

Note: all rules must have unique names and same names will overwrite any pre-existing rules.

Note: several rules are needed internally; if you experience odd behaviour it could be because you changed the behaviour of a built-in rule.

Adding missing mime-types

somnambulist/validation includes a mime-type guesser that is registered by default and is available as a service. You can add additional mime-types and extensions to this by injecting the service and configuring it, either in a boot method or in a service.

Alternatively: the implementation can be replaced entirely provided it implements the MimeTypeGuesser interface.

Tests

PHPUnit 9+ is used for testing. Run tests via vendor/bin/phpunit.


All versions of form-request-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
somnambulist/validation Version ^1.4
symfony/framework-bundle Version ^6.4|^7.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 somnambulist/form-request-bundle contains the following files

Loading the files please wait ....