blue-twilight/installer/AppRequirements.php

71 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace AppInstaller;
use App\Helpers\MiscHelper;
class AppRequirements
{
const STATUS_OK = 0;
const STATUS_WARNING = 1;
const STATUS_NOT_MET = 2;
public static function hasCurlLibrary()
{
return self::isModuleLoaded('curl') ? self::STATUS_OK : self::STATUS_NOT_MET;
}
public static function hasGdLibrary()
{
return self::isModuleLoaded('gd') ? self::STATUS_OK : self::STATUS_NOT_MET;
}
public static function hasMySqlClientLibrary()
{
return self::isModuleLoaded('pdo_mysql') ? self::STATUS_OK : self::STATUS_NOT_MET;
}
public static function maxPostRequestSize(&$status)
{
$bytes = self::getPhpIniValueAsBytes('post_max_size');
$recommendedMinimum = 4 * 1024 * 1024;
if ($bytes < $recommendedMinimum)
{
return self::STATUS_WARNING;
}
$status = sprintf('%0.2f MB', $bytes / 1024 / 1024);
return self::STATUS_OK;
}
public static function maxUploadSize(&$status)
{
$bytes = self::getPhpIniValueAsBytes('upload_max_filesize');
$recommendedMinimum = 4 * 1024 * 1024;
if ($bytes < $recommendedMinimum)
{
return self::STATUS_WARNING;
}
$status = sprintf('%0.2f MB', $bytes / 1024 / 1024);
return self::STATUS_OK;
}
public static function php72OrLater(&$status)
{
$status = phpversion();
return version_compare(phpversion(), '7.4.5', '>=') ? self::STATUS_OK : self::STATUS_NOT_MET;
}
private static function getPhpIniValueAsBytes($settingName)
{
return MiscHelper::convertToBytes(ini_get($settingName));
}
private static function isModuleLoaded($name)
{
return extension_loaded($name);
}
}