Проинтегрировал новый трансформер
This commit is contained in:
parent
a9f184e898
commit
f7cc8b99f6
@ -8,11 +8,11 @@
|
||||
"ext-iconv": "*",
|
||||
"ext-json": "*",
|
||||
"rinsvent/data2dto": "^0.0",
|
||||
"rinsvent/data2dto-bundle": "^0.0",
|
||||
"symfony/http-kernel": "^5.4",
|
||||
"symfony/config": "^5.4",
|
||||
"symfony/dependency-injection": "^5.4",
|
||||
"doctrine/mongodb-odm": "^2"
|
||||
"doctrine/mongodb-odm": "^2",
|
||||
"rinsvent/transformer-bundle": "^0.0.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"codeception/codeception": "^4.1",
|
||||
|
@ -9,4 +9,4 @@ services:
|
||||
|
||||
_instanceof:
|
||||
Rinsvent\Data2DTOBundle\Service\AbstractTransformer:
|
||||
tags: [ 'rinsvent.transformer' ]
|
||||
tags: [ 'rinsvent.transformer.transformer' ]
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Rinsvent\Data2DTODoctrineDocumentBundle\Service;
|
||||
|
||||
use Rinsvent\Data2DTO\Transformer\Meta;
|
||||
use Rinsvent\Transformer\Transformer\Meta;
|
||||
|
||||
#[\Attribute]
|
||||
class Document extends Meta
|
||||
@ -11,6 +11,8 @@ class Document 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\Data2DTODoctrineDocumentBundle\Service;
|
||||
|
||||
use Doctrine\ODM\MongoDB\DocumentManager;
|
||||
use Rinsvent\Data2DTO\Transformer\Meta;
|
||||
use Rinsvent\Data2DTOBundle\Service\AbstractTransformer;
|
||||
use Rinsvent\Transformer\Transformer\Meta;
|
||||
use Rinsvent\TransformerBundle\Service\AbstractTransformer;
|
||||
|
||||
class DocumentTransformer extends AbstractTransformer
|
||||
{
|
||||
public function __construct(
|
||||
protected DocumentManager $dm
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param Document $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->dm->getRepository($meta->class);
|
||||
$data = $repository->find($data);
|
||||
try {
|
||||
return $repository->find($data);
|
||||
} catch (\Throwable) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user