From 596482de82ff32705e85f18c1c9ae784e6cd2c6f Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 9 Aug 2026 11:24:48 +0900 Subject: refactor(xdebug-handler): extract composer/xdebug_handler into the shirabe-xdebug-handler crate Move `Composer\XdebugHandler` out of shirabe-external-packages and into its own crate, so the path is `shirabe_xdebug_handler::XdebugHandler` instead of `shirabe_external_packages::composer::xdebug_handler::XdebugHandler`. Standing alone, the stub no longer sits in a crate that shirabe-php-rpc depends on, so drop the dependency-cycle rationale from the comments that explain why callers reach for shirabe_php_rpc directly. Co-Authored-By: Claude Opus 5 (1M context) --- Cargo.lock | 5 ++++ Cargo.toml | 1 + crates/shirabe-external-packages/src/composer.rs | 3 -- .../src/composer/xdebug_handler.rs | 3 -- .../src/composer/xdebug_handler/xdebug_handler.rs | 34 ---------------------- crates/shirabe-external-packages/src/lib.rs | 2 +- crates/shirabe-xdebug-handler/Cargo.toml | 7 +++++ crates/shirabe-xdebug-handler/src/lib.rs | 3 ++ .../shirabe-xdebug-handler/src/xdebug_handler.rs | 32 ++++++++++++++++++++ crates/shirabe/Cargo.toml | 1 + crates/shirabe/src/command/diagnose_command.rs | 4 +-- crates/shirabe/src/console/application.rs | 2 +- .../shirabe/src/repository/platform_repository.rs | 2 +- crates/shirabe/src/util/ini_helper.rs | 7 ++--- 14 files changed, 57 insertions(+), 49 deletions(-) delete mode 100644 crates/shirabe-external-packages/src/composer.rs delete mode 100644 crates/shirabe-external-packages/src/composer/xdebug_handler.rs delete mode 100644 crates/shirabe-external-packages/src/composer/xdebug_handler/xdebug_handler.rs create mode 100644 crates/shirabe-xdebug-handler/Cargo.toml create mode 100644 crates/shirabe-xdebug-handler/src/lib.rs create mode 100644 crates/shirabe-xdebug-handler/src/xdebug_handler.rs diff --git a/Cargo.lock b/Cargo.lock index 543c1df1..1e56a33a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2111,6 +2111,7 @@ dependencies = [ "shirabe-symfony-filesystem", "shirabe-symfony-finder", "shirabe-symfony-process", + "shirabe-xdebug-handler", "tempfile", "tokio", "tracing", @@ -2289,6 +2290,10 @@ dependencies = [ "shirabe-php-shim", ] +[[package]] +name = "shirabe-xdebug-handler" +version = "0.0.1" + [[package]] name = "shlex" version = "1.3.0" diff --git a/Cargo.toml b/Cargo.toml index 2ed93005..f16de4c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ shirabe-symfony-filesystem = { path = "crates/shirabe-symfony-filesystem" } shirabe-symfony-finder = { path = "crates/shirabe-symfony-finder" } shirabe-symfony-process = { path = "crates/shirabe-symfony-process" } shirabe-symfony-string = { path = "crates/shirabe-symfony-string" } +shirabe-xdebug-handler = { path = "crates/shirabe-xdebug-handler" } anyhow = "1.0.102" async-trait = "0.1.89" base64 = "0.22.1" diff --git a/crates/shirabe-external-packages/src/composer.rs b/crates/shirabe-external-packages/src/composer.rs deleted file mode 100644 index c95f237d..00000000 --- a/crates/shirabe-external-packages/src/composer.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod xdebug_handler; - -pub use xdebug_handler::*; diff --git a/crates/shirabe-external-packages/src/composer/xdebug_handler.rs b/crates/shirabe-external-packages/src/composer/xdebug_handler.rs deleted file mode 100644 index c95f237d..00000000 --- a/crates/shirabe-external-packages/src/composer/xdebug_handler.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod xdebug_handler; - -pub use xdebug_handler::*; diff --git a/crates/shirabe-external-packages/src/composer/xdebug_handler/xdebug_handler.rs b/crates/shirabe-external-packages/src/composer/xdebug_handler/xdebug_handler.rs deleted file mode 100644 index 3bbe9014..00000000 --- a/crates/shirabe-external-packages/src/composer/xdebug_handler/xdebug_handler.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! ref: composer/vendor/composer/xdebug-handler/src/XdebugHandler.php - -#[derive(Debug)] -pub struct XdebugHandler; - -impl XdebugHandler { - pub fn is_xdebug_active() -> bool { - // TODO(php-runtime) - false - } - - pub fn get_skipped_version() -> Option { - // TODO(php-runtime) - // The restart-to-disable-xdebug mechanism is not ported (`is_xdebug_active` is - // hardcoded `false`), so a restart never happens and `self::$skipped` stays at - // its PHP default of `""`. - Some(String::new()) - } - - pub fn get_all_ini_files() -> Vec { - // TODO(php-runtime) - // No XdebugHandler is ever constructed (`self::$name` stays null), because the - // `new XdebugHandler('Composer'); $xdebug->check();` bootstrap in `bin/composer` is not - // ported (see the TODO(phase-c) at the top of shirabe's main.rs), so the - // COMPOSER_ORIGINAL_INIS env-var branch is unreachable here. - // - // shirabe-external-packages cannot depend on shirabe-php-rpc (the reverse dependency - // would cycle, since shirabe-php-rpc already depends on shirabe-external-packages), so - // callers that need the real PHP runtime's ini files (php_ini_loaded_file() / - // php_ini_scanned_files()) query shirabe_php_rpc directly instead of going through this - // stub; see crate::util::ini_helper::IniHelper::get_all. - vec![String::new()] - } -} diff --git a/crates/shirabe-external-packages/src/lib.rs b/crates/shirabe-external-packages/src/lib.rs index 0ee3b91c..8b137891 100644 --- a/crates/shirabe-external-packages/src/lib.rs +++ b/crates/shirabe-external-packages/src/lib.rs @@ -1 +1 @@ -pub mod composer; + diff --git a/crates/shirabe-xdebug-handler/Cargo.toml b/crates/shirabe-xdebug-handler/Cargo.toml new file mode 100644 index 00000000..cd8f42eb --- /dev/null +++ b/crates/shirabe-xdebug-handler/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "shirabe-xdebug-handler" +version.workspace = true +edition.workspace = true + +[lints] +workspace = true diff --git a/crates/shirabe-xdebug-handler/src/lib.rs b/crates/shirabe-xdebug-handler/src/lib.rs new file mode 100644 index 00000000..c95f237d --- /dev/null +++ b/crates/shirabe-xdebug-handler/src/lib.rs @@ -0,0 +1,3 @@ +pub mod xdebug_handler; + +pub use xdebug_handler::*; diff --git a/crates/shirabe-xdebug-handler/src/xdebug_handler.rs b/crates/shirabe-xdebug-handler/src/xdebug_handler.rs new file mode 100644 index 00000000..6ccedc6a --- /dev/null +++ b/crates/shirabe-xdebug-handler/src/xdebug_handler.rs @@ -0,0 +1,32 @@ +//! ref: composer/vendor/composer/xdebug-handler/src/XdebugHandler.php + +#[derive(Debug)] +pub struct XdebugHandler; + +impl XdebugHandler { + pub fn is_xdebug_active() -> bool { + // TODO(php-runtime) + false + } + + pub fn get_skipped_version() -> Option { + // TODO(php-runtime) + // The restart-to-disable-xdebug mechanism is not ported (`is_xdebug_active` is + // hardcoded `false`), so a restart never happens and `self::$skipped` stays at + // its PHP default of `""`. + Some(String::new()) + } + + pub fn get_all_ini_files() -> Vec { + // TODO(php-runtime) + // No XdebugHandler is ever constructed (`self::$name` stays null), because the + // `new XdebugHandler('Composer'); $xdebug->check();` bootstrap in `bin/composer` is not + // ported (see the TODO(phase-c) at the top of shirabe's main.rs), so the + // COMPOSER_ORIGINAL_INIS env-var branch is unreachable here. + // + // Callers that need the real PHP runtime's ini files (php_ini_loaded_file() / + // php_ini_scanned_files()) query shirabe_php_rpc directly instead of going through this + // stub; see IniHelper::get_all in the shirabe crate. + vec![String::new()] + } +} diff --git a/crates/shirabe/Cargo.toml b/crates/shirabe/Cargo.toml index 469b7e32..a2cf1f50 100644 --- a/crates/shirabe/Cargo.toml +++ b/crates/shirabe/Cargo.toml @@ -19,6 +19,7 @@ shirabe-symfony-console.workspace = true shirabe-symfony-filesystem.workspace = true shirabe-symfony-finder.workspace = true shirabe-symfony-process.workspace = true +shirabe-xdebug-handler.workspace = true anyhow.workspace = true async-trait.workspace = true base64.workspace = true diff --git a/crates/shirabe/src/command/diagnose_command.rs b/crates/shirabe/src/command/diagnose_command.rs index eade37fc..2af2acfc 100644 --- a/crates/shirabe/src/command/diagnose_command.rs +++ b/crates/shirabe/src/command/diagnose_command.rs @@ -888,8 +888,8 @@ impl DiagnoseCommand { warnings.insert("xdebug_profile".to_string(), PhpMixed::Bool(true)); } else if diagnostics.xdebug_active { // PHP: XdebugHandler::isXdebugActive(). As with IniHelper::get_all, the port of that - // method in shirabe_external_packages cannot reach the PHP RPC bridge (the dependency - // would cycle), so the real runtime is queried through the diagnose payload instead. + // method in shirabe_xdebug_handler is a stub, so the real runtime is queried through + // the diagnose payload instead. warnings.insert("xdebug_loaded".to_string(), PhpMixed::Bool(true)); } diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index f5c953da..cc456c3c 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -54,7 +54,6 @@ use crate::util::HttpDownloader; use crate::util::Platform; use crate::util::Silencer; use indexmap::IndexMap; -use shirabe_external_packages::composer::xdebug_handler::XdebugHandler; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ LogicException as ShimLogicException, PHP_VERSION, PHP_VERSION_ID, PhpMixed, RuntimeException, @@ -99,6 +98,7 @@ use shirabe_symfony_console::style::style_interface::StyleInterface; use shirabe_symfony_console::style::symfony_style::SymfonyStyle; use shirabe_symfony_console::terminal::Terminal; use shirabe_symfony_process::exception::ProcessTimedOutException; +use shirabe_xdebug_handler::XdebugHandler; /// The PHP `Composer\Console\Application` and `Symfony\Component\Console\Application` are /// flattened into a single struct. Methods that are overridden by subclass and called via diff --git a/crates/shirabe/src/repository/platform_repository.rs b/crates/shirabe/src/repository/platform_repository.rs index 710ba28c..7e123151 100644 --- a/crates/shirabe/src/repository/platform_repository.rs +++ b/crates/shirabe/src/repository/platform_repository.rs @@ -16,7 +16,6 @@ use crate::plugin::plugin_interface::{self}; use crate::repository::ArrayRepository; use crate::repository::RepositoryInterface; use indexmap::IndexMap; -use shirabe_external_packages::composer::xdebug_handler::XdebugHandler; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_rpc::PlatformInfo; use shirabe_php_shim::{ @@ -25,6 +24,7 @@ use shirabe_php_shim::{ str_replace, str_starts_with, strpos, strtolower, var_export, }; use shirabe_semver::constraint::SimpleConstraint; +use shirabe_xdebug_handler::XdebugHandler; use std::sync::{LazyLock, Mutex}; static LAST_SEEN_PLATFORM_PHP: LazyLock>> = LazyLock::new(|| Mutex::new(None)); diff --git a/crates/shirabe/src/util/ini_helper.rs b/crates/shirabe/src/util/ini_helper.rs index c36b9189..4ff9a5e2 100644 --- a/crates/shirabe/src/util/ini_helper.rs +++ b/crates/shirabe/src/util/ini_helper.rs @@ -5,10 +5,9 @@ pub struct IniHelper; impl IniHelper { /// Returns an array of php.ini locations with at least one entry. pub fn get_all() -> Vec { - // PHP: XdebugHandler::getAllIniFiles(). shirabe_external_packages::XdebugHandler's port - // of that method can't reach the PHP RPC bridge (shirabe-php-rpc already depends on - // shirabe-external-packages, so the reverse dependency would cycle), so query the real - // PHP runtime's loaded/scanned ini files here instead. + // PHP: XdebugHandler::getAllIniFiles(). shirabe_xdebug_handler::XdebugHandler's port + // of that method is a stub that returns the PHP default, so query the real PHP + // runtime's loaded/scanned ini files here instead. shirabe_php_rpc::get_all_ini_files() } -- cgit v1.3.1-4-g156e