1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ScayTrase\Api\Cruds\Adaptors\JmsSerializer; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
6
|
|
|
use JMS\Serializer\Context; |
7
|
|
|
use JMS\Serializer\VisitorInterface; |
8
|
|
|
use ScayTrase\Api\Cruds\Adaptors\DoctrineOrm\EntityToIdNormalizer; |
9
|
|
|
|
10
|
|
|
final class JmsDoctrineHandler |
11
|
|
|
{ |
12
|
|
|
const TYPE = 'DoctrineAssociation'; |
13
|
|
|
|
14
|
|
|
/** @var ManagerRegistry */ |
15
|
|
|
private $registry; |
16
|
|
|
/** @var EntityToIdNormalizer */ |
17
|
|
|
private $converter; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* JmsDoctrineHandler constructor. |
21
|
|
|
* |
22
|
|
|
* @param ManagerRegistry $registry |
23
|
|
|
*/ |
24
|
|
|
public function __construct(ManagerRegistry $registry) |
25
|
|
|
{ |
26
|
|
|
$this->registry = $registry; |
27
|
|
|
$this->converter = new EntityToIdNormalizer($this->registry); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function serializeRelation(VisitorInterface $visitor, $relation, array $type, Context $context) |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
if ($relation instanceof \Traversable) { |
33
|
|
|
$relation = iterator_to_array($relation); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (is_array($relation)) { |
37
|
|
|
return array_map([$this->converter, 'normalize'], $relation); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
return $this->converter->normalize($relation); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function deserializeRelation(VisitorInterface $visitor, $data, array $type, Context $context) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
// obtain params from deeps |
46
|
|
|
// $class = $type['params'][0]['name']; |
|
|
|
|
47
|
|
|
// return $this->converter->denormalize($data, $class); |
|
|
|
|
48
|
|
|
|
49
|
|
|
// fixme |
50
|
|
|
throw new \BadMethodCallException('Not supported at the moment'); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.