aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 14:55:32 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 15:08:49 +0900
commitf6dd10ff812c445fe738b0feaf8e84e827ca8f9f (patch)
tree1983147524370eb8bd2b81f2d14001a8f9b227ac /crates
parent8313c66b5b07e7b8af8db8faa044a0b3a1783fa1 (diff)
downloadphp-shirabe-f6dd10ff812c445fe738b0feaf8e84e827ca8f9f.tar.gz
php-shirabe-f6dd10ff812c445fe738b0feaf8e84e827ca8f9f.tar.zst
php-shirabe-f6dd10ff812c445fe738b0feaf8e84e827ca8f9f.zip
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) <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-php-shim/src/lib.rs24
1 files changed, 22 insertions, 2 deletions
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 {