Files
development/www/lib/CoreLibs/Get/System.php
Clemens Schwaighofer 13c0fcd869 Fixes for CoreLibs based on phpunit tests
Add note that on change in lib/ folder (add/name/delete) 'composer
dump-autoload' must be run to update the composer auto loader as this is
currently on testing to not use internal autoloader

update all composer/vender autoload configs

Check\Basic: just apply updates in deprecated method calls
Check\Jason: has been deprecaged and moved to Convert\Json. Primary issue
was wrong name "Jason" instead of "Json"
Check\Password: only
Check\PhpVersion: fix version check for >9 numbers
Combined\Array: variable name change to be more clear, all searches are
strict for recoursive search, new option for recoursive search many to
return only found array data and no control array info. for backwards
compatible this is default set to ($old = true) and needs to be set to
false to get the new format,
array search normal has a new strict flag for forcing strict compare on
search.
remove some unneeded is_array checks,
fixed the flatten array to key to not only use leave elements, but all
array keys, if only leaves are wanted the new method
flattenArrayKeyLeavesOnly only returns key from leaves
Combined\DateTime: checkDateTime got more correct error checks on
invalid data
compareDate uses strtotimestamp for more easier compare like
compareDateTime does, both to a check on inalid timestamp now
calcDaysInterval also aborts on invalid data now
Convert\Byte: str to bytes does not drop the minus sign anymore
Convert\Colors: any error will now return false and not set to some
neutral gray. also fix missing round on hsb/hsl special return groups
Convert\Html: add constants for CHECKED/SELECTED options, fix remove
linebreak to not add two spaces if \r\n was found
Convert\Json: moved from Check\Jason and add two new error types
Convert\MimeAppName: do not set if mime type or app name is empty
Create\Hash: add crc32b to hash allows types so we can create a normal
not reversed crc32b
Create\Uids: move default hash type to var in class, fix defined
constant check
Debug\FileWriter: add log folder setting to override config constant
settings and also check if we can actually write to the folder and if
BASE and LOG constants are not empty
Get\System: add constant for getPageName and fix getHostName to be more
shorter and faster
Language\L10n: remove \Basic class extends because we don't need it
there at all
Template\SmartyExtend: fix constant check
2022-01-13 13:20:28 +09:00

100 lines
2.7 KiB
PHP

<?php
/*
* system related functions to get self name, host name, error strings
*/
declare(strict_types=1);
namespace CoreLibs\Get;
class System
{
public const WITH_EXTENSION = 0;
public const NO_EXTENSION = 1;
public const FULL_PATH = 2;
private const DEFAULT_PORT = '80';
/**
* helper function for PHP file upload error messgaes to messge string
* @param int $error_code integer _FILE upload error code
* @return string message string, translated
*/
public static function fileUploadErrorMessage(int $error_code): string
{
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
break;
case UPLOAD_ERR_FORM_SIZE:
$message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
break;
case UPLOAD_ERR_PARTIAL:
$message = 'The uploaded file was only partially uploaded';
break;
case UPLOAD_ERR_NO_FILE:
$message = 'No file was uploaded';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = 'Missing a temporary folder';
break;
case UPLOAD_ERR_CANT_WRITE:
$message = 'Failed to write file to disk';
break;
case UPLOAD_ERR_EXTENSION:
$message = 'File upload stopped by extension';
break;
default:
$message = 'Unknown upload error';
break;
}
return $message;
}
/**
* get the host name without the port as given by the SELF var
* @return array<mixed> host name/port name
*/
public static function getHostName(): array
{
$host = $_SERVER['HTTP_HOST'] ?? 'NOHOST:NOPORT';
list($host_name, $port) = array_pad(explode(':', $host), 2, self::DEFAULT_PORT);
return [$host_name, $port];
}
/**
* get the page name of the curronte page
* @param int $strip_ext WITH_EXTENSION: keep filename as is (default)
* NO_EXTENSION: strip page file name extension
* FULL_PATH: keep filename as is, but add dirname too
* @return string filename
*/
public static function getPageName(int $strip_ext = self::WITH_EXTENSION): string
{
// get the file info
$page_temp = pathinfo($_SERVER['PHP_SELF']);
if ($strip_ext == self::NO_EXTENSION) {
// no extension
return $page_temp['filename'];
} elseif ($strip_ext == self::FULL_PATH) {
// full path
return $_SERVER['PHP_SELF'];
} else {
// with extension
return $page_temp['basename'];
}
}
/**
* similar to getPageName, but it retuns the raw array
*
* @return array<string> pathinfo array from PHP SELF
*/
public static function getPageNameArray(): array
{
return pathinfo($_SERVER['PHP_SELF']);
}
}
// __END__