Compare commits

..

No commits in common. "master" and "v0.0.3" have entirely different histories.

4 changed files with 18 additions and 19 deletions

View File

@ -8,11 +8,11 @@
"ext-iconv": "*", "ext-iconv": "*",
"ext-json": "*", "ext-json": "*",
"rinsvent/data2dto": "^0.0", "rinsvent/data2dto": "^0.0",
"rinsvent/data2dto-bundle": "^0.0",
"symfony/http-kernel": "^5.4", "symfony/http-kernel": "^5.4",
"symfony/config": "^5.4", "symfony/config": "^5.4",
"symfony/dependency-injection": "^5.4", "symfony/dependency-injection": "^5.4",
"doctrine/mongodb-odm": "^2", "doctrine/mongodb-odm": "^2"
"rinsvent/transformer-bundle": "^0.0"
}, },
"require-dev": { "require-dev": {
"codeception/codeception": "^4.1", "codeception/codeception": "^4.1",

View File

@ -8,5 +8,5 @@ services:
resource: '../../../src/Service' resource: '../../../src/Service'
_instanceof: _instanceof:
Rinsvent\TransformerBundle\Service\AbstractTransformer: Rinsvent\Data2DTOBundle\Service\AbstractTransformer:
tags: [ 'rinsvent.transformer.transformer' ] tags: [ 'rinsvent.transformer' ]

View File

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

View File

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