From 7fd7df848cdbbd8792b0043799018d51408458fc Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 2 Jul 2026 05:12:39 +0900 Subject: feat(php-rpc): implement Runtime::has_constant/get_constant via php-rpc Runtime::hasConstant/getConstant need a real PHP interpreter's defined()/ constant() to answer platform requirement checks (e.g. PHP_ZTS, PHP_INT_SIZE), which the shim can't provide since Rust constants aren't queryable by string. Extend shirabe-php-rpc's protocol to carry one string argument and return the full PHP scalar range, add defined/constant dispatch entries to the worker, and wire Runtime and get_php_version/get_php_binary onto them. --- crates/shirabe-php-rpc/php/worker.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'crates/shirabe-php-rpc/php/worker.php') diff --git a/crates/shirabe-php-rpc/php/worker.php b/crates/shirabe-php-rpc/php/worker.php index 214817a..58ba973 100644 --- a/crates/shirabe-php-rpc/php/worker.php +++ b/crates/shirabe-php-rpc/php/worker.php @@ -7,8 +7,8 @@ if ($client === false) { exit(1); } $dispatch = [ - 'get_php_version' => static fn() => PHP_VERSION, - 'get_php_binary' => static fn() => PHP_BINARY, + 'defined' => static fn($name) => defined($name), + 'constant' => static fn($name) => defined($name) ? constant($name) : null, ]; $read_exact = static function ($conn, int $len): ?string { $buf = ''; @@ -31,7 +31,13 @@ while (true) { if ($name === null) { break; } - $result = isset($dispatch[$name]) ? ($dispatch[$name])() : null; + $sep = strpos($name, "\0"); + $arg = null; + if ($sep !== false) { + $arg = substr($name, $sep + 1); + $name = substr($name, 0, $sep); + } + $result = isset($dispatch[$name]) ? ($dispatch[$name])($arg) : null; $payload = serialize($result); fwrite($client, pack('P', strlen($payload)) . $payload); } -- cgit v1.3.1