1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSRestBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\RestBundle\Serializer; |
13
|
|
|
|
14
|
|
|
use JMS\Serializer\Handler\SubscribingHandlerInterface; |
15
|
|
|
use JMS\Serializer\Handler\HandlerRegistryInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Search in the class parents to find an adapted handler. |
19
|
|
|
* |
20
|
|
|
* @author Ener-Getick <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @internal do not depend on this class directly |
23
|
|
|
* |
24
|
|
|
* @deprecated since FOSRestBundle 3.1, use the option `fos_rest.serializer.disable_custom_jms_registry` to avoid relying on it. |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
final class JMSHandlerRegistryV2 implements HandlerRegistryInterface |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
private $registry; |
29
|
|
|
|
30
|
8 |
|
public function __construct(HandlerRegistryInterface $registry) |
31
|
|
|
{ |
32
|
8 |
|
$this->registry = $registry; |
33
|
8 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function registerSubscribingHandler(SubscribingHandlerInterface $handler): void |
39
|
|
|
{ |
40
|
|
|
$this->registry->registerSubscribingHandler($handler); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function registerHandler(int $direction, string $typeName, string $format, $handler): void |
47
|
|
|
{ |
48
|
|
|
$this->registry->registerHandler($direction, $typeName, $format, $handler); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
6 |
|
public function getHandler(int $direction, string $typeName, string $format) |
55
|
|
|
{ |
56
|
6 |
|
$first = true; |
57
|
|
|
do { |
58
|
6 |
|
$handler = $this->registry->getHandler($direction, $typeName, $format); |
59
|
6 |
|
if (null !== $handler) { |
60
|
6 |
|
if (!$first) { |
61
|
|
|
@trigger_error(sprintf('Relying on the custom registry %s to inherit the JMS handler of type `%s` is deprecated since FOSRestBundle 3.1. It will be removed in version 4.0. Use the option `fos_rest.serializer.disable_custom_jms_registry` to disable it.', __CLASS__, $typeName), E_USER_DEPRECATED); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
6 |
|
return $handler; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$first = false; |
68
|
|
|
} while ($typeName = get_parent_class($typeName)); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.