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
|
|
|
* SSLRequest command. |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
class SSLRequestCommand implements CommandInterface { |
17
|
|
|
use \Evenement\EventEmitterTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \Plasma\Drivers\MySQL\Messages\HandshakeMessage |
21
|
|
|
*/ |
22
|
|
|
protected $handshake; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
protected $capability; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var bool |
31
|
|
|
*/ |
32
|
|
|
protected $finished = false; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor. |
36
|
|
|
* @param \Plasma\Drivers\MySQL\Messages\HandshakeMessage $handshake |
37
|
|
|
* @param int $capability |
38
|
|
|
*/ |
39
|
7 |
|
function __construct(\Plasma\Drivers\MySQL\Messages\HandshakeMessage $handshake, int $capability) { |
40
|
7 |
|
$this->handshake = $handshake; |
41
|
7 |
|
$this->capability = $capability; |
42
|
7 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the encoded message for writing to the database connection. |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
1 |
|
function getEncodedMessage(): string { |
49
|
1 |
|
$maxPacketSize = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_MAX_PACKET_SIZE; |
50
|
1 |
|
$charsetNumber = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_CHARSET_NUMBER; |
51
|
|
|
|
52
|
1 |
|
$packet = \pack('VVc', $this->capability, $maxPacketSize, $charsetNumber); |
53
|
1 |
|
$packet .= \str_repeat("\x00", 23); |
54
|
|
|
|
55
|
1 |
|
$this->finished = true; |
56
|
1 |
|
return $packet; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
1 |
|
function setParserState(): int { |
64
|
1 |
|
return \Plasma\Drivers\MySQL\ProtocolParser::STATE_HANDSHAKE; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Sets the command as completed. This state gets reported back to the user. |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
1 |
|
function onComplete(): void { |
72
|
1 |
|
$this->finished = true; |
73
|
1 |
|
$this->emit('end'); |
74
|
1 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sets the command as errored. This state gets reported back to the user. |
78
|
|
|
* @param \Throwable $throwable |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
1 |
|
function onError(\Throwable $throwable): void { |
82
|
1 |
|
$this->finished = true; |
83
|
1 |
|
$this->emit('error', array($throwable)); |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Sends the next received value into the command. |
88
|
|
|
* @param mixed $value |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
1 |
|
function onNext($value): void { |
92
|
|
|
// Nothing to do |
93
|
1 |
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Whether the command has finished. |
97
|
|
|
* @return bool |
98
|
|
|
*/ |
99
|
1 |
|
function hasFinished(): bool { |
100
|
1 |
|
return $this->finished; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Whether this command sets the connection as busy. |
105
|
|
|
* @return bool |
106
|
|
|
*/ |
107
|
1 |
|
function waitForCompletion(): bool { |
108
|
1 |
|
return false; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Whether the sequence ID should be resetted. |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
1 |
|
function resetSequence(): bool { |
116
|
1 |
|
return false; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|