aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-21 17:42:32 +0900
committernsfisis <nsfisis@gmail.com>2026-06-21 17:42:32 +0900
commitf05e1a55cf0d44e9611e06a3d7b4fccdcb90ce7b (patch)
treeb93311ab2473b988051f0285efb7181afe301fe5 /crates/shirabe-php-shim
parent277dc4065d2eb0d6621a6aa56a299a0d2369caf7 (diff)
downloadphp-shirabe-f05e1a55cf0d44e9611e06a3d7b4fccdcb90ce7b.tar.gz
php-shirabe-f05e1a55cf0d44e9611e06a3d7b4fccdcb90ce7b.tar.zst
php-shirabe-f05e1a55cf0d44e9611e06a3d7b4fccdcb90ce7b.zip
refactor(php-shim): split filter_var into per-filter functions
Replace the dispatch-on-constant filter_var() and filter_var_with_options() with dedicated filter_var_boolean/url/email/ip and filter_var_int_with_range, dropping the FILTER_VALIDATE_* constants and updating all call sites. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim')
-rw-r--r--crates/shirabe-php-shim/src/filter.rs56
1 files changed, 24 insertions, 32 deletions
diff --git a/crates/shirabe-php-shim/src/filter.rs b/crates/shirabe-php-shim/src/filter.rs
index a23752b..bd1a6fa 100644
--- a/crates/shirabe-php-shim/src/filter.rs
+++ b/crates/shirabe-php-shim/src/filter.rs
@@ -1,39 +1,31 @@
-use crate::PhpMixed;
-use indexmap::IndexMap;
+// Without FILTER_NULL_ON_FAILURE, php_filter_boolean trims surrounding
+// whitespace, lowercases, and yields true only for "1"/"true"/"on"/"yes";
+// every other input (including the "0"/"false"/"off"/"no"/"" set) yields
+// false.
+pub fn filter_var_boolean(value: &str) -> bool {
+ let trimmed = value.trim_matches([' ', '\t', '\n', '\r', '\0', '\x0B']);
+ matches!(
+ trimmed.to_ascii_lowercase().as_str(),
+ "1" | "true" | "on" | "yes"
+ )
+}
-pub const FILTER_VALIDATE_EMAIL: i64 = 274;
+// TODO(phase-c): PHP's FILTER_VALIDATE_URL parses with php_url_parse_ex and
+// additionally validates the host as a domain/IPv6 literal. reqwest::Url
+// (WHATWG/RFC 3986) is stricter on some inputs and more lenient on others,
+// so this is not a byte-for-byte compatible validator.
+pub fn filter_var_url(value: &str) -> bool {
+ reqwest::Url::parse(value).is_ok()
+}
-pub const FILTER_VALIDATE_BOOLEAN: i64 = 258;
-pub const FILTER_VALIDATE_URL: i64 = 273;
-pub const FILTER_VALIDATE_IP: i64 = 275;
-pub const FILTER_VALIDATE_INT: i64 = 257;
+pub fn filter_var_email(_value: &str) -> bool {
+ todo!()
+}
-pub fn filter_var(value: &str, filter: i64) -> bool {
- match filter {
- // Without FILTER_NULL_ON_FAILURE, php_filter_boolean trims surrounding
- // whitespace, lowercases, and yields true only for "1"/"true"/"on"/"yes";
- // every other input (including the "0"/"false"/"off"/"no"/"" set) yields
- // false.
- FILTER_VALIDATE_BOOLEAN => {
- let trimmed = value.trim_matches([' ', '\t', '\n', '\r', '\0', '\x0B']);
- matches!(
- trimmed.to_ascii_lowercase().as_str(),
- "1" | "true" | "on" | "yes"
- )
- }
- // TODO(phase-c): PHP's FILTER_VALIDATE_URL parses with php_url_parse_ex and
- // additionally validates the host as a domain/IPv6 literal. reqwest::Url
- // (WHATWG/RFC 3986) is stricter on some inputs and more lenient on others,
- // so this is not a byte-for-byte compatible validator.
- FILTER_VALIDATE_URL => reqwest::Url::parse(value).is_ok(),
- _ => todo!(),
- }
+pub fn filter_var_ip(_value: &str) -> bool {
+ todo!()
}
-pub fn filter_var_with_options(
- _value: &str,
- _filter: i64,
- _options: &IndexMap<String, PhpMixed>,
-) -> PhpMixed {
+pub fn filter_var_int_with_range(_value: &str, _min: i64, _max: i64) -> bool {
todo!()
}