aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/util/process_executor.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-20 23:37:42 +0900
committernsfisis <nsfisis@gmail.com>2026-06-20 23:37:42 +0900
commit84655bf3a4a21dbbe7aec8e3aee1e661505bbb6d (patch)
tree189f8ce5d7d53246632d5e2419c392d58f06e2b8 /crates/shirabe/src/util/process_executor.rs
parent10840ec1fd7f1140305449fc94175d60998572c1 (diff)
downloadphp-shirabe-84655bf3a4a21dbbe7aec8e3aee1e661505bbb6d.tar.gz
php-shirabe-84655bf3a4a21dbbe7aec8e3aee1e661505bbb6d.tar.zst
php-shirabe-84655bf3a4a21dbbe7aec8e3aee1e661505bbb6d.zip
feat(symfony-process): port full Process class from PHP
Faithfully port every method, field and constant of Symfony's Process.php into process.rs, replacing the reduced stub. Add the supporting pipes module (PipesInterface/AbstractPipes/UnixPipes/ WindowsPipes), ProcessUtils and the missing process exceptions (LogicException/InvalidArgumentException) with constructors. Methods now return anyhow::Result where PHP throws, take the env argument and a bool-returning callback, and borrow &mut for status-updating accessors; all callers are updated accordingly. Extend the php-shim with proc_open/proc_close (PHP-compatible signatures), proc_get_status, proc_terminate, posix_kill, uniqid, ftruncate, ftell_stream, fseek3, stream_get_contents3 and env helpers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/util/process_executor.rs')
-rw-r--r--crates/shirabe/src/util/process_executor.rs57
1 files changed, 35 insertions, 22 deletions
diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs
index 2bdf065..61fc0a1 100644
--- a/crates/shirabe/src/util/process_executor.rs
+++ b/crates/shirabe/src/util/process_executor.rs
@@ -221,9 +221,9 @@ impl ProcessExecutor {
&command_str,
cwd,
env.clone(),
- None,
+ PhpMixed::Null,
Some(Self::get_timeout() as f64),
- );
+ )?;
} else if let PhpMixed::List(ref list) = command {
let mut cmd_vec: Vec<String> = list
.iter()
@@ -238,9 +238,9 @@ impl ProcessExecutor {
cmd_vec,
cwd.map(String::from),
env,
- None,
+ PhpMixed::Null,
Some(Self::get_timeout() as f64),
- );
+ )?;
} else {
return Err(LogicException {
message: "Invalid command type".to_string(),
@@ -291,20 +291,23 @@ impl ProcessExecutor {
}),
);
- let result: Result<()> = {
- let _ = process.run(/* callback */ Some(Box::new(|_t: &str, _b: &str| {})));
+ let result: Result<()> = (|| -> Result<()> {
+ process.run(
+ /* callback */ Some(Box::new(|_t: &str, _b: &str| false)),
+ IndexMap::new(),
+ )?;
let output_is_callable_inner = output.as_deref().map(is_callable).unwrap_or(false);
if self.capture_output
&& !output_is_callable_inner
&& let Some(out) = output.as_mut()
{
- **out = PhpMixed::String(process.get_output());
+ **out = PhpMixed::String(process.get_output()?);
}
- self.error_output = process.get_error_output();
+ self.error_output = process.get_error_output()?;
Ok(())
- };
+ })();
let final_result: Result<()> = match result {
Ok(()) => Ok(()),
Err(e) => {
@@ -467,23 +470,23 @@ impl ProcessExecutor {
self.output_command_run(&command, cwd.as_deref(), true);
let process_result: Result<Process> = (if is_string(&command) {
- Ok(Process::from_shell_commandline(
+ Process::from_shell_commandline(
command.as_string().unwrap_or(""),
cwd.as_deref(),
None,
- None,
+ PhpMixed::Null,
Some(Self::get_timeout() as f64),
- ))
+ )
} else if let PhpMixed::List(ref list) = command {
- Ok(Process::new(
+ Process::new(
list.iter()
.map(|v| v.as_string().unwrap_or("").to_string())
.collect(),
cwd.clone(),
None,
- None,
+ PhpMixed::Null,
Some(Self::get_timeout() as f64),
- ))
+ )
} else {
Err(LogicException {
message: "Invalid command type".to_string(),
@@ -509,10 +512,20 @@ impl ProcessExecutor {
}
// PHP: $process->start($callback); — we operate on the stored job.process directly
- if let Some(job) = self.jobs.get_mut(&id)
+ let start_result = if let Some(job) = self.jobs.get_mut(&id)
&& let Some(p) = job.process.as_mut()
{
- p.start(None);
+ p.start(None, IndexMap::new())
+ } else {
+ Ok(())
+ };
+ if let Err(e) = start_result {
+ // PHP: $job['reject']($e) — record the rejection and settle the job as failed.
+ if let Some(job) = self.jobs.get_mut(&id) {
+ job.status = Self::STATUS_FAILED;
+ job.exception = Some(e);
+ }
+ self.mark_job_done();
}
}
@@ -571,8 +584,8 @@ impl ProcessExecutor {
if status == Self::STATUS_STARTED && has_process {
let is_running = self
.jobs
- .get(id)
- .and_then(|j| j.process.as_ref())
+ .get_mut(id)
+ .and_then(|j| j.process.as_mut())
.map(|p| p.is_running())
.unwrap_or(false);
if !is_running {
@@ -580,8 +593,8 @@ impl ProcessExecutor {
// marks the job completed/failed based on the process exit status.
let successful = self
.jobs
- .get(id)
- .and_then(|j| j.process.as_ref())
+ .get_mut(id)
+ .and_then(|j| j.process.as_mut())
.map(|p| p.is_successful())
.unwrap_or(false);
if let Some(job) = self.jobs.get_mut(id) {
@@ -594,7 +607,7 @@ impl ProcessExecutor {
self.mark_job_done();
}
- if let Some(p) = self.jobs.get(id).and_then(|j| j.process.as_ref()) {
+ if let Some(p) = self.jobs.get_mut(id).and_then(|j| j.process.as_mut()) {
p.check_timeout()?;
}
}