From f6dd10ff812c445fe738b0feaf8e84e827ca8f9f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 20 Jun 2026 14:55:32 +0900 Subject: feat(php-shim): implement single-component pathinfo Was a todo!() that panicked in Factory::get_lock_file (require, and the file/gzip downloaders). Handles the four PATHINFO_* single-component options by reusing dirname/basename, computing extension and filename around the last dot of the basename. Verified against PHP for eight representative paths, including dotfiles and trailing-dot names. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/lib.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 4b2ea87..c30c434 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -763,8 +763,28 @@ pub fn parse_url_all(_url: &str) -> PhpMixed { todo!() } -pub fn pathinfo(_path: PhpMixed, _option: i64) -> PhpMixed { - todo!() +pub fn pathinfo(path: PhpMixed, option: i64) -> PhpMixed { + let path = path.as_string().unwrap_or(""); + let component = match option { + PATHINFO_DIRNAME => dirname(path), + PATHINFO_BASENAME => basename(path), + PATHINFO_EXTENSION => { + let base = basename(path); + match base.rfind('.') { + Some(index) => base[index + 1..].to_string(), + None => String::new(), + } + } + PATHINFO_FILENAME => { + let base = basename(path); + match base.rfind('.') { + Some(index) => base[..index].to_string(), + None => base, + } + } + _ => unreachable!("pathinfo called with an unsupported single-component option"), + }; + PhpMixed::String(component) } pub fn strtr(str: &str, from: &str, to: &str) -> String { -- cgit v1.3.1