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