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\Messages; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Represents a Local In File Data Message. |
14
|
|
|
* @internal |
15
|
|
|
*/ |
16
|
|
|
class LocalInFileRequestMessage implements \Plasma\Drivers\MySQL\Messages\MessageInterface { |
17
|
|
|
/** |
18
|
|
|
* @var \Plasma\Drivers\MySQL\ProtocolParser |
19
|
|
|
*/ |
20
|
|
|
protected $parser; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Constructor. |
24
|
|
|
* @param \Plasma\Drivers\MySQL\ProtocolParser $parser |
25
|
|
|
*/ |
26
|
3 |
|
function __construct(\Plasma\Drivers\MySQL\ProtocolParser $parser) { |
27
|
3 |
|
$this->parser = $parser; |
28
|
3 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get the identifier for the packet. |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
1 |
|
static function getID(): string { |
35
|
1 |
|
return "\xFB"; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Parses the message, once the complete string has been received. |
40
|
|
|
* Returns false if not enough data has been received, or the remaining buffer. |
41
|
|
|
* @param \Plasma\BinaryBuffer $buffer |
42
|
|
|
* @return bool |
43
|
|
|
* @throws \Plasma\Drivers\MySQL\Messages\ParseException |
44
|
|
|
*/ |
45
|
|
|
function parseMessage(\Plasma\BinaryBuffer $buffer): bool { |
46
|
|
|
$filesystem = \Plasma\Drivers\MySQL\DriverFactory::getFilesystem(); |
47
|
|
|
|
48
|
|
|
if($filesystem !== null) { |
49
|
|
|
$filesystem->file($buffer->getContents())->getContents()->then(null, function () { |
50
|
|
|
return ''; |
51
|
|
|
})->then(function (string $content) { |
52
|
|
|
$this->sendFile($content); |
53
|
|
|
}); |
54
|
|
|
} else { |
55
|
|
|
if(\file_exists($buffer->getContents())) { |
56
|
|
|
$this->sendFile(\file_get_contents($buffer->getContents())); |
57
|
|
|
} else { |
58
|
|
|
$this->sendFile(''); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the parser which created this message. |
67
|
|
|
* @return \Plasma\Drivers\MySQL\ProtocolParser |
68
|
|
|
*/ |
69
|
1 |
|
function getParser(): \Plasma\Drivers\MySQL\ProtocolParser { |
70
|
1 |
|
return $this->parser; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets the parser state, if necessary. If not, return `-1`. |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
1 |
|
function setParserState(): int { |
78
|
1 |
|
return -1; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sends the contents to the server. |
83
|
|
|
* @param string $content |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
protected function sendFile(string $content): void { |
87
|
|
|
$this->parser->sendPacket($content); |
88
|
|
|
$this->parser->sendPacket(''); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|