Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Use Symfony's helper to format the memory values #283

Merged
merged 1 commit into from
Oct 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions src/Symfony/Installer/DownloadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use GuzzleHttp\Event\ProgressEvent;
use GuzzleHttp\Utils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -146,10 +147,10 @@ protected function download()

if (null === $progressBar) {
ProgressBar::setPlaceholderFormatterDefinition('max', function (ProgressBar $bar) {
return $this->formatSize($bar->getMaxSteps());
return Helper::formatMemory($bar->getMaxSteps());
});
ProgressBar::setPlaceholderFormatterDefinition('current', function (ProgressBar $bar) {
return str_pad($this->formatSize($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
return str_pad(Helper::formatMemory($bar->getProgress()), 11, ' ', STR_PAD_LEFT);
});

$progressBar = new ProgressBar($this->output, $downloadSize);
Expand Down Expand Up @@ -449,26 +450,6 @@ protected function checkPermissions()
return $this;
}

/**
* Utility method to show the number of bytes in a readable format.
*
* @param int $bytes The number of bytes to format
*
* @return string The human readable string of bytes (e.g. 4.32MB)
*/
protected function formatSize($bytes)
{
$units = array('B', 'KB', 'MB', 'GB', 'TB');

$bytes = max($bytes, 0);
$pow = $bytes ? floor(log($bytes, 1024)) : 0;
$pow = min($pow, count($units) - 1);

$bytes /= pow(1024, $pow);

return number_format($bytes, 2).' '.$units[$pow];
}

/**
* Formats the error message contained in the given Requirement item
* using the optional line length provided.
Expand Down