1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plasma Driver MySQL component |
4
|
|
|
* Copyright 2018-2019 PlasmaPHP, All Rights Reserved |
5
|
|
|
* |
6
|
|
|
* Website: https://github.com/PlasmaPHP |
7
|
|
|
* License: https://github.com/PlasmaPHP/driver-mysql/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Plasma\Drivers\MySQL\Commands; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Ping command. |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
class PingCommand implements CommandInterface { |
17
|
|
|
use \Evenement\EventEmitterTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The identifier for this command. |
21
|
|
|
* @var int |
22
|
|
|
* @source |
23
|
|
|
*/ |
24
|
|
|
const COMMAND_ID = 0x0E; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var bool |
28
|
|
|
*/ |
29
|
|
|
protected $finished = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get the encoded message for writing to the database connection. |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
4 |
|
function getEncodedMessage(): string { |
36
|
4 |
|
$this->finished = true; |
37
|
4 |
|
return \chr(static::COMMAND_ID); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
42
|
|
|
* @return int |
43
|
|
|
*/ |
44
|
4 |
|
function setParserState(): int { |
45
|
4 |
|
return -1; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Sets the command as completed. This state gets reported back to the user. |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
3 |
|
function onComplete(): void { |
53
|
3 |
|
$this->finished = true; |
54
|
3 |
|
$this->emit('end'); |
55
|
3 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sets the command as errored. This state gets reported back to the user. |
59
|
|
|
* @param \Throwable $throwable |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
function onError(\Throwable $throwable): void { |
63
|
|
|
$this->finished = true; |
64
|
|
|
$this->emit('error', array($throwable)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Sends the next received value into the command. |
69
|
|
|
* @param mixed $value |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
function onNext($value): void { |
73
|
|
|
// Nothing to do |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Whether the command has finished. |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
3 |
|
function hasFinished(): bool { |
81
|
3 |
|
return $this->finished; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Whether this command sets the connection as busy. |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
4 |
|
function waitForCompletion(): bool { |
89
|
4 |
|
return true; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Whether the sequence ID should be resetted. |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
4 |
|
function resetSequence(): bool { |
97
|
4 |
|
return true; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|