From 8d6dbf51af859ad0017ed8d1358824d9386d48c8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 17 May 2026 03:02:18 +0900 Subject: fix(php-shim): resolve duplicate definitions and compile errors - Remove duplicate function/constant definitions that were added during porting (strpos, str_contains, str_starts_with, is_scalar, strlen, substr, strtoupper, str_replace, sprintf, array_keys, str_ends_with, is_int, array_values, is_object, is_numeric, PHP_EOL, FILTER_VALIDATE_EMAIL, PHP_VERSION_ID) - Replace old spl_autoload_register/unregister (PhpMixed args) with typed Box versions - Replace old array_pop/array_shift/array_unshift/array_splice with generic/correctly-typed versions - Replace old trim(chars: &str) with trim(chars: Option<&str>) - Rename array_slice(PhpMixed) to array_slice_mixed to coexist with the typed array_slice(IndexMap) version - Fix chdir return type Result<()> -> anyhow::Result<()> - Add anyhow dependency to shirabe-php-shim --- Cargo.lock | 1 + crates/shirabe-php-shim/Cargo.toml | 1 + crates/shirabe-php-shim/src/lib.rs | 101 +------------------------------------ 3 files changed, 4 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 96c6990..b275c43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,6 +921,7 @@ dependencies = [ name = "shirabe-php-shim" version = "0.0.1" dependencies = [ + "anyhow", "indexmap", "zip", ] diff --git a/crates/shirabe-php-shim/Cargo.toml b/crates/shirabe-php-shim/Cargo.toml index 64bbec3..4104da3 100644 --- a/crates/shirabe-php-shim/Cargo.toml +++ b/crates/shirabe-php-shim/Cargo.toml @@ -4,5 +4,6 @@ version.workspace = true edition.workspace = true [dependencies] +anyhow.workspace = true indexmap.workspace = true zip.workspace = true diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 323d8f8..2c09d7c 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -130,10 +130,6 @@ pub fn is_numeric(value: &PhpMixed) -> bool { todo!() } -pub fn trim(s: &str, chars: &str) -> String { - todo!() -} - pub fn strtotime(time: &str) -> Option { todo!() } @@ -174,18 +170,6 @@ pub fn spl_autoload_functions() -> Vec { todo!() } -pub fn spl_autoload_register(callback: PhpMixed) { - todo!() -} - -pub fn spl_autoload_unregister(callback: PhpMixed) -> bool { - todo!() -} - -pub fn array_pop(array: &mut Vec) -> Option { - todo!() -} - pub fn array_push(array: &mut Vec, value: String) -> i64 { todo!() } @@ -194,15 +178,6 @@ pub fn array_search_in_vec(needle: &str, haystack: &[String]) -> Option { todo!() } -pub fn array_splice( - array: &mut Vec, - offset: usize, - length: usize, - replacement: &[T], -) -> Vec { - todo!() -} - pub fn array_map_str_fn String>(callback: F, array: &[String]) -> Vec { todo!() } @@ -255,7 +230,7 @@ pub fn count_mixed(value: &PhpMixed) -> i64 { todo!() } -pub fn array_slice(value: &PhpMixed, offset: i64, length: Option) -> PhpMixed { +pub fn array_slice_mixed(value: &PhpMixed, offset: i64, length: Option) -> PhpMixed { todo!() } @@ -263,14 +238,6 @@ pub fn array_slice_strs(value: &[String], offset: i64, length: Option) -> V todo!() } -pub fn array_shift(array: &mut Vec) -> T { - todo!() -} - -pub fn array_unshift(array: &mut Vec, value: T) -> i64 { - todo!() -} - pub fn empty(value: &PhpMixed) -> bool { todo!() } @@ -912,7 +879,7 @@ pub fn getcwd() -> Option { todo!() } -pub fn chdir(path: &str) -> Result<()> { +pub fn chdir(path: &str) -> anyhow::Result<()> { todo!() } @@ -1156,7 +1123,6 @@ pub fn get_current_user() -> String { } pub const FILE_IGNORE_NEW_LINES: i64 = 2; -pub const FILTER_VALIDATE_EMAIL: i64 = 274; pub fn array_diff(array1: &[String], array2: &[String]) -> Vec { todo!() @@ -1235,7 +1201,6 @@ pub fn reset(array: &[T]) -> Option { } pub const OPENSSL_ALGO_SHA384: i64 = 9; -pub const PHP_VERSION_ID: i64 = 80100; pub fn array_intersect_key( array1: &IndexMap>, @@ -1378,10 +1343,6 @@ pub fn is_link(path: &str) -> bool { todo!() } -pub fn strpos(haystack: &str, needle: &str) -> Option { - todo!() -} - pub fn str_pad(input: &str, length: usize, pad_string: &str, pad_type: i64) -> String { todo!() } @@ -1394,24 +1355,12 @@ pub fn abs(value: i64) -> i64 { todo!() } -pub fn str_contains(haystack: &str, needle: &str) -> bool { - todo!() -} - -pub fn str_starts_with(haystack: &str, needle: &str) -> bool { - todo!() -} - pub const DATE_ATOM: &str = "Y-m-d\\TH:i:sP"; pub fn ucfirst(s: &str) -> String { todo!() } -pub fn is_scalar(value: &PhpMixed) -> bool { - todo!() -} - pub fn strval(value: &PhpMixed) -> String { todo!() } @@ -1424,18 +1373,6 @@ pub fn mb_strlen(s: &str, encoding: &str) -> i64 { todo!() } -pub fn strlen(s: &str) -> i64 { - todo!() -} - -pub fn substr(s: &str, offset: i64, length: Option) -> String { - todo!() -} - -pub fn strtoupper(s: &str) -> String { - todo!() -} - pub fn stream_isatty(stream: PhpMixed) -> bool { todo!() } @@ -1506,10 +1443,6 @@ pub fn env_contains_key(name: &str) -> bool { todo!() } -pub fn str_replace(search: &str, replace: &str, subject: &str) -> String { - todo!() -} - pub fn trim(s: &str, chars: Option<&str>) -> String { todo!() } @@ -1518,10 +1451,6 @@ pub fn count(value: &PhpMixed) -> i64 { todo!() } -pub fn sprintf(format: &str, args: &[PhpMixed]) -> String { - todo!() -} - pub fn array_shift(array: &mut Vec) -> Option { todo!() } @@ -1570,10 +1499,6 @@ pub fn array_intersect(array1: &[T], array2: &[T]) -> Vec< todo!() } -pub fn array_keys(array: &IndexMap) -> Vec { - todo!() -} - pub fn mkdir(pathname: &str, mode: u32, recursive: bool) -> bool { todo!() } @@ -1674,10 +1599,6 @@ pub fn json_last_error() -> i64 { todo!() } -pub fn str_ends_with(haystack: &str, needle: &str) -> bool { - todo!() -} - pub fn sort(array: &mut Vec) { todo!() } @@ -1703,10 +1624,6 @@ pub fn ksort(array: &mut IndexMap) { todo!() } -pub fn is_int(value: &PhpMixed) -> bool { - todo!() -} - pub fn is_null(value: &PhpMixed) -> bool { todo!() } @@ -1719,10 +1636,6 @@ pub fn array_is_list(array: &PhpMixed) -> bool { todo!() } -pub fn array_values(array: &IndexMap) -> Vec { - todo!() -} - pub fn array_splice( array: &mut Vec, offset: i64, @@ -1751,14 +1664,6 @@ pub fn array_merge_recursive(arrays: Vec) -> PhpMixed { todo!() } -pub fn is_object(value: &PhpMixed) -> bool { - todo!() -} - -pub fn is_numeric(value: &PhpMixed) -> bool { - todo!() -} - pub fn levenshtein(string1: &str, string2: &str) -> i64 { todo!() } @@ -1775,8 +1680,6 @@ pub fn asort(array: &mut IndexMap) { todo!() } -pub const PHP_EOL: &str = "\n"; - pub const PHP_INT_MAX: i64 = i64::MAX; pub const PHP_INT_MIN: i64 = i64::MIN; pub const PHP_INT_SIZE: i64 = 8; -- cgit v1.3.1