1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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![]
}
}
|