aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc/php/worker.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-16 14:18:41 +0900
committernsfisis <nsfisis@gmail.com>2026-08-16 14:35:48 +0900
commitaa2124fe5d0c96078c034a6e4044b7e81acdf692 (patch)
treec9b1597fef555220676f6a5ae554dc81579a4269 /crates/shirabe-php-rpc/php/worker.php
parentb4ab3df2ec85fbe477d7721344a8cd3630b437a1 (diff)
downloadphp-shirabe-aa2124fe5d0c96078c034a6e4044b7e81acdf692.tar.gz
php-shirabe-aa2124fe5d0c96078c034a6e4044b7e81acdf692.tar.zst
php-shirabe-aa2124fe5d0c96078c034a6e4044b7e81acdf692.zip
feat(php-rpc): replay Rust-side env writes into the PHP worker
The worker is a long-lived child holding the environment it was handed at spawn, so `@putenv`, the bin dir the event dispatcher prepends to PATH, and COMPOSER_DEV_MODE never reached the PHP code running in it. The shim now journals every write to the three storages PHP exposes, and the outermost rpc_call replays the entries the worker has not seen yet through __shirabe_sync_env. Replaying the writes rather than pushing a whole snapshot keeps the worker's own $_SERVER entries intact. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-rpc/php/worker.php')
-rw-r--r--crates/shirabe-php-rpc/php/worker.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/crates/shirabe-php-rpc/php/worker.php b/crates/shirabe-php-rpc/php/worker.php
index ce75f9d1..164d73ea 100644
--- a/crates/shirabe-php-rpc/php/worker.php
+++ b/crates/shirabe-php-rpc/php/worker.php
@@ -851,6 +851,40 @@ ShirabeRpcRuntime::$dispatch = [
}
return $value;
},
+ // Replays environment writes the Rust side made after this process was spawned, which only
+ // inherited the environment as it stood then. The three storages PHP exposes are distinct
+ // (docs/dev/env-vars-porting.md), so each write names the one it targets; a null value is an
+ // unset.
+ '__shirabe_sync_env' => static function ($args) {
+ foreach ($args[0] as [$storage, $key, $value]) {
+ switch ($storage) {
+ case 'process':
+ if ($value === null) {
+ putenv($key);
+ } else {
+ putenv("{$key}={$value}");
+ }
+ break;
+ case '_ENV':
+ if ($value === null) {
+ unset($_ENV[$key]);
+ } else {
+ $_ENV[$key] = $value;
+ }
+ break;
+ case '_SERVER':
+ if ($value === null) {
+ unset($_SERVER[$key]);
+ } else {
+ $_SERVER[$key] = $value;
+ }
+ break;
+ default:
+ throw new RuntimeException("__shirabe_sync_env got an unknown storage `{$storage}`");
+ }
+ }
+ return true;
+ },
// For testing only: reads a public property of a P-table entity (PHPUnit asserts like
// `$plugins[0]->version` have no method to call).
'__shirabe_get_property' => static function ($args) {