Convert memory to a human readable string for the console.
@param int $mem In bytes
@return string
3797
protected function memoryToString($mem)
    {
        $abs = abs($mem);
        if ($abs < 1024) {
            return "$mem Bytes";
        } elseif ($abs < 1048576) {
            return round($mem / 1024, 2)." KB";
        } else {
            return round($mem / 1048576, 2)." MB";
        }
    }
229355
function _convertNumber($num)
    {
        // Integer in the range 0..2**16-1
        if ((preg_match("/^\d+$/", $num)) and ($num <= 65535)) {
            return pack("Cv", $this->ptg['ptgInt'], $num);
        } else { // A float
            if ($this->_byte_order) { // if it's Big Endian
                $num = strrev($num);
            }
            return pack("Cd", $this->ptg['ptgNum'], $num);
        }
    }
958193
function formatBytes($bytes)
    {
        $bytes = floatval($bytes);
        $arBytes = array(
            0 => array(
                "UNIT" => "TB",
                "VALUE" => pow(1024, 4)
            ),
            1 => array(
                "UNIT" => "GB",
                "VALUE" => pow(1024, 3)
            ),
            2 => array(
                "UNIT" => "MB",
                "VALUE" => pow(1024, 2)
            ),
            3 => array(
                "UNIT" => "KB",
                "VALUE" => 1024
            ),
            4 => array(
                "UNIT" => "B",
                "VALUE" => 1
            ),
        );

        foreach($arBytes as $arItem)
        {
            if($bytes >= $arItem["VALUE"])
            {
                $result = $bytes / $arItem["VALUE"];
                $result = str_replace(".", "," , strval(round($result, 2)))." ".$arItem["UNIT"];
                break;
            }
        }
        return $result;
    }
494894
private function GetParamString($param)
    {
        if ($param === null)
            return "null";
        if (is_string($param))
            return "'" .  addcslashes($param, "'") . "'";
        
        else if (is_bool($param))
            return $param ? "true" : "false";
        
        else if (is_int($param) || is_float($param))
            return (string)$param;
        
        else if ($param instanceof WritableClass)
            return $param->GetNewStatement();
        
        else if (is_array($param))
        {
            $resultArr = array();
            foreach ($param as $key=>$val)
            {
                $resultArr[] = $this->GetParamString($key) . '=>' . $this->GetParamString($val);
            }
            return 'array(' . join (', ' , $resultArr) .')';
        }
        else if ($param instanceof \Phine\Framework\System\Enum)
        {
            $value = $param->Value();
            $class = get_class($param);
            return "\\$class::ByValue('$value')";
        }
        throw new \InvalidArgumentException('A writable class must have primitive types, Enums, arrays and PhpWritable classes as construct params only.');
    }
743254
public static function word(int $num): string
    {
        $numberWordMap = [
            1 => Yii::t('yuncms', 'One'),
            2 => Yii::t('yuncms', 'Two'),
            3 => Yii::t('yuncms', 'Three'),
            4 => Yii::t('yuncms', 'Four'),
            5 => Yii::t('yuncms', 'Five'),
            6 => Yii::t('yuncms', 'Six'),
            7 => Yii::t('yuncms', 'Seven'),
            8 => Yii::t('yuncms', 'Eight'),
            9 => Yii::t('yuncms', 'Nine')
        ];

        if (isset($numberWordMap[$num])) {
            return $numberWordMap[$num];
        }

        return (string)$num;
    }
961238
public function readBytes(int $num, bool $skipTests = false): string
    {
        // @codeCoverageIgnoreStart
        if ($num < 0) {
            throw new CannotPerformOperation('num < 0');
        } elseif ($num === 0) {
            return '';
        }
        if (($this->pos + $num) > $this->stat['size']) {
            throw new CannotPerformOperation('Out-of-bounds read');
        }
        // @codeCoverageIgnoreEnd
        $buf = '';
        $remaining = $num;
        do {
            if ($remaining <= 0) {
                // @codeCoverageIgnoreStart
                break;
                // @codeCoverageIgnoreEnd
            }
            /** @var int $bufSize */
            $bufSize = \min($remaining, self::CHUNK);
            /** @var string|bool $read */
            $read = \fread($this->fp, $bufSize);
            if (!\is_string($read)) {
                // @codeCoverageIgnoreStart
                throw new FileAccessDenied(
                    'Could not read from the file'
                );
                // @codeCoverageIgnoreEnd
            }
            $buf .= $read;
            $readSize = Binary::safeStrlen($read);
            $this->pos += $readSize;
            $remaining -= $readSize;
        } while ($remaining > 0);
        return $buf;
    }
524353
private static function formatParameter($param): string
	{
		if (is_int($param) || is_float($param)) {
			return (string) $param;

		} elseif (is_string($param)) {
			return "'" . addslashes($param) . "'";

		} elseif (is_null($param)) {
			return "NULL";

		} elseif (is_bool($param)) {
			return $param ? "TRUE" : "FALSE";

		} elseif (is_array($param)) {
			$formatted = [];
			foreach ($param as $value) {
				$formatted[] = self::formatParameter($value);
			}
			return implode(', ', $formatted);

		} elseif ($param instanceof \Datetime) {
			return "'" . $param->format('Y-m-d H:i:s') . "'";

		} elseif (is_object($param)) {
			return get_class($param) . (method_exists($param, 'getId') ? '(' . $param->getId() . ')' : '');

		} else {
			return @"'$param'"; // @ - conversion of something to string
		}
	}
245446
protected static function paramToString($param)
    {
        if (is_string($param)) {
            return '"' . $param . '"';
        }

        if (is_numeric($param)) {
            return $param;
        }

        if (is_null($param)) {
            return 'NULL';
        }

        if (is_bool($param)) {
            return $param ? 'TRUE' : 'FALSE';
        }

        if (is_resource($param)) {
            return '#resource';
        }

        if (is_callable($param)) {
            if (is_string($param)) {
                return $param;
            }

            if (is_array($param)) {
                if (is_string($param[0])) {
                    return $param[0] . '::' . $param[1];
                } else {
                    return get_class($param[0]) . '->' . $param[1];
                }
            }

            return 'Closure';
        }

        if (is_array($param)) {
            return 'Array(' . count($param) . ')';
        }

        if (is_object($param)) {
            return get_class($param);
        }

        return 'unknown';
    }
821517
private function encodeNumber($num)
    {
        $encodeString = '';

        while ($num >= 0x20) {
            $nextValue = (0x20 | ($num & 0x1f)) + 63;
            $encodeString .= chr($nextValue);
            $num >>= 5;
        }
        $finalValue = $num + 63;
        $encodeString .= chr($finalValue);
        return $encodeString;
    }
208577
private static function convertBytesToEntities(array $m)
    {
        $m = $m[1];
        $out = "";
        for($i=0; $i < strlen($m); $i++)
        {
            $out .= '&#X'.strtoupper(dechex(ord($m[$i]))).';';
        }
        return $out;
    }
579043
public static function digit_to_word($num)
    {
        $numbers = array(_t('MathSpamProtection.ZERO', 'zero'),
            _t('MathSpamProtection.ONE', 'one'),
            _t('MathSpamProtection.TWO', 'two'),
            _t('MathSpamProtection.THREE', 'three'),
            _t('MathSpamProtection.FOUR', 'four'),
            _t('MathSpamProtection.FIVE', 'five'),
            _t('MathSpamProtection.SIX', 'six'),
            _t('MathSpamProtection.SEVEN', 'seven'),
            _t('MathSpamProtection.EIGHT', 'eight'),
            _t('MathSpamProtection.NINE', 'nine'),
            _t('MathSpamProtection.TEN', 'ten'),
            _t('MathSpamProtection.ELEVEN', 'eleven'),
            _t('MathSpamProtection.TWELVE', 'twelve'),
            _t('MathSpamProtection.THIRTEEN', 'thirteen'),
            _t('MathSpamProtection.FOURTEEN', 'fourteen'),
            _t('MathSpamProtection.FIFTEEN', 'fifteen'),
            _t('MathSpamProtection.SIXTEEN', 'sixteen'),
            _t('MathSpamProtection.SEVENTEEN', 'seventeen'),
            _t('MathSpamProtection.EIGHTEEN', 'eighteen'));

        if ($num < 0) {
            return "minus ".($numbers[-1*$num]);
        }

        return $numbers[$num];
    }
131077
public function toBytes()
    {
        if (0 === gmp_cmp($this->value, gmp_init(0))) {
            return '';
        }

        $temp = gmp_strval(gmp_abs($this->value), 16);
        $temp = mb_strlen($temp, '8bit') & 1 ? '0'.$temp : $temp;
        $temp = hex2bin($temp);

        return ltrim($temp, chr(0));
    }
791939
public static function encode($num)
    {
        $str = '';
        while ($num > 0) {
            $str = self::ALPHABET[($num % self::BASE)] . $str;
            $num = (int)($num / self::BASE);
        }
        return $str;
    }
29510
public function toString()
	{
		if( function_exists( 'mb_convert_case' ) )
			$name	= mb_convert_case( $this->name, MB_CASE_TITLE );
		else
			$name	= str_replace( " ", "-", ucwords( str_replace( "-", " ", $this->name ) ) );
		return $name.": ".$this->value;
	}
705448
private static function getMemoryLimit() {
    // Get values if no cache
    if (null === self::$memoryLimit) {
      $limit = ini_get('memory_limit');

	  // Feal with defaults
      if ('' === (string) $limit) {
        $limit = '128M';
      }

      $value = (int) $limit;

	  // Deal with "no-limit"
      if ($value < 0) {
        $value = false;
      } else {
        // Deal with shorthand bytes
        switch (strtoupper(substr($limit, -1))) {
          case 'G': $value *= 1024;
          case 'M': $value *= 1024;
          case 'K': $value *= 1024;
        }
      }
      self::$memoryLimit = $value;
    }
    return self::$memoryLimit;
  }
412996
public function consumeReadBuffer(int $bytes) : string
    {
        if ($this->getBufferLength()<$bytes) {
            throw new \RuntimeException("BufferedSocket::getAndConsumeReadBuffer requested more bytes than are currently available. Requested=".$bytes.", available=".$this->getBufferLength().".");
        }
        $data = \substr($this->getReadBuffer(), 0, $bytes);
        $this->reduceReadBuffer($bytes);
        return $data;
    }
951619
private function _memory()
    {
        if ($this->_wmi) {
            $buffer = $this->_get_Win32_OperatingSystem();
            if ($buffer) {
                $this->sys->setMemTotal($buffer[0]['TotalVisibleMemorySize'] * 1024);
                $this->sys->setMemFree($buffer[0]['FreePhysicalMemory'] * 1024);
                $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
            }
            $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PageFileUsage');
            foreach ($buffer as $swapdevice) {
                $dev = new DiskDevice();
                $dev->setName("SWAP");
                $dev->setMountPoint($swapdevice['Name']);
                $dev->setTotal($swapdevice['AllocatedBaseSize'] * 1024 * 1024);
                $dev->setUsed($swapdevice['CurrentUsage'] * 1024 * 1024);
                $dev->setFree($dev->getTotal() - $dev->getUsed());
                $dev->setFsType('swap');
                $this->sys->setSwapDevices($dev);
            }
        } elseif (($buffer = $this->_get_systeminfo()) && preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n/m", $buffer, $buffer2)) {
//           && (preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n.*:\s+(\S+)\r\n/m", $buffer, $buffer2)) {
            $this->sys->setMemTotal(preg_replace('/(\s)|(\xFF)/', '', $buffer2[1]) * 1024 * 1024);
            $this->sys->setMemFree(preg_replace('/(\s)|(\xFF)/', '', $buffer2[2]) * 1024 * 1024);
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
        }
    }