66 lines
1.9 KiB
PHP
66 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace WizdomNetworks\WizeWeb\Utils;
|
|
|
|
/**
|
|
* Sanitizer Utility
|
|
*
|
|
* Provides methods for sanitizing various types of data, including strings, emails, URLs, and arrays.
|
|
*
|
|
* Logs sanitized data for debugging and traceability.
|
|
*/
|
|
class Sanitizer
|
|
{
|
|
/**
|
|
* Sanitizes a string by removing harmful characters.
|
|
*
|
|
* @param string $value The string to sanitize.
|
|
* @return string The sanitized string.
|
|
*/
|
|
public static function sanitizeString(string $value): string
|
|
{
|
|
$sanitized = filter_var($value, FILTER_SANITIZE_STRING);
|
|
Logger::info("Sanitized string: Original: $value | Sanitized: $sanitized");
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* Sanitizes an email address.
|
|
*
|
|
* @param string $value The email address to sanitize.
|
|
* @return string The sanitized email address.
|
|
*/
|
|
public static function sanitizeEmail(string $value): string
|
|
{
|
|
$sanitized = filter_var($value, FILTER_SANITIZE_EMAIL);
|
|
Logger::info("Sanitized email: Original: $value | Sanitized: $sanitized");
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* Sanitizes a URL.
|
|
*
|
|
* @param string $value The URL to sanitize.
|
|
* @return string The sanitized URL.
|
|
*/
|
|
public static function sanitizeURL(string $value): string
|
|
{
|
|
$sanitized = filter_var($value, FILTER_SANITIZE_URL);
|
|
Logger::info("Sanitized URL: Original: $value | Sanitized: $sanitized");
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* Sanitizes an array of strings.
|
|
*
|
|
* @param array $values The array of strings to sanitize.
|
|
* @return array The sanitized array.
|
|
*/
|
|
public static function sanitizeArray(array $values): array
|
|
{
|
|
$sanitizedArray = filter_var_array($values, FILTER_SANITIZE_STRING);
|
|
Logger::info("Sanitized array: Original: " . json_encode($values) . " | Sanitized: " . json_encode($sanitizedArray));
|
|
return $sanitizedArray;
|
|
}
|
|
}
|