aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc/php/worker.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-02 05:12:39 +0900
committernsfisis <nsfisis@gmail.com>2026-07-02 05:12:39 +0900
commit7fd7df848cdbbd8792b0043799018d51408458fc (patch)
tree28aeeef87c3d86a662ed1328b53b1a2865df2c6d /crates/shirabe-php-rpc/php/worker.php
parenteab3a31c5750013c53c0eb02adc976d6757dc9f7 (diff)
downloadphp-shirabe-7fd7df848cdbbd8792b0043799018d51408458fc.tar.gz
php-shirabe-7fd7df848cdbbd8792b0043799018d51408458fc.tar.zst
php-shirabe-7fd7df848cdbbd8792b0043799018d51408458fc.zip
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.
Diffstat (limited to 'crates/shirabe-php-rpc/php/worker.php')
-rw-r--r--crates/shirabe-php-rpc/php/worker.php12
1 files changed, 9 insertions, 3 deletions
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);
}