asShortSize() 공개 메소드

This is the short form of [[asSize]]. If [[sizeFormatBase]] is 1024, binary prefixes (e.g. kibibyte/KiB, mebibyte/MiB, ...) are used in the formatting result.
또한 보기: sizeFormatBase
또한 보기: asSize
public asShortSize ( string | integer | float $value, integer $decimals = null, array $options = [], array $textOptions = [] ) : string
$value string | integer | float value in bytes to be formatted.
$decimals integer the number of digits after the decimal point.
$options array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
$textOptions array optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
리턴 string the formatted result.
예제 #1
0
 public function testAsShortSize()
 {
     // tests for base 1000
     $this->formatter->sizeFormatBase = 1000;
     $this->assertSame("999 B", $this->formatter->asShortSize(999));
     $this->assertSame("1.05 MB", $this->formatter->asShortSize(1024 * 1024));
     $this->assertSame("1.0486 MB", $this->formatter->asShortSize(1024 * 1024, 4));
     $this->assertSame("1.00 KB", $this->formatter->asShortSize(1000));
     $this->assertSame("1.02 KB", $this->formatter->asShortSize(1023));
     $this->assertNotEquals("3 PB", $this->formatter->asShortSize(3 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000));
     // this is 3 EB not 3 PB
     // tests for base 1024
     $this->formatter->sizeFormatBase = 1024;
     $this->assertSame("1.00 KiB", $this->formatter->asShortSize(1024));
     $this->assertSame("1.00 MiB", $this->formatter->asShortSize(1024 * 1024));
     // https://github.com/yiisoft/yii2/issues/4960
     $this->assertSame("1023 B", $this->formatter->asShortSize(1023));
     $this->assertSame("5.00 GiB", $this->formatter->asShortSize(5 * 1024 * 1024 * 1024));
     $this->assertNotEquals("5.00 PiB", $this->formatter->asShortSize(5 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024));
     // this is 5 EiB not 5 PiB
     //$this->assertSame("1 YiB", $this->formatter->asShortSize(pow(2, 80)));
     $this->assertSame("2.00 GiB", $this->formatter->asShortSize(2147483647));
     // round 1.999 up to 2
     $this->formatter->decimalSeparator = ',';
     $this->assertSame("1,001 KiB", $this->formatter->asShortSize(1025, 3));
     // empty values
     $this->assertSame('0 bytes', $this->formatter->asSize(0));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asSize(null));
 }
예제 #2
0
 /**
  * https://github.com/yiisoft/yii2/issues/4960
  */
 public function testAsSizeConfiguration()
 {
     $this->assertSame("1023 bytes", $this->formatter->asSize(1023));
     $this->assertSame("1023 B", $this->formatter->asShortSize(1023));
     $this->formatter->thousandSeparator = '.';
     $this->assertSame("1023 bytes", $this->formatter->asSize(1023));
     $this->assertSame("1023 B", $this->formatter->asShortSize(1023));
 }
예제 #3
0
 public function actionList()
 {
     $files = $this->getFiles();
     $format = new Formatter();
     $x = 1;
     echo "Find " . count($files) . " backup files:\n\n";
     foreach ($files as $key => $value) {
         $file = key($value);
         $fullPath = current($value);
         $skip = str_repeat(" ", 37 - strlen($file));
         echo $x++ . ". " . $file . ' ' . $skip . ' ' . $format->asShortSize(filesize($fullPath)) . "\n\r";
     }
 }