Skip to content

Commit

Permalink
Make amphp/file optional
Browse files Browse the repository at this point in the history
Added support for amphp/file 2.x.
  • Loading branch information
trowski committed Nov 10, 2020
1 parent b6e9c25 commit 8729495
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,14 +15,14 @@
"require": {
"php": ">=7.1",
"amphp/amp": "^2",
"amphp/file": "^1 || ^0.3.5",
"amphp/socket": "^1",
"amphp/sql": "^1",
"amphp/sql-common": "^1"
},
"require-dev": {
"ext-openssl": "*",
"amphp/process": "^1",
"amphp/file": "^2 || ^1 || ^0.3.5",
"phpunit/phpunit": "^9 || ^8 || ^7",
"amphp/phpunit-util": "^1.1.2",
"amphp/php-cs-fixer-config": "dev-master",
Expand Down
14 changes: 12 additions & 2 deletions src/Internal/Processor.php
Expand Up @@ -5,6 +5,7 @@
use Amp\CancellationToken;
use Amp\Coroutine;
use Amp\Deferred;
use Amp\File;
use Amp\Loop;
use Amp\Mysql\CommandResult;
use Amp\Mysql\ConnectionConfig;
Expand Down Expand Up @@ -852,8 +853,17 @@ private function handleLocalInfileRequest(string $packet): void
\Amp\asyncCall(function () use ($packet) {
try {
$filePath = \substr($packet, 1);
/** @var \Amp\File\Handle $fileHandle */
$fileHandle = yield \Amp\File\open($filePath, 'r');
/** @var \Amp\File\File $fileHandle */
if (\function_exists("Amp\\File\\openFile")) {
// amphp/file 2.x
$fileHandle = yield File\openFile($filePath, 'r');
} elseif (\function_exists("Amp\\File\\open")) {
// amphp/file 1.x or 0.3.x
$fileHandle = yield File\open($filePath, 'r');
} else {
throw new \Error("amphp/file must be installed for LOCAL INFILE queries");
}

while ("" != ($chunk = yield $fileHandle->read())) {
$this->sendPacket($chunk);
}
Expand Down

0 comments on commit 8729495

Please sign in to comment.