diff options
Diffstat (limited to 'crates/shirabe-php-shim')
| -rw-r--r-- | crates/shirabe-php-shim/src/runtime.rs | 5 | ||||
| -rw-r--r-- | crates/shirabe-php-shim/src/string.rs | 12 |
2 files changed, 5 insertions, 12 deletions
diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs index 2f8b79f1..6b165567 100644 --- a/crates/shirabe-php-shim/src/runtime.rs +++ b/crates/shirabe-php-shim/src/runtime.rs @@ -360,11 +360,6 @@ pub fn call_php_callable(_callback: &PhpMixed, _args: &[PhpMixed]) -> PhpMixed { todo!() } -// The shim does not raise PHP-level errors, so there is never a last error. -pub fn error_get_last() -> Option<IndexMap<String, PhpMixed>> { - None -} - pub fn ini_set(_varname: &str, _value: &str) -> Option<String> { // TODO(php-runtime): ini_set must return the previous value and have its override observed by a // subsequent ini_get; ini_get is currently a static lookup, so overrides cannot be wired up yet. diff --git a/crates/shirabe-php-shim/src/string.rs b/crates/shirabe-php-shim/src/string.rs index 575bc16d..78688eed 100644 --- a/crates/shirabe-php-shim/src/string.rs +++ b/crates/shirabe-php-shim/src/string.rs @@ -846,17 +846,15 @@ pub fn ucfirst(s: &str) -> String { } } -pub fn php_strip_whitespace(path: impl AsRef<std::path::Path>) -> String { +pub fn php_strip_whitespace(path: impl AsRef<std::path::Path>) -> Result<String, std::io::Error> { // PHP `php_strip_whitespace()` tokenizes the source and re-emits it with comments removed and // each run of whitespace collapsed to a single space. There is no PHP tokenizer in the shim, so // this is a hand-written lexer that reproduces the observable effect for the cases the class-map // generator depends on: it preserves single-quoted, double-quoted, backtick and heredoc/nowdoc // string contents verbatim while dropping `//`, `#` and `/* */` comments and squeezing - // whitespace. On any read failure it returns an empty string, mirroring `@php_strip_whitespace`. - let contents = match std::fs::read(path.as_ref()) { - Ok(bytes) => bytes, - Err(_) => return String::new(), - }; + // whitespace. PHP returns an empty string on a read failure and leaves the reason in the warning + // text; this returns the io::Error instead so callers can report it. + let contents = std::fs::read(path.as_ref())?; let b = contents; let n = b.len(); @@ -981,7 +979,7 @@ pub fn php_strip_whitespace(path: impl AsRef<std::path::Path>) -> String { i += 1; } - String::from_utf8_lossy(&out).into_owned() + Ok(String::from_utf8_lossy(&out).into_owned()) } pub fn hexdec(_s: &str) -> i64 { |
