You are here

private function DrupalDataCollectorTrait::convertToBytes in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/DataCollector/DrupalDataCollectorTrait.php \Drupal\webprofiler\DataCollector\DrupalDataCollectorTrait::convertToBytes()
  2. 8.2 webprofiler/src/DataCollector/DrupalDataCollectorTrait.php \Drupal\webprofiler\DataCollector\DrupalDataCollectorTrait::convertToBytes()
  3. 4.x webprofiler/src/DataCollector/DrupalDataCollectorTrait.php \Drupal\webprofiler\DataCollector\DrupalDataCollectorTrait::convertToBytes()

Parameters

$value:

Return value

int|string

File

webprofiler/src/DataCollector/DrupalDataCollectorTrait.php, line 83

Class

DrupalDataCollectorTrait
Class DrupalDataCollectorTrait

Namespace

Drupal\webprofiler\DataCollector

Code

private function convertToBytes($value) {
  if ('-1' === $value) {
    return -1;
  }
  $value = strtolower($value);
  $max = strtolower(ltrim($value, '+'));
  if (0 === strpos($max, '0x')) {
    $max = intval($max, 16);
  }
  elseif (0 === strpos($max, '0')) {
    $max = intval($max, 8);
  }
  else {
    $max = intval($max);
  }
  switch (substr($value, -1)) {
    case 't':
      $max *= 1024;
      break;
    case 'g':
      $max *= 1024;
      break;
    case 'm':
      $max *= 1024;
      break;
    case 'k':
      $max *= 1024;
      break;
  }
  return $max;
}