aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-03 20:10:17 +0900
committernsfisis <nsfisis@gmail.com>2026-06-03 20:10:17 +0900
commiteacd2abcc53659a9fa20b1274a30ac4d9ad8bdb6 (patch)
tree22affc2abef924f4f8bbe7ccec920689c9c01783 /crates
parent26daafaae3713cd94ce32354e6404d95e06c568c (diff)
downloadphp-shirabe-eacd2abcc53659a9fa20b1274a30ac4d9ad8bdb6.tar.gz
php-shirabe-eacd2abcc53659a9fa20b1274a30ac4d9ad8bdb6.tar.zst
php-shirabe-eacd2abcc53659a9fa20b1274a30ac4d9ad8bdb6.zip
feat(php-shim): align fwrite/touch2/PHP_OS_FAMILY/PHP_URL_SCHEME with PHP
Adjust fwrite to return int|false equivalent (Option<i64>), add touch2 with mtime, implement PHP_OS_FAMILY via std::env::consts::OS, and swap the PHP_URL_HOST placeholders for the now-available PHP_URL_SCHEME. Wire these into locker, filesystem, platform, and remote_filesystem. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-php-shim/src/lib.rs19
-rw-r--r--crates/shirabe/src/package/locker.rs6
-rw-r--r--crates/shirabe/src/util/filesystem.rs6
-rw-r--r--crates/shirabe/src/util/platform.rs11
-rw-r--r--crates/shirabe/src/util/remote_filesystem.rs9
5 files changed, 30 insertions, 21 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index b265111..cb487a2 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -536,7 +536,7 @@ pub fn fopen(_file: &str, _mode: &str) -> PhpMixed {
todo!()
}
-pub fn fwrite(_file: PhpMixed, _data: &str, _length: i64) {
+pub fn fwrite(_file: PhpMixed, _data: &str, _length: i64) -> Option<i64> {
todo!()
}
@@ -863,6 +863,23 @@ pub fn touch(_path: &str) -> bool {
todo!()
}
+pub fn touch2(_path: &str, _mtime: i64) -> bool {
+ todo!()
+}
+
+/// PHP `PHP_OS_FAMILY` constant: the family of the host OS.
+/// One of "Windows", "BSD", "Darwin", "Solaris", "Linux", "Unknown".
+pub fn php_os_family() -> &'static str {
+ match std::env::consts::OS {
+ "linux" | "android" => "Linux",
+ "macos" | "ios" => "Darwin",
+ "windows" => "Windows",
+ "freebsd" | "dragonfly" | "netbsd" | "openbsd" => "BSD",
+ "solaris" | "illumos" => "Solaris",
+ _ => "Unknown",
+ }
+}
+
pub fn chmod(_path: &str, _mode: u32) -> bool {
todo!()
}
diff --git a/crates/shirabe/src/package/locker.rs b/crates/shirabe/src/package/locker.rs
index 9e36255..3b5db05 100644
--- a/crates/shirabe/src/package/locker.rs
+++ b/crates/shirabe/src/package/locker.rs
@@ -8,7 +8,7 @@ use shirabe_external_packages::seld::json_lint::ParsingException;
use shirabe_php_shim::{
DATE_RFC3339, LogicException, PhpMixed, RuntimeException, array_intersect, array_keys,
array_map, array_merge, call_user_func, file_get_contents, filemtime, function_exists, hash,
- in_array, is_array, is_int, ksort, realpath, reset_first, sprintf, strcmp, strtolower, touch,
+ in_array, is_array, is_int, ksort, realpath, reset_first, sprintf, strcmp, strtolower, touch2,
trim, usort,
};
@@ -709,9 +709,7 @@ impl Locker {
self.virtual_file_written = false;
if let Some(mtime) = lock_mtime {
if is_int(&PhpMixed::Int(mtime)) {
- // TODO(phase-b): touch() in php-shim doesn't accept mtime; need touch2
- let _ = mtime;
- let _ = touch(&self.lock_file.get_path());
+ let _ = touch2(&self.lock_file.get_path(), mtime);
}
}
Ok(())
diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs
index ef3d307..c7f3583 100644
--- a/crates/shirabe/src/util/filesystem.rs
+++ b/crates/shirabe/src/util/filesystem.rs
@@ -405,9 +405,9 @@ impl Filesystem {
while !feof(source_handle.clone()) {
let chunk =
fread(source_handle.clone(), 1024 * 1024).unwrap_or_default();
- // TODO(phase-b): PHP fwrite returns int|false; shim currently returns ();
- // assume success here.
- fwrite(target_handle.clone(), &chunk, chunk.len() as i64);
+ if fwrite(target_handle.clone(), &chunk, chunk.len() as i64).is_none() {
+ return Err(e.into());
+ }
}
fclose(source_handle);
fclose(target_handle);
diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs
index 541fd56..ecc362c 100644
--- a/crates/shirabe/src/util/platform.rs
+++ b/crates/shirabe/src/util/platform.rs
@@ -7,9 +7,9 @@ use shirabe_external_packages::composer::pcre::Preg;
use shirabe_php_shim::{
PhpMixed, RuntimeException, defined, env_contains_key, env_get, env_set, env_unset,
file_exists, file_get_contents, fopen, fstat, function_exists, getcwd, getenv, in_array,
- ini_get, is_array, is_readable, mb_strlen, posix_geteuid, posix_getpwuid, posix_getuid,
- posix_isatty, putenv, realpath, server_argv, server_contains_key, server_get, server_set,
- server_unset, stream_isatty, stripos, strlen, strtoupper, substr, usleep,
+ ini_get, is_array, is_readable, mb_strlen, php_os_family, posix_geteuid, posix_getpwuid,
+ posix_getuid, posix_isatty, putenv, realpath, server_argv, server_contains_key, server_get,
+ server_set, server_unset, stream_isatty, stripos, strlen, strtoupper, substr, usleep,
};
use crate::util::ProcessExecutor;
@@ -397,10 +397,7 @@ impl Platform {
return true;
}
- if defined("PHP_OS_FAMILY")
- // TODO(phase-b): PHP_OS_FAMILY constant comparison
- && true
- {
+ if php_os_family() == "Linux" {
let mut process = ProcessExecutor::new(None);
// TODO(phase-b): inner Result for catch(\Exception); use anyhow::Result<Result<_, _>>
let mut output = String::new();
diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs
index 22f5ea2..2773300 100644
--- a/crates/shirabe/src/util/remote_filesystem.rs
+++ b/crates/shirabe/src/util/remote_filesystem.rs
@@ -4,7 +4,7 @@ use indexmap::IndexMap;
use shirabe_external_packages::composer::pcre::{CaptureKey, Preg};
use shirabe_php_shim::{
- FILTER_VALIDATE_BOOLEAN, PHP_URL_HOST, PHP_URL_PATH, PHP_VERSION_ID, PhpMixed,
+ FILTER_VALIDATE_BOOLEAN, 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, gethostbyname, http_clear_last_response_headers, http_get_last_response_headers,
@@ -177,8 +177,7 @@ impl RemoteFilesystem {
file_name: Option<String>,
progress: bool,
) -> anyhow::Result<GetResult> {
- // TODO(phase-b): PHP_URL_SCHEME constant isn't yet in the shim; PHP_URL_HOST stands in.
- self.scheme = parse_url(&strtr(file_url, "\\", "/"), PHP_URL_HOST)
+ self.scheme = parse_url(&strtr(file_url, "\\", "/"), PHP_URL_SCHEME)
.as_string()
.unwrap_or("")
.to_string();
@@ -928,12 +927,10 @@ impl RemoteFilesystem {
) -> anyhow::Result<Option<String>> {
let mut target_url: Option<String> = None;
if let Some(location_header) = Response::find_header_value(response_headers, "location") {
- // TODO(phase-b): use PHP_URL_SCHEME once available to detect absolute URLs.
- if !parse_url(&location_header, PHP_URL_HOST)
+ if !parse_url(&location_header, PHP_URL_SCHEME)
.as_string()
.unwrap_or("")
.is_empty()
- && location_header.contains("://")
{
target_url = Some(location_header);
} else if parse_url(&location_header, PHP_URL_HOST)