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
|
|
|
* Statistics command. |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
class StatisticsCommand implements CommandInterface { |
17
|
|
|
use \Evenement\EventEmitterTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The identifier for this command. |
21
|
|
|
* @var int |
22
|
|
|
* @source |
23
|
|
|
*/ |
24
|
|
|
const COMMAND_ID = 0x09; |
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
|
1 |
|
function getEncodedMessage(): string { |
36
|
1 |
|
return \chr(static::COMMAND_ID); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
41
|
|
|
* @return int |
42
|
|
|
*/ |
43
|
1 |
|
function setParserState(): int { |
44
|
1 |
|
return -1; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Sets the command as completed. This state gets reported back to the user. |
49
|
|
|
* @return void |
50
|
|
|
*/ |
51
|
1 |
|
function onComplete(): void { |
52
|
1 |
|
$this->finished = true; |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Sets the command as errored. This state gets reported back to the user. |
57
|
|
|
* @param \Throwable $throwable |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
1 |
|
function onError(\Throwable $throwable): void { |
61
|
1 |
|
$this->finished = true; |
62
|
1 |
|
$this->emit('error', array($throwable)); |
63
|
1 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sends the next received value into the command. |
67
|
|
|
* @param mixed $value |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
1 |
|
function onNext($value): void { |
71
|
1 |
|
$this->finished = true; |
72
|
1 |
|
$this->emit('end', array($value)); |
73
|
1 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Whether the command has finished. |
77
|
|
|
* @return bool |
78
|
|
|
*/ |
79
|
3 |
|
function hasFinished(): bool { |
80
|
3 |
|
return $this->finished; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Whether this command sets the connection as busy. |
85
|
|
|
* @return bool |
86
|
|
|
*/ |
87
|
1 |
|
function waitForCompletion(): bool { |
88
|
1 |
|
return true; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Whether the sequence ID should be resetted. |
93
|
|
|
* @return bool |
94
|
|
|
*/ |
95
|
1 |
|
function resetSequence(): bool { |
96
|
1 |
|
return true; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|