Download the PHP package artyuum/request-dto-mapper-bundle without Composer

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

Request DTO Mapper Bundle

image

This bundle provides an easy way to automatically map the incoming request data to a DTO and optionally validate it. It's using the powerful Serializer component under the hood along with the Validator component (optional).

Requirements

Installation

Configuration

Usage

This is a simple step-by-step example of how to make a DTO that will be used by the bundle.

  1. Create the DTO that represents the structure of the content the user will send to your controller.

  2. Inject the DTO into your controller & configure it using the Dto attribute.

Alternatively, you can set the attribute directly on the argument:

If you have set some default options in the configuration file (the default extractor to use, whether to enable the validation), you can even make it shorter:

  1. That's it!

Attribute

The Dto attribute has the following seven properties:

1. Extractor

The FQCN (Fully-Qualified Class Name) of a class that implements the ExtractorInterface. It basically contains the extraction logic and it's called by the mapper in order to extract the data from the request.

The bundle already comes with 3 built-in extractors that should meet most of your use-cases:

If an error occurs when the extract() method is called from the extractor class, the ExtractionFailedException will be thrown.

If these built-in extractor classes don't meet your needs, you can implement your own extractor like this:

Then pass it to the Dto attribute like this:

If you don't set any value, the default value (defined in the bundle's configuration file) will be used.

Note: All classes implementing ExtractorInterface are automatically tagged as "artyum_request_dto_mapper.extractor", and this is needed by the mapper in order to retrieve the needed extractor class instance from the container.

2. Subject

The FQCN (Fully-Qualified Class Name) of the DTO you want to map (it must be present as your controller argument).

The "subject" property is required only if you're setting the attribute directly on the method. Example:

If you're setting the attribute on the method argument instead, the "subject" value can be omitted and won't be read by the mapper. Example:

3. Methods

It can contain a single or an array of HTTP methods that will "enable" the mapping/validation depending on the current HTTP method. In the following example, the DTO will be mapped & validated only if the request method is "GET".

or

If the array is empty (this is the default value), the mapper will always map the DTO and validate it.

4. Denormalization Options

The options that will be passed to the Denormalizer before mapping the DTO.

Example:

If an error occurs when the denormalize() method is called from the Denormalizer, the DtoMappingFailedException will be thrown.

5. Validate

Whether to validate the DTO (once the mapping is done). Internally, the validator component will be used, and if you do not have it installed a LogicException will be thrown.

Example:

If the validation failed (due to the constraint violations), the constraint violations will be available as request attribute:

If you don't set any value, the configured value (defined in the bundle's configuration file) will be used.

6. Validation Groups

The validation groups to pass to the validator.

Example:

If you don't set any value, the configured value (defined in the bundle's configuration file) will be used.

7. Throw on violation

When the validation failed, the DtoValidationFailedException will be thrown, and you will be able to get a list of these violations by calling the getViolations() method.

Setting the value to false will prevent the exception from being thrown, and your controller will still be executed.

Example:

If you don't set any value, the configured value (defined in the bundle's configuration file) will be used.

Events


All versions of request-dto-mapper-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
phpdocumentor/reflection-docblock Version ^5.3
symfony/config Version ^5.0 || ^6.0
symfony/event-dispatcher Version ^5.0 || ^6.0
symfony/framework-bundle Version ^5.0 || ^6.0
symfony/http-kernel Version ^5.0 || ^6.0
symfony/property-access Version ^5.0 || ^6.0
symfony/property-info Version ^5.0 || ^6.0
symfony/serializer Version ^5.0 || ^6.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 artyuum/request-dto-mapper-bundle contains the following files

Loading the files please wait ....