diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-05 14:51:32 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-05 14:51:32 +0900 |
| commit | a851d86b4546dae5fec9e0f046c29d2f2bedb857 (patch) | |
| tree | fc8ff76b1f3f3d098cb5e6c6a358028a245d8eda /crates/shirabe/src | |
| parent | 23860a736f539064a64284a673a1b0e69d24e980 (diff) | |
| download | php-shirabe-a851d86b4546dae5fec9e0f046c29d2f2bedb857.tar.gz php-shirabe-a851d86b4546dae5fec9e0f046c29d2f2bedb857.tar.zst php-shirabe-a851d86b4546dae5fec9e0f046c29d2f2bedb857.zip | |
feat(remote-filesystem): support file:// URLs in get_remote_contents
get_remote_contents was a full stub always returning None, so any
file:// download raised a TransportException. Read local files
directly for the file scheme, mirroring PHP's file_get_contents
transparently handling the file:// stream wrapper. Also fixes
file_get_contents5 to strip the file:// prefix like the 0-arg
variant already did.
Diffstat (limited to 'crates/shirabe/src')
| -rw-r--r-- | crates/shirabe/src/util/remote_filesystem.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index aa42f6b..fc61b16 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -17,10 +17,10 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ PHP_URL_HOST, PHP_URL_PATH, PHP_URL_SCHEME, PHP_VERSION_ID, PhpMixed, RuntimeException, STREAM_NOTIFY_FAILURE, STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_PROGRESS, - array_replace_recursive, base64_encode, explode, extension_loaded, file_put_contents, - filter_var_boolean, gethostbyname, http_clear_last_response_headers, - http_get_last_response_headers, ini_get, json_decode, parse_url, preg_quote, strpos, - strtolower, strtr, substr, trim, zlib_decode, + array_replace_recursive, base64_encode, explode, extension_loaded, file_get_contents, + file_get_contents5, file_put_contents, filter_var_boolean, gethostbyname, + http_clear_last_response_headers, http_get_last_response_headers, ini_get, json_decode, + parse_url, preg_quote, strpos, strtolower, strtr, substr, trim, zlib_decode, }; /// Result of `RemoteFilesystem::get` — string content, `true` (for copy), or `false`. @@ -699,7 +699,7 @@ impl RemoteFilesystem { fn get_remote_contents( &self, _origin_url: &str, - _file_url: &str, + file_url: &str, _context: &PhpMixed, response_headers: &mut Vec<String>, max_file_size: Option<i64>, @@ -711,9 +711,17 @@ impl RemoteFilesystem { } let mut caught_e: Option<anyhow::Error> = None; - // TODO(phase-c): wrap PHP's `file_get_contents` with stream context and error capture; - // depends on the unmodeled PHP stream-context layer. - let outer: Result<Option<String>, anyhow::Error> = Ok(None); + let outer: Result<Option<String>, anyhow::Error> = if self.scheme == "file" { + Ok(match max_file_size { + Some(max) => file_get_contents5(file_url, false, PhpMixed::Null, 0, Some(max)), + None => file_get_contents(file_url), + }) + } else { + // TODO(phase-c): wrap PHP's `file_get_contents` with stream context and error capture + // for http(s) and other network schemes; depends on the unmodeled PHP stream-context + // layer. + Ok(None) + }; match outer { Ok(v) => result = v, Err(e) => caught_e = Some(e), |
