Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/proklung/dto.mapper.bundle
DTO mapper bundle. Addon for AutoMapperPlusBundle
https://github.com/proklung/dto.mapper.bundle
dto symfony symfony-bundle
Last synced: 11 days ago
JSON representation
DTO mapper bundle. Addon for AutoMapperPlusBundle
- Host: GitHub
- URL: https://github.com/proklung/dto.mapper.bundle
- Owner: ProklUng
- Created: 2021-06-01T07:30:24.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-06-01T07:32:01.000Z (over 3 years ago)
- Last Synced: 2024-04-22T04:01:21.226Z (7 months ago)
- Topics: dto, symfony, symfony-bundle
- Language: PHP
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.MD
Awesome Lists containing this project
README
# Надстройка над [AutoMapperPlusBundle](https://github.com/mark-gerarts/automapper-plus-bundle)
**INTERNAL**
### Установка
composer.json:
```json
"repositories": [
{
"type": "git",
"url": "https://github.com/proklung/dto.mapper.bundle"
}
]
``````bash
composer require proklung/dto-mapper-bundle
```
### Функционал
Сервис `dto_mapper_bundle.mapper` с двумя методами:
1) `convert($source, $destination)`
2) `convertCollection(iterable $sources, string $destination): iterable`### Пример
Как-то так:
```php
class EmployeVersionTwo
{
/**
* @var string $firstName
*/
private $firstName = 'first name version two';/**
* @var string $lastName
*/
private $lastName = 'last name version two';/**
* @var string $unused
*/
private $unused = '';/**
* @return string
*/
public function getFirstName(): string
{
return $this->firstName;
}/**
* @return string
*/
public function getLastName(): string
{
return $this->lastName;
}
}
class EmployeDtoVersionTwo
{
/**
* @var string $firstName
*/
public $firstName = 'first name dto';/**
* @var string $lastName
*/
public $lastName = 'last name dto';
}$mapper = container()->get('dto_mapper_bundle.mapper');
$srcObj = new EmployeVersionTwo();$result = $mapper->convert($srcObj, EmployeDtoVersionTwo::class);
var_dump($result);
```Результат (замаппились свойства из исходного класса):
`object(EmployeDtoVersionTwo)#7268 (2) { ["firstName"]=> string(22) "first name version two" ["lastName"]=> string(21) "last name version two" } `