humanFileSize() публичный статический Метод

См. также: http://www.php.net/manual/en/function.filesize.php#106569
public static humanFileSize ( integer $bytes, integer $decimals = 2 ) : string
$bytes integer
$decimals integer
Результат string
Пример #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @throws RuntimeException
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->detectMagento($output);
     if ($this->initMagento()) {
         $fileName = $input->getArgument('log_filename');
         if ($fileName === null) {
             $path = $this->askLogFile($output);
         } else {
             $path = $this->getLogDir() . DIRECTORY_SEPARATOR . $fileName;
         }
         if ($this->logfileExists(basename($path))) {
             $size = @filesize($path);
             if ($size === false) {
                 throw new RuntimeException('Couldn\\t detect filesize.');
             }
         } else {
             $size = 0;
         }
         if ($input->getOption('human')) {
             $output->writeln(\N98\Util\Filesystem::humanFileSize($size));
         } else {
             $output->writeln("{$size}");
         }
     }
 }
Пример #2
0
 /**
  * @param array $vars
  *
  * @return array
  */
 protected function formatVariables(array $vars)
 {
     $rounding = (int) $this->_input->getOption('rounding');
     if ($rounding > -1) {
         foreach ($vars as $k => &$v) {
             if (true === $this->allowRounding($k)) {
                 $v = Filesystem::humanFileSize($v, $rounding);
             }
             if (isset($this->_specialFormat[$k])) {
                 $v = $this->{$this->_specialFormat[$k]}($v);
             }
         }
         unset($v);
     }
     $maxWidth = $this->getMaxValueWidth($vars);
     // align=right
     foreach ($vars as &$v) {
         $v = str_pad($v, $maxWidth, ' ', STR_PAD_LEFT);
     }
     return $vars;
 }
Пример #3
0
 /**
  * @param int $bytes
  * @param int $decimalPlaces
  * @param string $expected
  * @dataProvider convertedBytesProvider
  */
 public function testConvertBytesToHumanReadable($bytes, $decimalPlaces, $expected)
 {
     $res = Filesystem::humanFileSize($bytes, $decimalPlaces);
     $this->assertSame($expected, $res);
 }