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