PHPackages                             metglobal/dto-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. metglobal/dto-bundle

AbandonedArchivedSymfony-bundle

metglobal/dto-bundle
====================

Data transfer object library for symfony applications

v0.4.0(5y ago)11.6k3MITPHPPHP &gt;=7.0

Since Apr 24Pushed 5y agoCompare

[ Source](https://github.com/metglobal-compass/dto-bundle)[ Packagist](https://packagist.org/packages/metglobal/dto-bundle)[ RSS](/packages/metglobal-dto-bundle/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

Metglobal Compass DTO Bundle
============================

[](#metglobal-compass-dto-bundle)

This bundle is focused to inject request parameters into data transfer objects.

Installation
============

[](#installation)

Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Applications that use Symfony Flex
----------------------------------

[](#applications-that-use-symfony-flex)

Open a command console, enter your project directory and execute:

```
$ composer require metglobal-compass/dto-bundle
```

Applications that don't use Symfony Flex
----------------------------------------

[](#applications-that-dont-use-symfony-flex)

### Step 1: Download the Bundle

[](#step-1-download-the-bundle)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

```
$ composer require metglobal-compass/dto-bundle
```

### Step 2: Enable the Bundle

[](#step-2-enable-the-bundle)

Then, enable the bundle by adding it to the list of registered bundles in the `config/bundles.php` file of your project:

```
// config/bundles.php

return [
    // ...
    Metglobal\DTOBundle\DTOBundle::class => ['all' => true],
];
```

### Step 3: Enable the param converter

[](#step-3-enable-the-param-converter)

```
Metglobal\DTOBundle\DTOParamConverter:
    tags:
        - { name: request.param_converter, priority: -2, converter: dto_converter }
```

How to use
==========

[](#how-to-use)

Define a controller method parameter with type hint. The type hint must be instance of `\Metglobal\Compass\Domain\DTO\Request`. If it is symfony will try to resolve the parameters with default configurations. Using the `\Metglobal\DTOBundle\DTOParamConverter`.

See: `\Metglobal\DTOBundle\DTOParamConverter::supports`.

Default parameter resolver parameters (see: `\Metglobal\DTOBundle\OptionsResolver\ParameterOptionsResolver`, `\Metglobal\DTOBundle\OptionsResolver\DateParameterOptionsResolver`):

```
[ 'type' => 'string', 'scope' => 'request', 'disabled' => false, 'options' => [], 'undefined' => false ]

```

Property annotation example:

```
@Metglobal\Compass\Annotation\DTO\Parameter(
    type="string",
    scope="request",
    path="pathOfThisParameter",
    disabled=false,
    options={},
    undefined=false
)

```

Available property annotation options
=====================================

[](#available-property-annotation-options)

The converter will try to resolve all the things automatically with defaults but you can configure below parameters using the `Metglobal\Compass\Annotation\DTO\Parameter` annotation and also if you do not define this annotation to property it'll try to resolve the itself too.

type:
-----

[](#type)

Variable's type. Available types are: 'string', 'boolean', 'bool', 'integer', 'int' and 'mixed'. Mixed type allows you to apply any type of value into property.

**Warning:** boolean type is exceptional see: `\Symfony\Component\HttpFoundation\ParameterBag::getBoolean`.

scope:
------

[](#scope)

Variable's scope. Available scopes are: 'request', 'query', 'headers', 'attributes'

path:
-----

[](#path)

Variable's path. It's default is property's name but you can customise the path of variable. Example: Url: `*.com?testPath=3`

```
/**
 * @Parameter(scope="query", path="testPath")
 */
public $differentName;
```

It'll set 3 into $differentName.

**Warning:** This parameter required per property if you do not define, it'll try to resolve the parameter with its property name. It means in above example path will `differentName`.

disabled:
---------

[](#disabled)

Disable injection for the selected parameter.

options:
--------

[](#options)

```
format:
-------
Available when you set type to date. You can configure input datetime's format with this property.

timezone:
--------
Available when you set type to date. You can configure datetime's timezone with this property.

```

undefinedable:
--------------

[](#undefinedable)

Make property undefinedable. This property makes you able to find undefined properties.

Extra annotation tips
=====================

[](#extra-annotation-tips)

This annotation can be use at property or class. If you define this property to class it will effect all the classes properties.

```
Default parameters overrides --> Class annotation parameters (If exists) overrides --> Property annotation parameters (If exists)

```

For every parameter it call the method that finds the final injection configs **per property**. Example:

```
