ÿØÿà JFIF H H ÿÛ C ÿÛ Cÿ " ÿÄ ÿÄ ÿÚ ±5¬€ ÿÄ àÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÄ àÿÚ ?! ÿÚ ÿÄ ÀÿÚ ? ÿÄ ÀÿÚ ? ÿÄ àÿÚ ? ÿÙ
| Server IP : 160.25.81.117 / Your IP : 216.73.216.137 Web Server : Apache/2 System : Linux sv05.hilab.cloud 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : bellizen ( 1045) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/bellizen/public_html/vendor/gabrielelana/byte-units/src/ByteUnits/ |
Upload File : |
<?php
namespace ByteUnits;
abstract class System
{
const DEFAULT_FORMAT_PRECISION = 2;
const COMPUTE_WITH_PRECISION = 10;
protected $formatter;
protected $numberOfBytes;
public static function bytes($numberOf, $formatWithPrecision = self::DEFAULT_FORMAT_PRECISION)
{
return new static($numberOf, $formatWithPrecision);
}
public static function parse($bytesAsString)
{
return static::parser()->parse($bytesAsString);
}
public function __construct($numberOfBytes, $formatter)
{
$this->formatter = $formatter;
$this->numberOfBytes = $this->ensureIsNotNegative($this->normalize($numberOfBytes));
}
public function add($another)
{
return new static(
bcadd($this->numberOfBytes, box($another)->numberOfBytes, self::COMPUTE_WITH_PRECISION),
$this->formatter->precision()
);
}
public function remove($another)
{
return new static(
bcsub($this->numberOfBytes, box($another)->numberOfBytes, self::COMPUTE_WITH_PRECISION),
$this->formatter->precision()
);
}
public function isEqualTo($another)
{
return self::compare($this, box($another)) === 0;
}
public function isGreaterThanOrEqualTo($another)
{
return self::compare($this, box($another)) >= 0;
}
public function isGreaterThan($another)
{
return self::compare($this, box($another)) > 0;
}
public function isLessThanOrEqualTo($another)
{
return self::compare($this, box($another)) <= 0;
}
public function isLessThan($another)
{
return self::compare($this, box($another)) < 0;
}
public static function compare($left, $right)
{
return bccomp(
$left->numberOfBytes,
$right->numberOfBytes,
self::COMPUTE_WITH_PRECISION
);
}
public function format($howToFormat = null)
{
return $this->formatter->format($this->numberOfBytes, $howToFormat);
}
public function asBinary()
{
return Binary::bytes($this->numberOfBytes);
}
public function asMetric()
{
return Metric::bytes($this->numberOfBytes);
}
private function normalize($numberOfBytes)
{
$numberOfBytes = (string) $numberOfBytes;
if (preg_match('/^(?P<coefficient>\d+(?:\.\d+))E\+(?P<exponent>\d+)$/', $numberOfBytes, $matches)) {
$numberOfBytes = bcmul(
$matches['coefficient'],
bcpow($base = 10, $matches['exponent'], self::COMPUTE_WITH_PRECISION)
);
}
return $numberOfBytes;
}
private function ensureIsNotNegative($numberOfBytes)
{
if (bccomp($numberOfBytes, 0) < 0) {
throw new NegativeBytesException();
}
return $numberOfBytes;
}
}