proklung / dto-mapper-bundle
DTO mapper bundle.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.3 | ^8.0
- mark-gerarts/auto-mapper-plus: ^1.3
- psr/container: ^1.0
- symfony/config: ^4.0 || ^5.0
- symfony/dependency-injection: ^4.0 || ^5.0
- symfony/http-kernel: ^4.0 || ^5.0
- symfony/property-info: ^4.0 || ^5.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-29 06:12:45 UTC
README
INTERNAL
Установка
composer.json:
"repositories": [ { "type": "git", "url": "https://github.com/proklung/dto.mapper.bundle" } ]
composer require proklung/dto-mapper-bundle
Функционал
Сервис dto_mapper_bundle.mapper
с двумя методами:
convert($source, $destination)
convertCollection(iterable $sources, string $destination): iterable
Пример
Как-то так:
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" }