1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bankiru\Api\JsonRpc\Specification; |
4
|
|
|
|
5
|
|
|
use Bankiru\Api\JsonRpc\BankiruJsonRpcServerBundle; |
6
|
|
|
use Bankiru\Api\Rpc\RpcRequestInterface; |
7
|
|
|
use ScayTrase\Api\JsonRpc\JsonRpcRequestInterface; |
8
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
9
|
|
|
|
10
|
|
|
final class RichJsonRpcRequest implements RpcRequestInterface, JsonRpcRequestInterface |
11
|
|
|
{ |
12
|
|
|
/** @var JsonRpcRequestInterface */ |
13
|
|
|
private $request; |
14
|
|
|
/** @var ParameterBag */ |
15
|
|
|
private $attributes; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* RichJsonRpcRequest constructor. |
19
|
|
|
* |
20
|
|
|
* @param JsonRpcRequestInterface $request |
21
|
|
|
* @param ParameterBag $attributes |
22
|
|
|
*/ |
23
|
13 |
|
public function __construct(JsonRpcRequestInterface $request, ParameterBag $attributes = null) |
24
|
|
|
{ |
25
|
13 |
|
$this->request = $request; |
26
|
13 |
|
$this->attributes = $attributes ?: new ParameterBag(); |
27
|
13 |
|
} |
28
|
|
|
|
29
|
|
|
/** {@inheritdoc} */ |
30
|
13 |
|
public function isNotification() |
31
|
|
|
{ |
32
|
13 |
|
return $this->request->isNotification(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** {@inheritdoc} */ |
36
|
13 |
|
public function getAttributes() |
37
|
|
|
{ |
38
|
13 |
|
return $this->attributes; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** {@inheritdoc} */ |
42
|
|
View Code Duplication |
public function jsonSerialize() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
self::VERSION_FIELD => $this->getVersion(), |
46
|
|
|
self::METHOD_FIELD => $this->getMethod(), |
47
|
|
|
self::PARAMETERS_FIELD => $this->getParameters(), |
48
|
|
|
self::ID_FIELD => $this->getId(), |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** {@inheritdoc} */ |
53
|
|
|
public function getVersion() |
54
|
|
|
{ |
55
|
|
|
return BankiruJsonRpcServerBundle::JSONRPC_VERSION; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** {@inheritdoc} */ |
59
|
13 |
|
public function getMethod() |
60
|
|
|
{ |
61
|
13 |
|
return $this->request->getMethod(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** {@inheritdoc} */ |
65
|
6 |
|
public function getParameters() |
66
|
|
|
{ |
67
|
6 |
|
return $this->request->getParameters(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** {@inheritdoc} */ |
71
|
13 |
|
public function getId() |
72
|
|
|
{ |
73
|
13 |
|
return $this->request->getId(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.