aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc/src/xdebug.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-php-rpc/src/xdebug.rs')
-rw-r--r--crates/shirabe-php-rpc/src/xdebug.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/shirabe-php-rpc/src/xdebug.rs b/crates/shirabe-php-rpc/src/xdebug.rs
new file mode 100644
index 00000000..6ed048cf
--- /dev/null
+++ b/crates/shirabe-php-rpc/src/xdebug.rs
@@ -0,0 +1,35 @@
+//! ref: composer/vendor/composer/xdebug-handler/src/XdebugHandler.php
+//!
+//! Keeping Xdebug out of the PHP worker, which is where Composer's restart of itself lands in
+//! this port. See `docs/dev/xdebug.md`.
+
+use shirabe_php_shim::getenv;
+
+/// `XdebugHandler::$name.XdebugHandler::SUFFIX_ALLOW`, where the name is the uppercased prefix of
+/// the one construction Composer makes: `new XdebugHandler('Composer')` in `bin/composer`.
+const ALLOW: &str = "COMPOSER_ALLOW_XDEBUG";
+
+/// PHP: `XdebugHandler::isXdebugActive()`. Whether Xdebug is loaded and running in an active mode.
+///
+/// Answered without asking PHP whenever the worker is started with the mode switched off, since
+/// that settles the question for every Xdebug that honours the setting — Xdebug 2, which has no
+/// such setting, is reported inactive while it is not. `diagnose` reports what the worker measures
+/// instead.
+pub fn is_xdebug_active() -> bool {
+ if switches_xdebug_off() {
+ return false;
+ }
+
+ crate::xdebug_active()
+}
+
+/// Whether the worker is started with Xdebug switched off, which is this port's stand-in for
+/// `XdebugHandler::check()` restarting the process. The answer is a property of the environment
+/// alone, so it holds whether or not the worker has been spawned yet.
+pub(crate) fn switches_xdebug_off() -> bool {
+ // PHP: `!((bool) explode('|', getenv($this->envAllowXdebug))[0])`, where the pipe-separated
+ // form is the handoff to a process xdebug-handler restarted. Nothing restarts here, so what
+ // is left is PHP's truthiness of the value.
+ let allow_xdebug = getenv(ALLOW).unwrap_or_default();
+ matches!(allow_xdebug.to_string_lossy().as_ref(), "" | "0")
+}