Проинтегрировал новую версию трансформеров
This commit is contained in:
parent
c463effccf
commit
2e9ca614af
@ -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
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…
Reference in New Issue
Block a user