diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-09 11:14:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-09 11:14:42 +0900 |
| commit | 446f719f6c34453f027d5ccdbf81b16e63f4c982 (patch) | |
| tree | 9c0443adbb99da5891a81d0131fc414d9a04c8ef /crates/shirabe-symfony-process/src/php_executable_finder.rs | |
| parent | 880ba0fd1d05faf98588cc326b3d9fbe625ebf2b (diff) | |
| download | php-shirabe-446f719f6c34453f027d5ccdbf81b16e63f4c982.tar.gz php-shirabe-446f719f6c34453f027d5ccdbf81b16e63f4c982.tar.zst php-shirabe-446f719f6c34453f027d5ccdbf81b16e63f4c982.zip | |
refactor(symfony-process): extract symfony/process into the shirabe-symfony-process crate
Move `Symfony\Component\Process` out of shirabe-external-packages and
into its own crate, so the path is `shirabe_symfony_process::Process`
instead of `shirabe_external_packages::symfony::process::Process`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-symfony-process/src/php_executable_finder.rs')
| -rw-r--r-- | crates/shirabe-symfony-process/src/php_executable_finder.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/crates/shirabe-symfony-process/src/php_executable_finder.rs b/crates/shirabe-symfony-process/src/php_executable_finder.rs new file mode 100644 index 00000000..e8661866 --- /dev/null +++ b/crates/shirabe-symfony-process/src/php_executable_finder.rs @@ -0,0 +1,70 @@ +//! ref: composer/vendor/symfony/process/PhpExecutableFinder.php + +use super::executable_finder::ExecutableFinder; + +#[derive(Debug)] +pub struct PhpExecutableFinder { + executable_finder: ExecutableFinder, +} + +impl Default for PhpExecutableFinder { + fn default() -> Self { + Self::new() + } +} + +impl PhpExecutableFinder { + pub fn new() -> Self { + Self { + executable_finder: ExecutableFinder::new(), + } + } + + /// Finds The PHP executable. + pub fn find(&self, _include_args: bool) -> Option<String> { + if let Some(php) = shirabe_php_shim::getenv("PHP_BINARY").filter(|v| !v.is_empty()) { + let mut php = php.to_string_lossy().into_owned(); + if !shirabe_php_shim::is_executable(&php) { + match self.executable_finder.find(&php, None, &[]) { + Some(found) => php = found, + None => return None, + } + } + + if shirabe_php_shim::is_dir(&php) { + return None; + } + + return Some(php); + } + + // The original `\PHP_BINARY && \PHP_SAPI` branch describes the running PHP interpreter. + // These constants cannot be obtained in Rust, the branch is skipped here. + + if let Some(php) = shirabe_php_shim::getenv("PHP_PATH").filter(|v| !v.is_empty()) { + let php = php.to_string_lossy().into_owned(); + if !shirabe_php_shim::is_executable(&php) || shirabe_php_shim::is_dir(&php) { + return None; + } + + return Some(php); + } + + if let Some(php) = shirabe_php_shim::getenv("PHP_PEAR_PHP_BIN").filter(|v| !v.is_empty()) { + let php = php.to_string_lossy().into_owned(); + if shirabe_php_shim::is_executable(&php) && !shirabe_php_shim::is_dir(&php) { + return Some(php); + } + } + + // Even if `\PHP_BINDIR` is unavailable, searching `$PATH` should be performed. + self.executable_finder.find("php", None, &[]) + } + + /// Finds the PHP executable arguments. + pub fn find_arguments(&self) -> Vec<String> { + // If PHP_SAPI is not "phpdbg", returns an empty array. In Rust, PHP_SAPI is always "cli", + // so always returns an empty array. + vec![] + } +} |
