1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* This file is part of the Aggrego. |
5
|
|
|
* (c) Tomasz Kunicki <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types = 1); |
13
|
|
|
|
14
|
|
|
namespace Aggrego\Neo4jIntegration\Api\Command\RunCommand; |
15
|
|
|
|
16
|
|
|
use Aggrego\CommandConsumer\Command as CommandConsumer; |
17
|
|
|
use Aggrego\CommandConsumer\Name; |
18
|
|
|
use Aggrego\CommandConsumer\Uuid; |
19
|
|
|
use Assert\Assertion; |
20
|
|
|
|
21
|
|
|
class Command implements CommandConsumer |
22
|
|
|
{ |
23
|
|
|
public const NAME = 'neo4j_integration.run_command'; |
24
|
|
|
|
25
|
|
|
/** @var Uuid */ |
26
|
|
|
private $uuid; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
private $query; |
30
|
|
|
|
31
|
|
|
/** @var array */ |
32
|
|
|
private $parameters; |
33
|
|
|
|
34
|
|
|
public function __construct(string $uuid, string $query, array $parameters = []) |
35
|
|
|
{ |
36
|
|
|
Assertion::notEmpty($query); |
37
|
|
|
$this->uuid = new Uuid($uuid); |
38
|
|
|
$this->query = $query; |
39
|
|
|
$this->parameters = $parameters; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getUuid(): Uuid |
43
|
|
|
{ |
44
|
|
|
return $this->uuid; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getName(): Name |
48
|
|
|
{ |
49
|
|
|
return new Name(self::NAME); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getCypherQuery(): string |
53
|
|
|
{ |
54
|
|
|
return $this->query; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getParameters(): array |
58
|
|
|
{ |
59
|
|
|
return $this->parameters; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function serialize() |
63
|
|
|
{ |
64
|
|
|
return json_encode( |
65
|
|
|
[ |
66
|
|
|
'uuid' => $this->uuid->getValue(), |
67
|
|
|
'name' => self::NAME, |
68
|
|
|
'query' => $this->query, |
69
|
|
|
'parameters' => $this->parameters |
70
|
|
|
] |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function unserialize($serialized): self |
75
|
|
|
{ |
76
|
|
|
$json = json_decode($serialized, true); |
77
|
|
|
Assertion::keyExists($json, 'uuid'); |
78
|
|
|
Assertion::keyExists($json, 'name'); |
79
|
|
|
Assertion::eq($json['name'], self::NAME); |
80
|
|
|
Assertion::keyExists($json, 'query'); |
81
|
|
|
Assertion::keyExists($json, 'parameters'); |
82
|
|
|
|
83
|
|
|
return new self( |
|
|
|
|
84
|
|
|
$json['uuid'], |
85
|
|
|
$json['query'], |
86
|
|
|
$json['parameters'] |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: