diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-20 14:47:31 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-20 15:08:49 +0900 |
| commit | dc43cb1c663378130d727d9cee414a6a37433047 (patch) | |
| tree | 73959dd1b293d42caa45239914d1c22cc67fafa8 /crates/shirabe-php-shim/src | |
| parent | c854041bfca63f39ace6f0c01892e81889f90bb3 (diff) | |
| download | php-shirabe-dc43cb1c663378130d727d9cee414a6a37433047.tar.gz php-shirabe-dc43cb1c663378130d727d9cee414a6a37433047.tar.zst php-shirabe-dc43cb1c663378130d727d9cee414a6a37433047.zip | |
feat(php-shim): implement dirname()
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src')
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 13 |
1 files changed, 11 insertions, 2 deletions
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<T: serde::Serialize + ?Sized>(_value: &T) -> Option<String> { 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<String> { |
