aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/process
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-25 14:39:00 +0900
committernsfisis <nsfisis@gmail.com>2026-06-25 23:47:47 +0900
commitd0336078c5b63b174e7313d54d973a1832228928 (patch)
treeb0ed23c382e7ffd854fd3afb266a6932002e3335 /crates/shirabe-external-packages/src/symfony/process
parenteebba7ebad103a2f7afe885a25ba2e96efddbd89 (diff)
downloadphp-shirabe-d0336078c5b63b174e7313d54d973a1832228928.tar.gz
php-shirabe-d0336078c5b63b174e7313d54d973a1832228928.tar.zst
php-shirabe-d0336078c5b63b174e7313d54d973a1832228928.zip
feat(external-packages,shim): implement impl todos across components
Port seld/jsonlint JsonParser (+hand-written Lexer), unblocking 10 json_file parse-error tests verified byte-for-byte against PHP. Implement Symfony Finder SplFileInfo, executable finders, String classes (byte/code-point/unicode), ZipArchive shim (via the zip crate), SPDX license validation, and shim date/stream functions. Genuinely-blocked sites (reflection, PHP runtime constants, non-UTF-8 transcoding, recursive PCRE) stay todo!() with reasons. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/process')
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/executable_finder.rs111
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs49
2 files changed, 151 insertions, 9 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
index cfd1bef..a151283 100644
--- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
@@ -1,7 +1,18 @@
//! ref: composer/vendor/symfony/process/ExecutableFinder.php
+use shirabe_php_shim::{self as php, PhpMixed};
+
+const CMD_BUILTINS: &[&str] = &[
+ "assoc", "break", "call", "cd", "chdir", "cls", "color", "copy", "date", "del", "dir", "echo",
+ "endlocal", "erase", "exit", "for", "ftype", "goto", "help", "if", "label", "md", "mkdir",
+ "mklink", "move", "path", "pause", "popd", "prompt", "pushd", "rd", "rem", "ren", "rename",
+ "rmdir", "set", "setlocal", "shift", "start", "time", "title", "type", "ver", "vol",
+];
+
#[derive(Debug)]
-pub struct ExecutableFinder;
+pub struct ExecutableFinder {
+ suffixes: Vec<String>,
+}
impl Default for ExecutableFinder {
fn default() -> Self {
@@ -11,14 +22,102 @@ impl Default for ExecutableFinder {
impl ExecutableFinder {
pub fn new() -> Self {
- todo!()
+ Self { suffixes: vec![] }
}
- pub fn add_suffix(&mut self, _suffix: &str) {
- todo!()
+ /// Replaces default suffixes of executable.
+ pub fn set_suffixes(&mut self, suffixes: Vec<String>) {
+ self.suffixes = suffixes;
}
- pub fn find(&self, _name: &str, _default: Option<&str>, _dirs: &[String]) -> Option<String> {
- todo!()
+ /// Adds new possible suffix to check for executable.
+ pub fn add_suffix(&mut self, suffix: &str) {
+ self.suffixes.push(suffix.to_string());
+ }
+
+ pub fn find(&self, name: &str, default: Option<&str>, extra_dirs: &[String]) -> Option<String> {
+ // windows built-in commands that are present in cmd.exe should not be resolved using PATH as they do not exist as exes
+ if php::DIRECTORY_SEPARATOR == "\\"
+ && CMD_BUILTINS.contains(&php::strtolower(name).as_str())
+ {
+ return Some(name.to_string());
+ }
+
+ let path = php::getenv("PATH")
+ .or_else(|| php::getenv("Path"))
+ .map(|v| v.to_string_lossy().into_owned())
+ .unwrap_or_default();
+ let mut dirs = php::explode(php::PATH_SEPARATOR, &path);
+ dirs.extend_from_slice(extra_dirs);
+
+ let mut suffixes: Vec<String> = vec![];
+ if php::DIRECTORY_SEPARATOR == "\\" {
+ let path_ext = php::getenv("PATHEXT").map(|v| v.to_string_lossy().into_owned());
+ suffixes = self.suffixes.clone();
+ let exts = match path_ext {
+ Some(ref ext) if !ext.is_empty() => php::explode(php::PATH_SEPARATOR, ext),
+ _ => vec![
+ ".exe".to_string(),
+ ".bat".to_string(),
+ ".cmd".to_string(),
+ ".com".to_string(),
+ ],
+ };
+ suffixes.extend(exts);
+ }
+ suffixes = if !php::pathinfo(PhpMixed::String(name.to_string()), php::PATHINFO_EXTENSION)
+ .as_string()
+ .unwrap_or("")
+ .is_empty()
+ {
+ let mut s = vec![String::new()];
+ s.extend(suffixes);
+ s
+ } else {
+ suffixes.push(String::new());
+ suffixes
+ };
+ for suffix in &suffixes {
+ for dir in &dirs {
+ let dir = if dir.is_empty() { "." } else { dir.as_str() };
+ let file = format!("{dir}{}{name}{suffix}", php::DIRECTORY_SEPARATOR);
+ if php::is_file(&file)
+ && (php::DIRECTORY_SEPARATOR == "\\" || php::is_executable(&file))
+ {
+ return Some(file);
+ }
+
+ if !php::is_dir(dir)
+ && php::basename(dir) == format!("{name}{suffix}")
+ && php::is_executable(dir)
+ {
+ return Some(dir.to_string());
+ }
+ }
+ }
+
+ if php::DIRECTORY_SEPARATOR == "\\"
+ || name.len() != php::strcspn(name, &format!("/{}", php::DIRECTORY_SEPARATOR))
+ {
+ return default.map(ToString::to_string);
+ }
+
+ let exec_result = php::exec(
+ &format!("command -v -- {}", php::escapeshellarg(name)),
+ None,
+ None,
+ )
+ .unwrap_or_default();
+
+ let executable_path = php::substr(
+ &exec_result,
+ 0,
+ php::strpos(&exec_result, php::PHP_EOL).map(|i| i as i64),
+ );
+ if !executable_path.is_empty() && php::is_executable(&executable_path) {
+ return Some(executable_path);
+ }
+
+ default.map(ToString::to_string)
}
}
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 65eae30..9d04c5e 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
@@ -1,7 +1,12 @@
//! ref: composer/vendor/symfony/process/PhpExecutableFinder.php
+use super::executable_finder::ExecutableFinder;
+use shirabe_php_shim::{self as php};
+
#[derive(Debug)]
-pub struct PhpExecutableFinder;
+pub struct PhpExecutableFinder {
+ executable_finder: ExecutableFinder,
+}
impl Default for PhpExecutableFinder {
fn default() -> Self {
@@ -11,14 +16,52 @@ impl Default for PhpExecutableFinder {
impl PhpExecutableFinder {
pub fn new() -> Self {
- todo!()
+ Self {
+ executable_finder: ExecutableFinder::new(),
+ }
}
- pub fn find(&self, _include_args: bool) -> Option<String> {
+ /// Finds The PHP executable.
+ pub fn find(&self, include_args: bool) -> Option<String> {
+ if let Some(php) = php::getenv("PHP_BINARY").filter(|v| !v.is_empty()) {
+ let mut php = php.to_string_lossy().into_owned();
+ if !php::is_executable(&php) {
+ match self.executable_finder.find(&php, None, &[]) {
+ Some(found) => php = found,
+ None => return None,
+ }
+ }
+
+ if php::is_dir(&php) {
+ return None;
+ }
+
+ return Some(php);
+ }
+
+ let args = self.find_arguments();
+ let _args = if include_args && !args.is_empty() {
+ format!(" {}", args.join(" "))
+ } else {
+ String::new()
+ };
+
+ // 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!()
}
+ /// 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!()
}
}