1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Plasma Driver MySQL component |
4
|
|
|
* Copyright 2018 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
|
|
|
function __construct(\Plasma\Drivers\MySQL\Messages\HandshakeMessage $handshake, int $capability) { |
|
|
|
|
40
|
|
|
$this->handshake = $handshake; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the encoded message for writing to the database connection. |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
|
|
function getEncodedMessage(): string { |
48
|
|
|
$maxPacketSize = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_MAX_PACKET_SIZE; |
49
|
|
|
$charsetNumber = \Plasma\Drivers\MySQL\ProtocolParser::CLIENT_CHARSET_NUMBER; |
50
|
|
|
|
51
|
|
|
$packet = \pack('VVc', $this->capability, $maxPacketSize, $charsetNumber); |
52
|
|
|
$packet .= \str_repeat("\x00", 23); |
53
|
|
|
|
54
|
|
|
$this->finished = true; |
55
|
|
|
return $packet; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
60
|
|
|
* @return int |
61
|
|
|
*/ |
62
|
|
|
function setParserState(): int { |
63
|
|
|
return \Plasma\Drivers\MySQL\ProtocolParser::STATE_HANDSHAKE; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Sets the command as completed. This state gets reported back to the user. |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
function onComplete(): void { |
71
|
|
|
$this->finished = true; |
72
|
|
|
$this->emit('end', array()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Sets the command as errored. This state gets reported back to the user. |
77
|
|
|
* @param \Throwable $throwable |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
function onError(\Throwable $throwable): void { |
81
|
|
|
$this->finished = true; |
82
|
|
|
$this->emit('error', array($throwable)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Sends the next received value into the command. |
87
|
|
|
* @param mixed $value |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
function onNext($value): void { |
91
|
|
|
// Nothing to do |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Whether the command has finished. |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
|
|
function hasFinished(): bool { |
99
|
|
|
return $this->finished; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Whether this command sets the connection as busy. |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
|
|
function waitForCompletion(): bool { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Whether the sequence ID should be resetted. |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
function resetSequence(): bool { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.