Compare commits

..

No commits in common. 'master' and '953d0872d7ccb752d3b606a6f69e8f8c1bc41ec0' have entirely different histories.

  1. 12
      composer.json
  2. 6338
      composer.lock
  3. 4
      src/Resources/config/services.yaml
  4. 8
      src/Service/Document.php
  5. 21
      src/Service/DocumentTransformer.php

@ -3,16 +3,16 @@
"description": "Doctrine entity bridge for data2dto bundle", "description": "Doctrine entity bridge for data2dto bundle",
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8.1", "php": "^8.0",
"ext-ctype": "*", "ext-ctype": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-json": "*", "ext-json": "*",
"rinsvent/data2dto": "^0.0", "rinsvent/data2dto": "^0.0",
"symfony/http-kernel": "^5.4", "rinsvent/data2dto-bundle": "^0.0",
"symfony/config": "^5.4", "symfony/http-kernel": "^5.3",
"symfony/dependency-injection": "^5.4", "symfony/config": "^5.3",
"doctrine/mongodb-odm": "^2", "symfony/dependency-injection": "^5.3",
"rinsvent/transformer-bundle": "^0.0" "doctrine/mongodb-odm": "^2"
}, },
"require-dev": { "require-dev": {
"codeception/codeception": "^4.1", "codeception/codeception": "^4.1",

6338
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -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' ]

@ -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);
}
} }

@ -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);
} }
} }

Loading…
Cancel
Save