Basic Class update

Start moving all basic class methods into dedicated classes.
Most of them are static and can be direct called.
No need to group them into one big class that is hard to maintain and
check.

Work is ongoing
This commit is contained in:
Clemens Schwaighofer
2021-06-04 21:22:30 +09:00
parent ee6e0581da
commit 4ae1c2bde0
38 changed files with 4482 additions and 2105 deletions

View File

@@ -0,0 +1,60 @@
<?php declare(strict_types=1);
/*
* html convert functions
*/
namespace CoreLibs\Convert;
class Html
{
/**
* full wrapper for html entities
* @param mixed $string string to html encode
* @return mixed if string, encoded, else as is (eg null)
*/
public static function htmlent($string)
{
if (is_string($string)) {
return htmlentities($string, ENT_COMPAT|ENT_HTML401, 'UTF-8', false);
} else {
return $string;
}
}
/**
* strips out all line breaks or replaced with given string
* @param string $string string
* @param string $replace replace character, default ' '
* @return string cleaned string without any line breaks
*/
public static function removeLB(string $string, string $replace = ' '): string
{
return str_replace(array("\r", "\n"), $replace, $string);
}
/**
* returns 'checked' or 'selected' if okay
* $needle is a var, $haystack an array or a string
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
* @param array|string $haystack (search in) haystack can be an array or a string
* @param string $needle needle (search for)
* @param int $type type: 0: returns selected, 1, returns checked
* @return ?string returns checked or selected, else returns null
*/
public static function checked($haystack, $needle, int $type = 0): ?string
{
if (is_array($haystack)) {
if (in_array((string)$needle, $haystack)) {
return $type ? 'checked' : 'selected';
}
} else {
if ($haystack == $needle) {
return $type ? 'checked' : 'selected';
}
}
return null;
}
}
// __END__