Utils
in package
Tags
Table of Contents
Methods
- __construct() : mixed
- array_merge_by_value() : array<string|int, mixed>
- merge two associative array by a common value key
- array_str_in_string() : bool
- Checks if any string from an array is present in a given string.
- array_to_csv() : void
- Converts an array to CSV and writes to a file or outputs as attachment.
- check_url() : bool
- Checks if a URL is reachable (HTTP status < 400).
- compute_discount() : float
- Computes the discounted price.
- compute_vat() : float
- Computes the price including VAT.
- error_handler() : void
- Custom error handler that logs errors to helPHP.log.
- error_handler_to_trash() : bool
- Dummy error handler for suppressed errors.
- error_log() : void
- Logs arbitrary data to helPHP.log, with optional short format.
- filter_string() : string
- Filters a string to only allow characters from a given set.
- fix_EOL() : string
- Fixes double slaches in the classic EOL.
- follow_system_process() : string|false
- Follows the progress of a system process tracked in session.
- follow_system_process_redis() : mixed
- Follows the progress of a system process tracked in Redis.
- get_css_as_str() : string
- Returns a CSS theme in DB as a string to export it.
- get_ext_from_mime() : mixed
- get_host_ip() : string
- Retrieves the host IP address from the routing table.
- get_ip() : string
- Retrieves the client IPv4 address.
- get_ip_v6() : string
- Retrieves the client IPv6 address.
- get_mime_type() : mixed
- log_backtrace() : void
- Logs a PHP backtrace to helPHP.log.
- make_constant() : bool
- Regenerates the constants.js file from PHP constants.
- random_string() : string
- Generates a random string of given length and character set.
- remove_accents() : string
- Removes accents from a string.
- remove_vat() : float
- Removes VAT from a price.
- str_contains_only() : bool
- Checks if a string contains only characters from a given set.
- string_in_array_str() : mixed
- Checks if a string is present at the start of any string in an array.
- substr_from_html() : string
- Gets a substring from HTML, preserving tags and word boundaries.
- system_process() : void
- Launches a system process and pushes its output to a session variable, which can be followed by a key.
- system_process_no_redis() : void
- Launches one or more system processes with no tracking
- system_process_no_session() : string
- Launches a system process and returns its output as a string (without session tracking).
- system_process_to_redis() : void
- Launches one or more system processes and tracks their output/progress in Redis.
- write_in_config() : bool
- Updates the main config file with new variable values.
Methods
__construct()
public
__construct() : mixed
array_merge_by_value()
merge two associative array by a common value key
public
static array_merge_by_value(array<string|int, mixed> $a, array<string|int, mixed> $b, string $valueKey) : array<string|int, mixed>
The two associative array should have a common label key that will be used to merge them if I put the valueKey "id", my two array will be merged by the id key in their values. Preserve the orginal index in case of identical key, the second one is kept
Exemple: $a = [['id'=>'1','value'=>'jesuis1'],['id'=>'2','value'=>'jesuis2']]; $b = [['id'=>'1','value'=>'jesuispas1'],['id'=>'3','value'=>'jesuis3']]; $c = array_merge_by_value($a, $b, 'id'); [['id'=>'1','value'=>'jesuispas1'],['id'=>'2','value'=>'jesuis2'],['id'=>'3','value'=>'jesuis3']] $c = array_merge_by_value($b, $a, 'id'); [['id'=>'1','value'=>'jesuis1'],['id'=>'2','value'=>'jesuis2'],['id'=>'3','value'=>'jesuis3']]
Parameters
- $a : array<string|int, mixed>
-
First array.
- $b : array<string|int, mixed>
-
Second array.
- $valueKey : string
-
Key to merge by.
Return values
array<string|int, mixed> —Merged array.
array_str_in_string()
Checks if any string from an array is present in a given string.
public
static array_str_in_string(string $str, array<string|int, mixed> $array, bool $startwith) : bool
Parameters
- $str : string
-
The string to search in.
- $array : array<string|int, mixed>
-
The array of needles.
- $startwith : bool
-
If true, checks for start of string.
Return values
bool —True if found, false otherwise.
array_to_csv()
Converts an array to CSV and writes to a file or outputs as attachment.
public
static array_to_csv(array<string|int, mixed> $arraydata, string $filename[, bool $attachment = false ][, bool $headers = true ]) : void
Parameters
- $arraydata : array<string|int, mixed>
-
Data to write.
- $filename : string
-
Filename or output stream.
- $attachment : bool = false
-
If true, sends as attachment.
- $headers : bool = true
-
If true, includes headers.
check_url()
Checks if a URL is reachable (HTTP status < 400).
public
static check_url(string $url) : bool
Parameters
- $url : string
-
The URL to check.
Return values
bool —True if reachable, false otherwise.
compute_discount()
Computes the discounted price.
public
static compute_discount(float $prix, float $remise) : float
Parameters
- $prix : float
-
Original price.
- $remise : float
-
Discount percentage.
Return values
float —Discounted price.
compute_vat()
Computes the price including VAT.
public
static compute_vat(float $prix, float $tva) : float
Parameters
- $prix : float
-
Original price.
- $tva : float
-
VAT percentage.
Return values
float —Price including VAT.
error_handler()
Custom error handler that logs errors to helPHP.log.
public
static error_handler(int $errno, string $errstr, string $errfile, int $errline) : void
Parameters
- $errno : int
-
Error number.
- $errstr : string
-
Error message.
- $errfile : string
-
File where error occurred.
- $errline : int
-
Line number of error.
error_handler_to_trash()
Dummy error handler for suppressed errors.
public
static error_handler_to_trash(mixed $errno, mixed $errstr, mixed $errfile, mixed $errline) : bool
$errno $errstr $errfile $errline ar there juste for compatibility they are unsused
Parameters
- $errno : mixed
- $errstr : mixed
- $errfile : mixed
- $errline : mixed
Return values
bool —Always returns false.
error_log()
Logs arbitrary data to helPHP.log, with optional short format.
public
static error_log(mixed $data[, bool $short_form = false ]) : void
Parameters
- $data : mixed
-
Data to log.
- $short_form : bool = false
-
If true, logs in short format.
filter_string()
Filters a string to only allow characters from a given set.
public
static filter_string(string $t[, string $limit = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_" ]) : string
Parameters
- $t : string
-
The input string.
- $limit : string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
-
Allowed characters.
Return values
string —The filtered string.
fix_EOL()
Fixes double slaches in the classic EOL.
public
static fix_EOL(string $str) : string
Parameters
- $str : string
-
The input string.
Return values
string —The string with fixed EOL.
follow_system_process()
Follows the progress of a system process tracked in session.
public
static follow_system_process([string|false $key = false ]) : string|false
Parameters
- $key : string|false = false
-
The key referencing the process.
Return values
string|false —The process output or 'ok!' when finished.
follow_system_process_redis()
Follows the progress of a system process tracked in Redis.
public
static follow_system_process_redis([string|false $key = false ][, bool $update_history = false ]) : mixed
Parameters
- $key : string|false = false
-
The key referencing the process.
- $update_history : bool = false
-
Whether to update history when finished.
Return values
mixed —Progress percentage, 'ok!' when finished, or false.
get_css_as_str()
Returns a CSS theme in DB as a string to export it.
public
static get_css_as_str([int $id_theme = 0 ]) : string
Parameters
- $id_theme : int = 0
-
Theme ID.
Return values
string —CSS string.
get_ext_from_mime()
public
static get_ext_from_mime(mixed $mime) : mixed
Parameters
- $mime : mixed
get_host_ip()
Retrieves the host IP address from the routing table.
public
static get_host_ip() : string
Return values
string —The host IP address.
get_ip()
Retrieves the client IPv4 address.
public
static get_ip() : string
Return values
string —The IP address or 'NoIp' if not found.
get_ip_v6()
Retrieves the client IPv6 address.
public
static get_ip_v6() : string
Return values
string —The IPv6 address or 'NoIp' if not found.
get_mime_type()
public
static get_mime_type(mixed $ext) : mixed
Parameters
- $ext : mixed
log_backtrace()
Logs a PHP backtrace to helPHP.log.
public
static log_backtrace([bool $show_args = false ]) : void
Parameters
- $show_args : bool = false
-
Whether to show function arguments in the log.
Return values
void —(it's writing in helphp.log file)
make_constant()
Regenerates the constants.js file from PHP constants.
public
static make_constant() : bool
Return values
bool —True on success, false on error.
random_string()
Generates a random string of given length and character set.
public
static random_string([int $length = 5 ][, string|false $valid_characters = false ]) : string
Parameters
- $length : int = 5
-
Length of the string.
- $valid_characters : string|false = false
-
Allowed characters.
Return values
string —Random string.
remove_accents()
Removes accents from a string.
public
static remove_accents(string $text) : string
Parameters
- $text : string
-
The input string.
Return values
string —The string without accents.
remove_vat()
Removes VAT from a price.
public
static remove_vat(float $prix, float $tva) : float
Parameters
- $prix : float
-
Price including VAT.
- $tva : float
-
VAT percentage.
Return values
float —Price without VAT.
str_contains_only()
Checks if a string contains only characters from a given set.
public
static str_contains_only(string $string, string $gama) : bool
Parameters
- $string : string
-
The string to check.
- $gama : string
-
Allowed characters.
Return values
bool —True if only allowed characters, false otherwise.
string_in_array_str()
Checks if a string is present at the start of any string in an array.
public
static string_in_array_str(string $str, array<string|int, mixed> $array[, bool $details = true ]) : mixed
Parameters
- $str : string
-
The string to search for.
- $array : array<string|int, mixed>
-
The array to search in.
- $details : bool = true
-
If true, returns matching entries; else returns true/false.
Return values
mixed —Array of matches or boolean.
substr_from_html()
Gets a substring from HTML, preserving tags and word boundaries.
public
static substr_from_html(string $str, int $start, int $len) : string
Parameters
- $str : string
-
The HTML string.
- $start : int
-
Start position.
- $len : int
-
Length of substring.
Return values
string —The substring with HTML tags preserved.
system_process()
Launches a system process and pushes its output to a session variable, which can be followed by a key.
public
static system_process(string $cmd, string $key) : void
Used a lot by Filesystem class
Parameters
- $cmd : string
-
The command to execute.
- $key : string
-
The key to indentify the process output in session.
system_process_no_redis()
Launches one or more system processes with no tracking
public
static system_process_no_redis(array<string|int, mixed>|string $cmds, string $key[, string|false $type = false ][, array<string|int, mixed>|false $arg = false ][, array<string|int, mixed>|false $to_unlocked = false ]) : void
Parameters
- $cmds : array<string|int, mixed>|string
-
The command(s) to execute.
- $key : string
-
The key to reference the process in Redis.
- $type : string|false = false
-
Optional. Type for progress tracking.
- $arg : array<string|int, mixed>|false = false
-
Optional. Argument for the command type.
- $to_unlocked : array<string|int, mixed>|false = false
-
Optional. Paths to lock/unlock during the process.
system_process_no_session()
Launches a system process and returns its output as a string (without session tracking).
public
static system_process_no_session(string $cmd) : string
Parameters
- $cmd : string
-
The command to execute.
Return values
string —The output of the command.
system_process_to_redis()
Launches one or more system processes and tracks their output/progress in Redis.
public
static system_process_to_redis(array<string|int, mixed>|string $cmds, string $key[, string|false $type = false ][, array<string|int, mixed>|false $arg = false ][, array<string|int, mixed>|false $to_unlocked = false ]) : void
Parameters
- $cmds : array<string|int, mixed>|string
-
The command(s) to execute.
- $key : string
-
The key to reference the process in Redis.
- $type : string|false = false
-
Optional. Type for progress tracking.
- $arg : array<string|int, mixed>|false = false
-
Optional. Argument for the command type.
- $to_unlocked : array<string|int, mixed>|false = false
-
Optional. Paths to lock/unlock during the process.
write_in_config()
Updates the main config file with new variable values.
public
static write_in_config(string|array<string|int, mixed> $variable_name, string|array<string|int, mixed> $type, mixed $value[, string $path = false ]) : bool
Parameters
- $variable_name : string|array<string|int, mixed>
-
Variable name(s) to update.
- $type : string|array<string|int, mixed>
-
Type(s) of variable ('s' for string, etc.).
- $value : mixed
-
Value(s) to set.
- $path : string = false
-
Path of the config file to modify.
Return values
bool —True on success, false on error.