Проинтегрировал новую версию трансформеров

master v0.0.4
Rinsvent 3 years ago
parent c463effccf
commit 2e9ca614af
  1. 3
      composer.json
  2. 6343
      composer.lock
  3. 2
      src/Resources/config/services.yaml
  4. 8
      src/Service/Entity.php
  5. 21
      src/Service/EntityTransformer.php

@ -12,7 +12,8 @@
"symfony/http-kernel": "^5.3",
"symfony/config": "^5.3",
"symfony/dependency-injection": "^5.3",
"doctrine/orm": "^2"
"doctrine/orm": "^2",
"rinsvent/transformer-bundle": "^0.0.1"
},
"require-dev": {
"codeception/codeception": "^4.1",

6343
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -9,4 +9,4 @@ services:
_instanceof:
Rinsvent\Data2DTOBundle\Service\AbstractTransformer:
tags: [ 'rinsvent.transformer' ]
tags: [ 'rinsvent.transformer.transformer' ]

@ -2,7 +2,7 @@
namespace Rinsvent\Data2DTODoctrineEntityBundle\Service;
use Rinsvent\Data2DTO\Transformer\Meta;
use Rinsvent\Transformer\Transformer\Meta;
#[\Attribute]
class Entity extends Meta
@ -11,6 +11,8 @@ class Entity extends Meta
public function __construct(
public string $class,
public string $primaryType = 'id',
) {}
public array $tags = ['default'],
) {
parent::__construct($tags);
}
}

@ -3,28 +3,27 @@
namespace Rinsvent\Data2DTODoctrineEntityBundle\Service;
use Doctrine\ORM\EntityManagerInterface;
use Rinsvent\Data2DTO\Transformer\Meta;
use Rinsvent\Data2DTOBundle\Service\AbstractTransformer;
use Rinsvent\Transformer\Transformer\Meta;
use Rinsvent\TransformerBundle\Service\AbstractTransformer;
class EntityTransformer extends AbstractTransformer
{
public function __construct(
protected EntityManagerInterface $em
) {}
) {
}
/**
* @param $data
* @param Entity $meta
*/
public function transform(&$data, Meta $meta): void
public function transform(mixed $data, Meta $meta): mixed
{
if ($meta->primaryType === 'id' && !is_int($data)) {
return;
}
if ($meta->primaryType === 'uuid' && !is_string($data)) {
return;
}
$repository = $this->em->getRepository($meta->class);
$data = $repository->find($data);
try {
return $repository->find($data);
} catch (\Throwable) {
return $data;
}
}
}

Loading…
Cancel
Save