You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.6 KiB
88 lines
2.6 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* @author Robert Strutts
|
|
* @copyright Copyright (c) 2022, Robert Strutts.
|
|
* @license MIT
|
|
*/
|
|
|
|
namespace CodeHydrater\enums;
|
|
|
|
class safer_io_enums {} // Needed to auto-load
|
|
|
|
enum HTML_FLAG {
|
|
case raw; // Dangerious XSS attacks...
|
|
case strip;
|
|
case encode;
|
|
case purify; // Allow safe whitelisted HTML elements/tags
|
|
case escape; // safely Escape HTML
|
|
}
|
|
|
|
enum INPUTS: int {
|
|
case variable = 998; // User Defined VAR
|
|
case debugging = 999; // check POST and then if debugging is set, check GET
|
|
case json = 1000; // uses JSON on raw POST BODY
|
|
case post = 0; // INPUT_POST;
|
|
case get = 1; // INPUT_GET;
|
|
case cookie = 2; //INPUT_COOKIE;
|
|
case env = 4; // INPUT_ENV;
|
|
case server = 5; // INPUT_SERVER;
|
|
|
|
public function resolve(): int {
|
|
return match($this) {
|
|
self::post => INPUT_POST,
|
|
self::get => INPUT_GET,
|
|
self::cookie => INPUT_COOKIE,
|
|
self::env => INPUT_ENV,
|
|
self::server => INPUT_SERVER,
|
|
};
|
|
}
|
|
}
|
|
|
|
enum DB_FILTER {
|
|
case ON; // Tries to Filter out SQL from User Input
|
|
case OFF; // Normal pass thourgh...
|
|
}
|
|
|
|
enum FIELD_FILTER: string {
|
|
case raw_string = "string";
|
|
case array_of_strings = "strings";
|
|
case email = "email-address";
|
|
case url = "site-url";
|
|
case raw = "unfiltered-non-sanitized";
|
|
case integer_number = "integer";
|
|
case array_of_ints = "integers";
|
|
case floating_point = "float";
|
|
case array_of_floats = "floats";
|
|
|
|
public function resolve() {
|
|
return match($this) {
|
|
self::raw_string => FILTER_UNSAFE_RAW,
|
|
self::array_of_strings => [
|
|
'filter' => FILTER_UNSAFE_RAW,
|
|
'flags' => FILTER_REQUIRE_ARRAY
|
|
],
|
|
self::email => FILTER_SANITIZE_EMAIL,
|
|
self::url => FILTER_SANITIZE_URL,
|
|
self::raw => FILTER_DEFAULT, // Unfiltered, non-sanitized!!!
|
|
self::integer_number => [
|
|
'filter' => FILTER_SANITIZE_NUMBER_INT,
|
|
'flags' => FILTER_REQUIRE_SCALAR
|
|
],
|
|
self::array_of_ints => [
|
|
'filter' => FILTER_SANITIZE_NUMBER_INT,
|
|
'flags' => FILTER_REQUIRE_ARRAY
|
|
],
|
|
self::floating_point => [
|
|
'filter' => FILTER_SANITIZE_NUMBER_FLOAT,
|
|
'flags' => FILTER_FLAG_ALLOW_FRACTION
|
|
],
|
|
self::array_of_floats => [
|
|
'filter' => FILTER_SANITIZE_NUMBER_FLOAT,
|
|
'flags' => FILTER_REQUIRE_ARRAY
|
|
],
|
|
};
|
|
}
|
|
}
|
|
|