diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-28 19:35:42 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-28 19:35:42 +0900 |
| commit | 2f825f2ef3401aafaa951967681d52c90d65cbd5 (patch) | |
| tree | a5b03f9ad1786a0839bd49fd914512513c19b02c /crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs | |
| parent | da6dc375d679d302e379214564913aee7ba6f722 (diff) | |
| download | php-shirabe-2f825f2ef3401aafaa951967681d52c90d65cbd5.tar.gz php-shirabe-2f825f2ef3401aafaa951967681d52c90d65cbd5.tar.zst php-shirabe-2f825f2ef3401aafaa951967681d52c90d65cbd5.zip | |
feat(process): implement PhpExecutableFinder::find env fallbacks
Replace the todo!() with the PHP_PATH and PHP_PEAR_PHP_BIN env-var
fallbacks and the trailing PATH-based php lookup. The \PHP_BINARY/
\PHP_SAPI branch and the \PHP_BINDIR seed dir are skipped since the
shim does not model the running PHP interpreter, but the final lookup
still resolves php via PATH with empty extra dirs.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs index 55ace18..e866186 100644 --- a/crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs +++ b/crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs @@ -21,7 +21,7 @@ impl PhpExecutableFinder { } /// Finds The PHP executable. - pub fn find(&self, include_args: bool) -> Option<String> { + 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) { @@ -38,29 +38,33 @@ impl PhpExecutableFinder { return Some(php); } - let args = self.find_arguments(); - let _args = if include_args && !args.is_empty() { - format!(" {}", args.join(" ")) - } else { - String::new() - }; + // The original `\PHP_BINARY && \PHP_SAPI` branch describes the running PHP interpreter. + // These constants cannot be obtained in Rust, the branch is skipped here. - // PHP_BINARY return the current sapi executable - // - // Everything from here on depends on runtime constants describing the *running* PHP - // interpreter (\PHP_BINARY truthiness, \PHP_SAPI, \PHP_BINDIR). The shim does not model a - // current PHP runtime, so the remaining fallbacks (the \PHP_SAPI sapi check, \PHP_PATH, - // \PHP_PEAR_PHP_BIN, \PHP_BINDIR probing and the final php lookup seeded with \PHP_BINDIR) - // cannot be ported faithfully here. - // TODO(php-runtime): port once the shim exposes \PHP_SAPI and \PHP_BINDIR. - todo!() + 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> { - let _arguments: Vec<String> = vec![]; - // TODO(php-runtime): \PHP_SAPI is the SAPI name of the running PHP interpreter; the shim - // does not model a current PHP runtime, so the 'phpdbg' check cannot be ported faithfully. - todo!() + // If PHP_SAPI is not "phpdbg", returns an empty array. In Rust, PHP_SAPI is always "cli", + // so always returns an empty array. + vec![] } } |
