From dc43cb1c663378130d727d9cee414a6a37433047 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 20 Jun 2026 14:47:31 +0900 Subject: feat(php-shim): implement dirname() Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'crates/shirabe-php-shim') diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 609d320..362e20f 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -1053,8 +1053,17 @@ pub fn json_encode(_value: &T) -> Option { todo!() } -pub fn dirname(_path: &str) -> String { - todo!() +pub fn dirname(path: &str) -> String { + if path.is_empty() { + return String::new(); + } + match std::path::Path::new(path).parent() { + // No parent: the root itself, or a path made up solely of slashes. + None => "/".to_string(), + // Path::parent yields an empty path where PHP's dirname returns ".". + Some(parent) if parent.as_os_str().is_empty() => ".".to_string(), + Some(parent) => parent.to_str().expect("input was valid UTF-8").to_string(), + } } pub fn stream_get_contents(_stream: PhpMixed) -> Option { -- cgit v1.3.1