Newwebshop/classes/Tools.php

55 lines
1.2 KiB
PHP

<?php
/**
* Copyright seit 2024 Webshop System
*
* Hilfsfunktionen für das Webshop-System
*
* @author Webshop System
* @license GPL v3
*/
class Tools
{
public static function redirectToInstall()
{
header('Location: /install');
exit;
}
public static function convertBytes($value)
{
if (is_numeric($value)) {
return (int)$value;
}
$value_length = strlen($value);
$qty = (int)substr($value, 0, $value_length - 1);
$unit = strtolower(substr($value, $value_length - 1));
switch ($unit) {
case 'k':
$qty *= 1024;
break;
case 'm':
$qty *= 1048576;
break;
case 'g':
$qty *= 1073741824;
break;
}
return $qty;
}
public static function isPHPCLI()
{
return (php_sapi_name() === 'cli' || defined('STDIN'));
}
public static function argvToGET($argc, $argv)
{
for ($i = 1; $i < $argc; $i++) {
if (strpos($argv[$i], '=') !== false) {
list($key, $value) = explode('=', $argv[$i], 2);
$_GET[$key] = $value;
}
}
}
}