diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-25 14:11:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-25 23:47:47 +0900 |
| commit | eebba7ebad103a2f7afe885a25ba2e96efddbd89 (patch) | |
| tree | b51b16bfffa5f7e361dbad28fdf773aea780ab0a /crates | |
| parent | 2ff25dc307bc7e2d204feb368fc27bae8ce24ede (diff) | |
| download | php-shirabe-eebba7ebad103a2f7afe885a25ba2e96efddbd89.tar.gz php-shirabe-eebba7ebad103a2f7afe885a25ba2e96efddbd89.tar.zst php-shirabe-eebba7ebad103a2f7afe885a25ba2e96efddbd89.zip | |
feat(finder): port Symfony Finder SplFileInfo
Implement the SplFileInfo accessors (pathname/path/filename/basename/extension,
relative path/pathname, is_dir/is_file/is_link, real_path, size) over std and
existing php-shim functions. Extend new() to take relativePath/relativePathname
as in Symfony's constructor (no existing callers).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/finder/spl_file_info.rs | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/finder/spl_file_info.rs b/crates/shirabe-external-packages/src/symfony/finder/spl_file_info.rs index 3ab824f..c1d158d 100644 --- a/crates/shirabe-external-packages/src/symfony/finder/spl_file_info.rs +++ b/crates/shirabe-external-packages/src/symfony/finder/spl_file_info.rs @@ -1,7 +1,12 @@ //! ref: composer/vendor/symfony/finder/SplFileInfo.php #[derive(Debug)] -pub struct SplFileInfo; +pub struct SplFileInfo { + // The path passed to the underlying \SplFileInfo constructor. + pathname: String, + relative_path: String, + relative_pathname: String, +} impl std::fmt::Display for SplFileInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -10,55 +15,70 @@ impl std::fmt::Display for SplFileInfo { } impl SplFileInfo { - pub fn new(_path: &str) -> Self { - todo!() + pub fn new(file: &str, relative_path: &str, relative_pathname: &str) -> Self { + Self { + pathname: file.to_string(), + relative_path: relative_path.to_string(), + relative_pathname: relative_pathname.to_string(), + } } pub fn get_pathname(&self) -> String { - todo!() + self.pathname.clone() } pub fn get_path(&self) -> String { - todo!() + shirabe_php_shim::dirname(&self.pathname) } pub fn get_filename(&self) -> String { - todo!() + shirabe_php_shim::basename(&self.pathname) } - pub fn get_basename(&self, _suffix: Option<&str>) -> String { - todo!() + pub fn get_basename(&self, suffix: Option<&str>) -> String { + match suffix { + Some(suffix) => shirabe_php_shim::basename_with_suffix(&self.pathname, suffix), + None => shirabe_php_shim::basename(&self.pathname), + } } pub fn get_extension(&self) -> String { - todo!() + // \SplFileInfo::getExtension() returns the extension (without the dot), or "" if none. + let base = shirabe_php_shim::basename(&self.pathname); + match base.rfind('.') { + Some(index) => base[index + 1..].to_string(), + None => String::new(), + } } pub fn get_relative_path_name(&self) -> String { - todo!() + self.relative_pathname.clone() } pub fn get_relative_path(&self) -> String { - todo!() + self.relative_path.clone() } pub fn is_dir(&self) -> bool { - todo!() + shirabe_php_shim::is_dir(&self.pathname) } pub fn is_file(&self) -> bool { - todo!() + shirabe_php_shim::is_file(&self.pathname) } pub fn is_link(&self) -> bool { - todo!() + shirabe_php_shim::is_link(&self.pathname) } pub fn get_real_path(&self) -> Option<String> { - todo!() + // \SplFileInfo::getRealPath() returns the canonicalized absolute path, or false on failure. + shirabe_php_shim::realpath(&self.pathname) } pub fn get_size(&self) -> i64 { - todo!() + // \SplFileInfo::getSize() returns the file size in bytes (throws on failure). + // TODO(phase-d): PHP throws a \RuntimeException on stat failure; this returns 0 instead. + shirabe_php_shim::filesize(&self.pathname).unwrap_or(0) } } |
