diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:19:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 06:19:30 +0900 |
| commit | 880a5eaad9dcdfd31563385f11ba1f63d38cfd14 (patch) | |
| tree | 6f9de7b2b8331628a74287112711f65ae3eddc52 /crates/shirabe/src/autoload/class_loader.rs | |
| parent | f3d60c7836da0d50d59a22cfd6e4692e3dc75581 (diff) | |
| download | php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.tar.gz php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.tar.zst php-shirabe-880a5eaad9dcdfd31563385f11ba1f63d38cfd14.zip | |
refactor(php-shim): use std::path::MAIN_SEPARATOR over a shim constant
The shim's DIRECTORY_SEPARATOR was hardcoded to "/", so every ported
`'\\' === DIRECTORY_SEPARATOR` check compared against a constant that
does not track the target platform. std::path::MAIN_SEPARATOR and
MAIN_SEPARATOR_STR carry the same meaning as PHP's constant and resolve
per platform, so the Windows branches are selected on Windows targets.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/autoload/class_loader.rs')
| -rw-r--r-- | crates/shirabe/src/autoload/class_loader.rs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/crates/shirabe/src/autoload/class_loader.rs b/crates/shirabe/src/autoload/class_loader.rs index 47b6ee4c..21473fb9 100644 --- a/crates/shirabe/src/autoload/class_loader.rs +++ b/crates/shirabe/src/autoload/class_loader.rs @@ -2,9 +2,8 @@ use indexmap::IndexMap; use shirabe_php_shim::{ - DIRECTORY_SEPARATOR, InvalidArgumentException, PhpMixed, defined, file_exists, include_file, - spl_autoload_register, spl_autoload_unregister, stream_resolve_include_path, strlen, strpos, - strrpos, strtr, substr, + InvalidArgumentException, PhpMixed, defined, file_exists, include_file, spl_autoload_register, + spl_autoload_unregister, stream_resolve_include_path, strlen, strpos, strrpos, strtr, substr, }; use std::sync::{LazyLock, Mutex}; @@ -366,7 +365,11 @@ impl ClassLoader { fn find_file_with_extension(&self, class: &str, ext: &str) -> Option<String> { // PSR-4 lookup - let logical_path_psr4 = format!("{}{}", strtr(class, "\\", DIRECTORY_SEPARATOR), ext); + let logical_path_psr4 = format!( + "{}{}", + strtr(class, "\\", std::path::MAIN_SEPARATOR_STR), + ext + ); let first = class.chars().next().unwrap_or('\0').to_string(); if self.prefix_lengths_psr4.contains_key(&first) { @@ -382,7 +385,7 @@ impl ClassLoader { if let Some(dirs) = self.prefix_dirs_psr4.get(&search) { let path_end = format!( "{}{}", - DIRECTORY_SEPARATOR, + std::path::MAIN_SEPARATOR, substr(&logical_path_psr4, (last_pos + 1) as i64, None) ); for dir in dirs { @@ -397,7 +400,7 @@ impl ClassLoader { // PSR-4 fallback dirs for dir in &self.fallback_dirs_psr4 { - let file = format!("{}{}{}", dir, DIRECTORY_SEPARATOR, logical_path_psr4); + let file = format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr4); if file_exists(&file) { return Some(file); } @@ -413,19 +416,24 @@ impl ClassLoader { strtr( &substr(&logical_path_psr4, (pos + 1) as i64, None), "_", - DIRECTORY_SEPARATOR + std::path::MAIN_SEPARATOR_STR, ) ); } else { // PEAR-like class name - logical_path_psr0 = format!("{}{}", strtr(class, "_", DIRECTORY_SEPARATOR), ext); + logical_path_psr0 = format!( + "{}{}", + strtr(class, "_", std::path::MAIN_SEPARATOR_STR), + ext + ); } if let Some(prefixes) = self.prefixes_psr0.get(&first) { for (prefix, dirs) in prefixes { if Some(0) == strpos(class, prefix) { for dir in dirs { - let file = format!("{}{}{}", dir, DIRECTORY_SEPARATOR, logical_path_psr0); + let file = + format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr0); if file_exists(&file) { return Some(file); } @@ -436,7 +444,7 @@ impl ClassLoader { // PSR-0 fallback dirs for dir in &self.fallback_dirs_psr0 { - let file = format!("{}{}{}", dir, DIRECTORY_SEPARATOR, logical_path_psr0); + let file = format!("{}{}{}", dir, std::path::MAIN_SEPARATOR, logical_path_psr0); if file_exists(&file) { return Some(file); } |
