From f05e1a55cf0d44e9611e06a3d7b4fccdcb90ce7b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 17:42:32 +0900 Subject: 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) --- crates/shirabe/src/command/diagnose_command.rs | 40 +++++++++----------------- crates/shirabe/src/command/home_command.rs | 4 +-- crates/shirabe/src/command/init_command.rs | 17 ++++------- 3 files changed, 21 insertions(+), 40 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index 43e878d..4b1c241 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -10,14 +10,14 @@ use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_external_packages::symfony::process::ExecutableFinder; use shirabe_php_shim::{ - CURL_HTTP_VERSION_2_0, CURL_VERSION_HTTP2, CURL_VERSION_HTTP3, CURL_VERSION_ZSTD, - FILTER_VALIDATE_BOOLEAN, INFO_GENERAL, InvalidArgumentException, OPENSSL_VERSION_NUMBER, - OPENSSL_VERSION_TEXT, PHP_BINARY, PHP_EOL, PHP_VERSION, PHP_VERSION_ID, - PHP_WINDOWS_VERSION_BUILD, PhpMixed, RuntimeException, count, curl_version, defined, - disk_free_space, extension_loaded, file_exists, filter_var, function_exists, get_class, - get_class_err, hash, implode, ini_get, ioncube_loader_iversion, ioncube_loader_version, - is_array, is_string, key, ob_get_clean, ob_start, phpinfo, reset, rtrim, sprintf, str_contains, - str_replace, str_starts_with, strpos, strstr, strtolower, trim, version_compare, + CURL_HTTP_VERSION_2_0, CURL_VERSION_HTTP2, CURL_VERSION_HTTP3, CURL_VERSION_ZSTD, INFO_GENERAL, + InvalidArgumentException, OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_TEXT, PHP_BINARY, PHP_EOL, + PHP_VERSION, PHP_VERSION_ID, PHP_WINDOWS_VERSION_BUILD, PhpMixed, RuntimeException, count, + curl_version, defined, disk_free_space, extension_loaded, file_exists, filter_var_boolean, + function_exists, get_class, get_class_err, hash, implode, ini_get, ioncube_loader_iversion, + ioncube_loader_version, is_array, is_string, key, ob_get_clean, ob_start, phpinfo, reset, + rtrim, sprintf, str_contains, str_replace, str_starts_with, strpos, strstr, strtolower, trim, + version_compare, }; use std::cell::RefCell; use std::rc::Rc; @@ -1177,10 +1177,7 @@ impl DiagnoseCommand { errors.insert("iconv_mbstring".to_string(), PhpMixed::Bool(true)); } - if !filter_var( - ini_get("allow_url_fopen").as_deref().unwrap_or(""), - FILTER_VALIDATE_BOOLEAN, - ) { + if !filter_var_boolean(ini_get("allow_url_fopen").as_deref().unwrap_or("")) { errors.insert("allow_url_fopen".to_string(), PhpMixed::Bool(true)); } @@ -1205,10 +1202,7 @@ impl DiagnoseCommand { if !defined("HHVM_VERSION") && !extension_loaded("apcu") - && filter_var( - ini_get("apc.enable_cli").as_deref().unwrap_or(""), - FILTER_VALIDATE_BOOLEAN, - ) + && filter_var_boolean(ini_get("apc.enable_cli").as_deref().unwrap_or("")) { warnings.insert("apc_cli".to_string(), PhpMixed::Bool(true)); } @@ -1243,10 +1237,7 @@ impl DiagnoseCommand { } } - if filter_var( - ini_get("xdebug.profiler_enabled").as_deref().unwrap_or(""), - FILTER_VALIDATE_BOOLEAN, - ) { + if filter_var_boolean(ini_get("xdebug.profiler_enabled").as_deref().unwrap_or("")) { warnings.insert("xdebug_profile".to_string(), PhpMixed::Bool(true)); } else if XdebugHandler::is_xdebug_active() { warnings.insert("xdebug_loaded".to_string(), PhpMixed::Bool(true)); @@ -1265,13 +1256,8 @@ impl DiagnoseCommand { } if extension_loaded("uopz") - && !(filter_var( - ini_get("uopz.disable").as_deref().unwrap_or(""), - FILTER_VALIDATE_BOOLEAN, - ) || filter_var( - ini_get("uopz.exit").as_deref().unwrap_or(""), - FILTER_VALIDATE_BOOLEAN, - )) + && !(filter_var_boolean(ini_get("uopz.disable").as_deref().unwrap_or("")) + || filter_var_boolean(ini_get("uopz.exit").as_deref().unwrap_or(""))) { warnings.insert("uopz".to_string(), PhpMixed::Bool(true)); } diff --git a/crates/shirabe/src/command/home_command.rs b/crates/shirabe/src/command/home_command.rs index 1620205..5b05815 100644 --- a/crates/shirabe/src/command/home_command.rs +++ b/crates/shirabe/src/command/home_command.rs @@ -6,7 +6,7 @@ use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::PhpMixed; -use shirabe_php_shim::{FILTER_VALIDATE_URL, filter_var}; +use shirabe_php_shim::filter_var_url; use std::cell::RefCell; use std::rc::Rc; @@ -73,7 +73,7 @@ impl HomeCommand { Some(u) => u, }; - if !filter_var(&url, FILTER_VALIDATE_URL) { + if !filter_var_url(&url) { return false; } diff --git a/crates/shirabe/src/command/init_command.rs b/crates/shirabe/src/command/init_command.rs index f58952e..22cd75b 100644 --- a/crates/shirabe/src/command/init_command.rs +++ b/crates/shirabe/src/command/init_command.rs @@ -12,11 +12,11 @@ use shirabe_external_packages::symfony::console::input::ArrayInput; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; use shirabe_php_shim::{ - FILE_IGNORE_NEW_LINES, FILTER_VALIDATE_EMAIL, InvalidArgumentException, PHP_EOL, PhpMixed, - array_filter, array_flip, array_flip_strings, array_intersect_key, array_keys, array_map, - basename, empty, explode, file, file_exists, file_get_contents, file_put_contents, - function_exists, get_current_user, implode, is_dir, is_string, preg_quote, realpath, - server_get, sprintf, str_replace, strpos, strtolower, trim, ucwords, + FILE_IGNORE_NEW_LINES, InvalidArgumentException, PHP_EOL, PhpMixed, array_filter, array_flip, + array_flip_strings, array_intersect_key, array_keys, array_map, basename, empty, explode, file, + file_exists, file_get_contents, file_put_contents, function_exists, get_current_user, implode, + is_dir, is_string, preg_quote, realpath, server_get, sprintf, str_replace, strpos, strtolower, + trim, ucwords, }; use std::cell::RefCell; use std::rc::Rc; @@ -1076,12 +1076,7 @@ impl InitCommand { } pub(crate) fn is_valid_email(&self, email: &str) -> bool { - // assume it's valid if we can't validate it - if !function_exists("filter_var") { - return true; - } - - shirabe_php_shim::filter_var(email, FILTER_VALIDATE_EMAIL) + shirabe_php_shim::filter_var_email(email) } fn update_dependencies(&self, output: std::rc::Rc>) { -- cgit v1.3.1