forked from thephpleague/flysystem-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushCommand.php
More file actions
42 lines (35 loc) · 1.37 KB
/
PushCommand.php
File metadata and controls
42 lines (35 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/*
* This file is part of the flysystem-bundle project.
*
* (c) Titouan Galopin <galopintitouan@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\FlysystemBundle\Command;
use League\Flysystem\FilesystemOperator;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'flysystem:push', description: 'Push a local file to a configured Flysystem storage.')]
final class PushCommand extends AbstractTransferCommand
{
protected function transfer(FilesystemOperator $storage, string $source, string $destination): void
{
if (!is_file($source)) {
throw new \InvalidArgumentException(sprintf('The source file "%s" does not exist or is not a regular file.', $source));
}
$resource = fopen($source, 'rb');
if (false === $resource) {
throw new \RuntimeException(sprintf('Unable to open the source file "%s" for reading.', $source));
}
try {
$storage->writeStream($destination, $resource);
} finally {
fclose($resource);
}
}
protected function createSuccessMessage(string $storageName, string $source, string $destination): string
{
return sprintf('Pushed "%s" to "%s" on storage "%s".', $source, $destination, $storageName);
}
}