1 <?php 2 3 declare(strict_types=1); 4 5 namespace OpenSpout\Reader\XLSX\Manager\SharedStringsCaching; 6 7 /** 8 * @internal 9 */ 10 final class MemoryLimit 11 { 12 private string $memoryLimit; 13 14 public function __construct(string $memoryLimit) 15 { 16 $this->memoryLimit = $memoryLimit; 17 } 18 19 /** 20 * Returns the PHP "memory_limit" in Kilobytes. 21 */ 22 public function getMemoryLimitInKB(): float 23 { 24 $memoryLimitFormatted = strtolower(trim($this->memoryLimit)); 25 26 // No memory limit 27 if ('-1' === $memoryLimitFormatted) { 28 return -1; 29 } 30 31 if (1 === preg_match('/(\d+)([bkmgt])b?/', $memoryLimitFormatted, $matches)) { 32 $amount = (int) $matches[1]; 33 $unit = $matches[2]; 34 35 switch ($unit) { 36 case 'b': return $amount / 1024; 37 38 case 'k': return $amount; 39 40 case 'm': return $amount * 1024; 41 42 case 'g': return $amount * 1024 * 1024; 43 44 case 't': return $amount * 1024 * 1024 * 1024; 45 } 46 } 47 48 return -1; 49 } 50 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body