Skip to content

Commit

Permalink
use symfony/console to format bytes if available
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Nov 22, 2021
1 parent 28cd828 commit 69f6699
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"symfony/process": "~3.4|~4.0|~5.0",
"symfony/console": "~3.4|~4.0|~5.0",
"symfony/finder": "~3.4|~4.0|~5.0",
"gabrielelana/byte-units": "^0.3.0",
"league/flysystem": "~1.0",
"phpunit/phpunit": "^5.7.11"
},
Expand All @@ -28,9 +27,6 @@
"autoload-dev": {
"psr-4": { "Zenstruck\\Backup\\Tests\\": "tests/" }
},
"suggest": {
"gabrielelana/byte-units": "For pretty filesize display"
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
Expand Down
10 changes: 10 additions & 0 deletions src/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Zenstruck\Backup;

use Symfony\Component\Console\Helper\Helper;

/**
* @author Kevin Bond <kevinbond@gmail.com>
*/
Expand Down Expand Up @@ -49,6 +51,14 @@ public function getSize()
return $this->size;
}

/**
* @return string
*/
public function getFormattedSize()
{
return \class_exists(Helper::class) ? Helper::formatMemory($this->size) : $this->size.' B';
}

/**
* @return \DateTime
*/
Expand Down
8 changes: 1 addition & 7 deletions src/Console/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ private function listBackups(Destination $destination, OutputInterface $output)
}

foreach ($destination->all() as $backup) {
$size = $backup->getSize();

if (class_exists('\\ByteUnits\\System')) {
$size = \ByteUnits\parse($size)->format('B');
}

$table->addRow(array($backup->getKey(), $size, $backup->getCreatedAt()->format('Y-m-d H:i:s')));
$table->addRow(array($backup->getKey(), $backup->getFormattedSize(), $backup->getCreatedAt()->format('Y-m-d H:i:s')));
}

$table->render();
Expand Down
8 changes: 1 addition & 7 deletions src/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,10 @@ private function sendToDestinations(Profile $profile, $filename)
foreach ($profile->getDestinations() as $destination) {
$backup = $destination->push($filename, $this->logger);

$size = $backup->getSize();

if (class_exists('\\ByteUnits\\System')) {
$size = \ByteUnits\parse($size)->format('B');
}

$this->logger->info(
sprintf('Backup created for destination "%s" at: "%s" ', $destination->getName(), $backup->getKey()),
array(
'size' => $size,
'size' => $backup->getFormattedSize(),
'created_at' => $backup->getCreatedAt()->format('Y-m-d H:i:s'),
)
);
Expand Down

0 comments on commit 69f6699

Please sign in to comment.