Download the PHP package danilovl/doctrine-entity-dto-bundle without Composer
On this page you can find all versions of the php package danilovl/doctrine-entity-dto-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package doctrine-entity-dto-bundle
DoctrineEntityDtoBundle
About
The Symfony bundle provides a simple mechanism to convert Doctrine entities to DTO objects.
Requirements
- PHP 8.5 or higher
- Symfony 8.0 or higher
- Doctrine 3
1. Installation
Install danilovl/doctrine-entity-dto-bundle package by Composer:
Add the DoctrineEntityDtoBundle to your application's bundles if it does not add automatically:
2. Configuration
After installing the bundle, you can change configuration settings in the danilovl_doctrine_entity_dto.yaml.
Default configuration.
3. Usage
3.1 Entity DTO
The DoctrineEntityDtoBundle automatically creates doctrine hydration for every entity class names if isEnableEntityDTO is true.
You can add a control attribute isAsEntityDTO that only entities with this attribute will create DTO hydration.
You can choose your own array of entities.
Or you can combine your list with the attribute control.
You only need to use the alias name of the entity and add the entity class name to the getResult method.
Alias name selects all data in the table.
The result will be the same as Doctrine's result but without a connection to the unit of work.
If you want the name of the DTO class to be different from the entity class name, use the parameter isEnableEntityRuntimeNameDTO.
It creates the name based on the pattern %sRuntimeDTO.
Note that this feature utilizes the eval function.
3.2 Scalar DTO
If isAsScalarDTO is true, it automatically scans the src project directory for every file, trying to find a class with the attribute AsScalarDTO.
When you use the AsScalarDTO attribute, the results of namespaces are cached for prod environment.
You can declare your own list of namespaces for the DTO class in the configuration without using the attribute.
Alternatively, you can combine the attribute and list. The final result will be merged.
Example of ChequeDTO.
Before using scalar select, you need to set the class name to the static property $dtoClass.
After call getResult, ScalarHydration set to null static $dtoClass parameter.
It is a limitation of Doctrine hydration that when you use scalar select, the Doctrine ResultSetMapping is empty.
As a result, the select query returns an array of DTO objects.
4. Other
For example, when you use knplabs/knp-components to create a paginator and set a Doctrine query to pagination,
if you want to create DTO objects as a result, simply add the class using the setHydrationMode method.
If use Gedmo Translatable DoctrineExtensions additionally needed setHint.
License
The DoctrineEntityDtoBundle is open-sourced software licensed under the MIT license.
All versions of doctrine-entity-dto-bundle with dependencies
symfony/framework-bundle Version ^8.0
doctrine/doctrine-bundle Version ^3.0
doctrine/orm Version ^3.3
symfony/finder Version ^8.0
symfony/property-access Version ^8.0