aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/process
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/process')
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/exception.rs (renamed from crates/shirabe-external-packages/src/symfony/process/exception/mod.rs)0
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/executable_finder.rs66
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/mod.rs13
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/php_executable_finder.rs7
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/pipes.rs (renamed from crates/shirabe-external-packages/src/symfony/process/pipes/mod.rs)0
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/pipes/abstract_pipes.rs15
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/pipes/unix_pipes.rs16
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs5
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/process.rs235
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/process_utils.rs7
10 files changed, 198 insertions, 166 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/process/exception/mod.rs b/crates/shirabe-external-packages/src/symfony/process/exception.rs
index 689a64b..689a64b 100644
--- a/crates/shirabe-external-packages/src/symfony/process/exception/mod.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/exception.rs
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 a151283..3396b29 100644
--- a/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/executable_finder.rs
@@ -1,6 +1,6 @@
//! ref: composer/vendor/symfony/process/ExecutableFinder.php
-use shirabe_php_shim::{self as php, PhpMixed};
+use shirabe_php_shim::PhpMixed;
const CMD_BUILTINS: &[&str] = &[
"assoc", "break", "call", "cd", "chdir", "cls", "color", "copy", "date", "del", "dir", "echo",
@@ -37,25 +37,28 @@ impl ExecutableFinder {
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())
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
+ && CMD_BUILTINS.contains(&shirabe_php_shim::strtolower(name).as_str())
{
return Some(name.to_string());
}
- let path = php::getenv("PATH")
- .or_else(|| php::getenv("Path"))
+ let path = shirabe_php_shim::getenv("PATH")
+ .or_else(|| shirabe_php_shim::getenv("Path"))
.map(|v| v.to_string_lossy().into_owned())
.unwrap_or_default();
- let mut dirs = php::explode(php::PATH_SEPARATOR, &path);
+ let mut dirs = shirabe_php_shim::explode(shirabe_php_shim::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());
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
+ let path_ext =
+ shirabe_php_shim::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),
+ Some(ref ext) if !ext.is_empty() => {
+ shirabe_php_shim::explode(shirabe_php_shim::PATH_SEPARATOR, ext)
+ }
_ => vec![
".exe".to_string(),
".bat".to_string(),
@@ -65,10 +68,13 @@ impl ExecutableFinder {
};
suffixes.extend(exts);
}
- suffixes = if !php::pathinfo(PhpMixed::String(name.to_string()), php::PATHINFO_EXTENSION)
- .as_string()
- .unwrap_or("")
- .is_empty()
+ suffixes = if !shirabe_php_shim::pathinfo(
+ PhpMixed::String(name.to_string()),
+ shirabe_php_shim::PATHINFO_EXTENSION,
+ )
+ .as_string()
+ .unwrap_or("")
+ .is_empty()
{
let mut s = vec![String::new()];
s.extend(suffixes);
@@ -80,41 +86,49 @@ impl ExecutableFinder {
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))
+ let file = format!(
+ "{dir}{}{name}{suffix}",
+ shirabe_php_shim::DIRECTORY_SEPARATOR
+ );
+ if shirabe_php_shim::is_file(&file)
+ && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
+ || shirabe_php_shim::is_executable(&file))
{
return Some(file);
}
- if !php::is_dir(dir)
- && php::basename(dir) == format!("{name}{suffix}")
- && php::is_executable(dir)
+ if !shirabe_php_shim::is_dir(dir)
+ && shirabe_php_shim::basename(dir) == format!("{name}{suffix}")
+ && shirabe_php_shim::is_executable(dir)
{
return Some(dir.to_string());
}
}
}
- if php::DIRECTORY_SEPARATOR == "\\"
- || name.len() != php::strcspn(name, &format!("/{}", php::DIRECTORY_SEPARATOR))
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
+ || name.len()
+ != shirabe_php_shim::strcspn(
+ name,
+ &format!("/{}", shirabe_php_shim::DIRECTORY_SEPARATOR),
+ )
{
return default.map(ToString::to_string);
}
- let exec_result = php::exec(
- &format!("command -v -- {}", php::escapeshellarg(name)),
+ let exec_result = shirabe_php_shim::exec(
+ &format!("command -v -- {}", shirabe_php_shim::escapeshellarg(name)),
None,
None,
)
.unwrap_or_default();
- let executable_path = php::substr(
+ let executable_path = shirabe_php_shim::substr(
&exec_result,
0,
- php::strpos(&exec_result, php::PHP_EOL).map(|i| i as i64),
+ shirabe_php_shim::strpos(&exec_result, shirabe_php_shim::PHP_EOL).map(|i| i as i64),
);
- if !executable_path.is_empty() && php::is_executable(&executable_path) {
+ if !executable_path.is_empty() && shirabe_php_shim::is_executable(&executable_path) {
return Some(executable_path);
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/mod.rs b/crates/shirabe-external-packages/src/symfony/process/mod.rs
deleted file mode 100644
index 15967be..0000000
--- a/crates/shirabe-external-packages/src/symfony/process/mod.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-pub mod exception;
-pub mod executable_finder;
-pub mod php_executable_finder;
-pub mod pipes;
-pub mod process;
-pub mod process_utils;
-
-pub use exception::*;
-pub use executable_finder::*;
-pub use php_executable_finder::*;
-pub use pipes::*;
-pub use process::*;
-pub use process_utils::*;
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 9d04c5e..55ace18 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,6 @@
//! ref: composer/vendor/symfony/process/PhpExecutableFinder.php
use super::executable_finder::ExecutableFinder;
-use shirabe_php_shim::{self as php};
#[derive(Debug)]
pub struct PhpExecutableFinder {
@@ -23,16 +22,16 @@ impl PhpExecutableFinder {
/// 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()) {
+ 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 !php::is_executable(&php) {
+ if !shirabe_php_shim::is_executable(&php) {
match self.executable_finder.find(&php, None, &[]) {
Some(found) => php = found,
None => return None,
}
}
- if php::is_dir(&php) {
+ if shirabe_php_shim::is_dir(&php) {
return None;
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/mod.rs b/crates/shirabe-external-packages/src/symfony/process/pipes.rs
index 6a77f5f..6a77f5f 100644
--- a/crates/shirabe-external-packages/src/symfony/process/pipes/mod.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/pipes.rs
diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/abstract_pipes.rs b/crates/shirabe-external-packages/src/symfony/process/pipes/abstract_pipes.rs
index 43a6567..f9fb251 100644
--- a/crates/shirabe-external-packages/src/symfony/process/pipes/abstract_pipes.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/pipes/abstract_pipes.rs
@@ -1,7 +1,7 @@
//! ref: composer/vendor/symfony/process/Pipes/AbstractPipes.php
use indexmap::IndexMap;
-use shirabe_php_shim::{self as php, PhpMixed, PhpResource};
+use shirabe_php_shim::{PhpMixed, PhpResource};
#[derive(Debug)]
pub struct AbstractPipes {
@@ -38,7 +38,7 @@ impl AbstractPipes {
pub fn close(&mut self) {
for (_, pipe) in &self.pipes {
- php::fclose(pipe);
+ shirabe_php_shim::fclose(pipe);
}
self.pipes = IndexMap::new();
}
@@ -60,7 +60,7 @@ impl AbstractPipes {
}
for (_, pipe) in &self.pipes {
- php::stream_set_blocking(pipe, false);
+ shirabe_php_shim::stream_set_blocking(pipe, false);
}
// The `is_resource($this->input)` branch does not apply: `input` is never a resource in this
// port (is_resource on a PhpMixed is always false).
@@ -81,10 +81,11 @@ impl AbstractPipes {
let mut w: Vec<PhpResource> = vec![stdin.clone()];
// let's have a look if something changed in streams
- php::stream_select(&mut r, &mut w, &mut e, 0, Some(0))?;
+ shirabe_php_shim::stream_select(&mut r, &mut w, &mut e, 0, Some(0))?;
if !self.input_buffer.is_empty() {
- let written = php::fwrite(&stdin, &self.input_buffer, None).unwrap_or(0) as usize;
+ let written =
+ shirabe_php_shim::fwrite(&stdin, &self.input_buffer, None).unwrap_or(0) as usize;
self.input_buffer = self.input_buffer.get(written..).unwrap_or("").to_string();
if !self.input_buffer.is_empty() {
return Some(vec![stdin]);
@@ -92,9 +93,9 @@ impl AbstractPipes {
}
// no input to read on resource, buffer is empty
- if self.input_buffer.is_empty() && !php::php_truthy(&self.input) {
+ if self.input_buffer.is_empty() && !shirabe_php_shim::php_truthy(&self.input) {
self.input = PhpMixed::Null;
- php::fclose(&stdin);
+ shirabe_php_shim::fclose(&stdin);
self.pipes.shift_remove(&0);
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/unix_pipes.rs b/crates/shirabe-external-packages/src/symfony/process/pipes/unix_pipes.rs
index 795bb64..aff2a54 100644
--- a/crates/shirabe-external-packages/src/symfony/process/pipes/unix_pipes.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/pipes/unix_pipes.rs
@@ -1,11 +1,10 @@
//! ref: composer/vendor/symfony/process/Pipes/UnixPipes.php
-use indexmap::IndexMap;
-use shirabe_php_shim::{self as php, Descriptor, PhpMixed, PhpResource};
-
use crate::symfony::process::pipes::abstract_pipes::AbstractPipes;
use crate::symfony::process::pipes::pipes_interface::{CHUNK_SIZE, PipesInterface};
use crate::symfony::process::process::Process;
+use indexmap::IndexMap;
+use shirabe_php_shim::{Descriptor, PhpMixed, PhpResource};
/// UnixPipes implementation uses unix pipes as handles.
#[derive(Debug)]
@@ -44,7 +43,8 @@ fn descriptor(items: &[&str]) -> Descriptor {
impl PipesInterface for UnixPipes {
fn get_descriptors(&mut self) -> Vec<Descriptor> {
if !self.have_read_support {
- let nullstream = php::fopen("/dev/null", "c").expect("fopen('/dev/null') failed");
+ let nullstream =
+ shirabe_php_shim::fopen("/dev/null", "c").expect("fopen('/dev/null') failed");
return vec![
descriptor(&["pipe", "r"]),
Descriptor::Resource(nullstream.clone()),
@@ -100,7 +100,7 @@ impl PipesInterface for UnixPipes {
// let's have a look if something changed in streams
if (!r_sel.is_empty() || w.is_some())
- && php::stream_select(
+ && shirabe_php_shim::stream_select(
&mut r_sel,
&mut w_sel,
&mut e_sel,
@@ -125,7 +125,7 @@ impl PipesInterface for UnixPipes {
for (fd, pipe) in &r {
let mut data = String::new();
loop {
- let chunk = php::fread(pipe, CHUNK_SIZE).unwrap_or_default();
+ let chunk = shirabe_php_shim::fread(pipe, CHUNK_SIZE).unwrap_or_default();
let len = chunk.len() as i64;
data.push_str(&chunk);
if !(len > 0 && (close || len >= CHUNK_SIZE)) {
@@ -137,8 +137,8 @@ impl PipesInterface for UnixPipes {
read.insert(*fd, data);
}
- if close && php::feof(pipe) {
- php::fclose(pipe);
+ if close && shirabe_php_shim::feof(pipe) {
+ shirabe_php_shim::fclose(pipe);
self.inner.pipes.shift_remove(fd);
}
}
diff --git a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
index a31f184..f721d2b 100644
--- a/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/pipes/windows_pipes.rs
@@ -1,10 +1,9 @@
//! ref: composer/vendor/symfony/process/Pipes/WindowsPipes.php
-use indexmap::IndexMap;
-use shirabe_php_shim::{Descriptor, PhpMixed, PhpResource};
-
use crate::symfony::process::pipes::abstract_pipes::AbstractPipes;
use crate::symfony::process::pipes::pipes_interface::PipesInterface;
+use indexmap::IndexMap;
+use shirabe_php_shim::{Descriptor, PhpMixed, PhpResource};
/// WindowsPipes implementation uses temporary files as handles.
#[derive(Debug)]
diff --git a/crates/shirabe-external-packages/src/symfony/process/process.rs b/crates/shirabe-external-packages/src/symfony/process/process.rs
index fbf2da7..84bed62 100644
--- a/crates/shirabe-external-packages/src/symfony/process/process.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/process.rs
@@ -1,10 +1,5 @@
//! ref: composer/vendor/symfony/process/Process.php
-use std::sync::OnceLock;
-
-use indexmap::IndexMap;
-use shirabe_php_shim::{self as php, Descriptor, PhpMixed, PhpResource};
-
use crate::symfony::process::exception::invalid_argument_exception::InvalidArgumentException;
use crate::symfony::process::exception::logic_exception::LogicException;
use crate::symfony::process::exception::process_failed_exception::ProcessFailedException;
@@ -16,6 +11,9 @@ use crate::symfony::process::pipes::pipes_interface::PipesInterface;
use crate::symfony::process::pipes::unix_pipes::UnixPipes;
use crate::symfony::process::pipes::windows_pipes::WindowsPipes;
use crate::symfony::process::process_utils::ProcessUtils;
+use indexmap::IndexMap;
+use shirabe_php_shim::{Descriptor, PhpMixed, PhpResource};
+use std::sync::OnceLock;
/// A user-supplied callback invoked with the output type ("out"/"err") and a chunk of output.
pub type UserCallback = Box<dyn FnMut(&str, &str) -> bool>;
@@ -210,7 +208,7 @@ impl Process {
input: PhpMixed,
timeout: Option<f64>,
) -> anyhow::Result<Self> {
- if !php::function_exists("proc_open") {
+ if !shirabe_php_shim::function_exists("proc_open") {
return Err(LogicException::new(
"The Process class relies on proc_open, which is not available on your PHP installation.".to_string(),
)
@@ -227,7 +225,7 @@ impl Process {
// exists; its value merely reflects the NTS/ZTS build), so the disjunction is always true and
// the cwd is defaulted to getcwd() whenever it was null.
if this.cwd.is_none() {
- this.cwd = php::getcwd();
+ this.cwd = shirabe_php_shim::getcwd();
}
if let Some(env) = env {
this.set_env(
@@ -239,7 +237,7 @@ impl Process {
this.set_input(input)?;
this.set_timeout(timeout)?;
- this.use_file_handles = php::DIRECTORY_SEPARATOR == "\\";
+ this.use_file_handles = shirabe_php_shim::DIRECTORY_SEPARATOR == "\\";
this.pty = false;
Ok(this)
@@ -260,7 +258,7 @@ impl Process {
}
pub fn __sleep(&self) -> anyhow::Result<Vec<String>> {
- Err(php::BadMethodCallException {
+ Err(shirabe_php_shim::BadMethodCallException {
message: "Cannot serialize Symfony\\Component\\Process\\Process".to_string(),
code: 0,
}
@@ -268,7 +266,7 @@ impl Process {
}
pub fn __wakeup(&self) -> anyhow::Result<()> {
- Err(php::BadMethodCallException {
+ Err(shirabe_php_shim::BadMethodCallException {
message: "Cannot unserialize Symfony\\Component\\Process\\Process".to_string(),
code: 0,
}
@@ -310,7 +308,7 @@ impl Process {
}
self.reset_process_data();
- self.starttime = Some(php::microtime());
+ self.starttime = Some(shirabe_php_shim::microtime());
self.last_output_time = self.starttime;
let has_callback = callback.is_some();
self.callback = Some(self.build_callback(callback));
@@ -336,7 +334,7 @@ impl Process {
.collect::<Vec<_>>()
.join(" ");
- if php::DIRECTORY_SEPARATOR != "\\" {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" {
// exec is mandatory to deal with sending a signal to the process
cmd = format!("exec {}", cmd);
}
@@ -345,7 +343,7 @@ impl Process {
CommandLine::String(s) => self.replace_placeholders(s, &env)?,
};
- if php::DIRECTORY_SEPARATOR == "\\" {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
commandline = self.prepare_windows_command_line(&commandline, &mut env)?;
} else if !self.use_file_handles && self.is_sigchild_enabled() {
// last exit code is output on the fourth pipe and caught to work around --enable-sigchild
@@ -357,7 +355,7 @@ impl Process {
);
// Workaround for the bug, when PTS functionality is enabled.
- let _pts_workaround = php::fopen("Process.php", "r");
+ let _pts_workaround = shirabe_php_shim::fopen("Process.php", "r");
}
let mut env_pairs: Vec<String> = Vec::new();
@@ -368,7 +366,12 @@ impl Process {
}
}
- if !self.cwd.as_deref().map(php::is_dir).unwrap_or(false) {
+ if !self
+ .cwd
+ .as_deref()
+ .map(shirabe_php_shim::is_dir)
+ .unwrap_or(false)
+ {
return Err(RuntimeException::new(format!(
"The provided cwd \"{}\" does not exist.",
self.cwd.as_deref().unwrap_or("")
@@ -380,7 +383,7 @@ impl Process {
let options = self.options.clone();
let process = {
let pipes = self.process_pipes.as_mut().unwrap().pipes_mut();
- php::proc_open(
+ shirabe_php_shim::proc_open(
&commandline,
&descriptors,
pipes,
@@ -407,7 +410,7 @@ impl Process {
.get(&3)
.cloned();
let pid = pipe3
- .and_then(|p| php::fgets(&p, None))
+ .and_then(|p| shirabe_php_shim::fgets(&p, None))
.map(|s| s.trim().parse::<i64>().unwrap_or(0))
.unwrap_or(0);
self.fallback_status
@@ -459,9 +462,12 @@ impl Process {
loop {
self.check_timeout()?;
let running = self.is_running()
- && (php::DIRECTORY_SEPARATOR == "\\"
+ && (shirabe_php_shim::DIRECTORY_SEPARATOR == "\\"
|| self.process_pipes.as_ref().unwrap().are_open());
- self.read_pipes(running, php::DIRECTORY_SEPARATOR != "\\" || !running);
+ self.read_pipes(
+ running,
+ shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running,
+ );
if !running {
break;
}
@@ -469,14 +475,14 @@ impl Process {
while self.is_running() {
self.check_timeout()?;
- php::usleep(1000);
+ shirabe_php_shim::usleep(1000);
}
let signaled = self
.process_information
.as_ref()
.and_then(|i| i.get("signaled"))
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false);
let termsig = self
.process_information
@@ -507,16 +513,15 @@ impl Process {
let mut ready = false;
loop {
self.check_timeout()?;
- let running = if php::DIRECTORY_SEPARATOR == "\\" {
+ let running = if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
self.is_running()
} else {
self.process_pipes.as_ref().unwrap().are_open()
};
- let output = self
- .process_pipes
- .as_mut()
- .unwrap()
- .read_and_write(running, php::DIRECTORY_SEPARATOR != "\\" || !running);
+ let output = self.process_pipes.as_mut().unwrap().read_and_write(
+ running,
+ shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running,
+ );
for (r#type, data) in output {
if r#type != 3 {
@@ -544,7 +549,7 @@ impl Process {
return Ok(false);
}
- php::usleep(1000);
+ shirabe_php_shim::usleep(1000);
}
}
@@ -609,19 +614,23 @@ impl Process {
pub fn get_output(&mut self) -> anyhow::Result<String> {
self.read_pipes_for_output("getOutput", false)?;
- Ok(php::stream_get_contents3(self.stdout.as_ref().unwrap(), -1, 0).unwrap_or_default())
+ Ok(
+ shirabe_php_shim::stream_get_contents3(self.stdout.as_ref().unwrap(), -1, 0)
+ .unwrap_or_default(),
+ )
}
/// Returns the output incrementally.
pub fn get_incremental_output(&mut self) -> anyhow::Result<String> {
self.read_pipes_for_output("getIncrementalOutput", false)?;
- let latest = php::stream_get_contents3(
+ let latest = shirabe_php_shim::stream_get_contents3(
self.stdout.as_ref().unwrap(),
-1,
self.incremental_output_offset,
);
- self.incremental_output_offset = php::ftell(self.stdout.as_ref().unwrap()).unwrap_or(0);
+ self.incremental_output_offset =
+ shirabe_php_shim::ftell(self.stdout.as_ref().unwrap()).unwrap_or(0);
Ok(latest.unwrap_or_default())
}
@@ -639,14 +648,14 @@ impl Process {
let mut yields = Vec::new();
while self.callback.is_some()
- || (yield_out && !php::feof(self.stdout.as_ref().unwrap()))
- || (yield_err && !php::feof(self.stderr.as_ref().unwrap()))
+ || (yield_out && !shirabe_php_shim::feof(self.stdout.as_ref().unwrap()))
+ || (yield_err && !shirabe_php_shim::feof(self.stderr.as_ref().unwrap()))
{
let mut got_out = false;
let mut got_err = false;
if yield_out {
- let out = php::stream_get_contents3(
+ let out = shirabe_php_shim::stream_get_contents3(
self.stdout.as_ref().unwrap(),
-1,
self.incremental_output_offset,
@@ -659,7 +668,7 @@ impl Process {
self.clear_output();
} else {
self.incremental_output_offset =
- php::ftell(self.stdout.as_ref().unwrap()).unwrap_or(0);
+ shirabe_php_shim::ftell(self.stdout.as_ref().unwrap()).unwrap_or(0);
}
yields.push((Self::OUT.to_string(), out));
@@ -667,7 +676,7 @@ impl Process {
}
if yield_err {
- let err = php::stream_get_contents3(
+ let err = shirabe_php_shim::stream_get_contents3(
self.stderr.as_ref().unwrap(),
-1,
self.incremental_error_output_offset,
@@ -680,7 +689,7 @@ impl Process {
self.clear_error_output();
} else {
self.incremental_error_output_offset =
- php::ftell(self.stderr.as_ref().unwrap()).unwrap_or(0);
+ shirabe_php_shim::ftell(self.stderr.as_ref().unwrap()).unwrap_or(0);
}
yields.push((Self::ERR.to_string(), err));
@@ -700,8 +709,8 @@ impl Process {
/// Clears the process output.
pub fn clear_output(&mut self) -> &mut Self {
- php::ftruncate(self.stdout.as_ref().unwrap(), 0);
- php::fseek(self.stdout.as_ref().unwrap(), 0, php::SEEK_SET);
+ shirabe_php_shim::ftruncate(self.stdout.as_ref().unwrap(), 0);
+ shirabe_php_shim::fseek(self.stdout.as_ref().unwrap(), 0, shirabe_php_shim::SEEK_SET);
self.incremental_output_offset = 0;
self
@@ -711,28 +720,31 @@ impl Process {
pub fn get_error_output(&mut self) -> anyhow::Result<String> {
self.read_pipes_for_output("getErrorOutput", false)?;
- Ok(php::stream_get_contents3(self.stderr.as_ref().unwrap(), -1, 0).unwrap_or_default())
+ Ok(
+ shirabe_php_shim::stream_get_contents3(self.stderr.as_ref().unwrap(), -1, 0)
+ .unwrap_or_default(),
+ )
}
/// Returns the errorOutput incrementally.
pub fn get_incremental_error_output(&mut self) -> anyhow::Result<String> {
self.read_pipes_for_output("getIncrementalErrorOutput", false)?;
- let latest = php::stream_get_contents3(
+ let latest = shirabe_php_shim::stream_get_contents3(
self.stderr.as_ref().unwrap(),
-1,
self.incremental_error_output_offset,
);
self.incremental_error_output_offset =
- php::ftell(self.stderr.as_ref().unwrap()).unwrap_or(0);
+ shirabe_php_shim::ftell(self.stderr.as_ref().unwrap()).unwrap_or(0);
Ok(latest.unwrap_or_default())
}
/// Clears the process error output.
pub fn clear_error_output(&mut self) -> &mut Self {
- php::ftruncate(self.stderr.as_ref().unwrap(), 0);
- php::fseek(self.stderr.as_ref().unwrap(), 0, php::SEEK_SET);
+ shirabe_php_shim::ftruncate(self.stderr.as_ref().unwrap(), 0);
+ shirabe_php_shim::fseek(self.stderr.as_ref().unwrap(), 0, shirabe_php_shim::SEEK_SET);
self.incremental_error_output_offset = 0;
self
@@ -769,7 +781,7 @@ impl Process {
.process_information
.as_ref()
.and_then(|i| i.get("signaled"))
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false))
}
@@ -800,7 +812,7 @@ impl Process {
.process_information
.as_ref()
.and_then(|i| i.get("stopped"))
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false))
}
@@ -827,7 +839,7 @@ impl Process {
self.process_information
.as_ref()
.and_then(|i| i.get("running"))
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false)
}
@@ -852,14 +864,14 @@ impl Process {
/// Stops the process.
pub fn stop(&mut self, timeout: f64, signal: Option<i64>) -> Option<i64> {
- let timeout_micro = php::microtime() + timeout;
+ let timeout_micro = shirabe_php_shim::microtime() + timeout;
if self.is_running() {
// given SIGTERM may not be defined and that "proc_terminate" uses the constant value
// and not the constant itself, we use the same here
let _ = self.do_signal(15, false);
loop {
- php::usleep(1000);
- if !(self.is_running() && php::microtime() < timeout_micro) {
+ shirabe_php_shim::usleep(1000);
+ if !(self.is_running() && shirabe_php_shim::microtime() < timeout_micro) {
break;
}
}
@@ -885,22 +897,30 @@ impl Process {
/// Adds a line to the STDOUT stream.
pub fn add_output(&mut self, line: &str) {
- self.last_output_time = Some(php::microtime());
+ self.last_output_time = Some(shirabe_php_shim::microtime());
let stdout = self.stdout.as_ref().unwrap();
- php::fseek(stdout, 0, php::SEEK_END);
- php::fwrite(stdout, line, Some(line.len() as i64));
- php::fseek(stdout, self.incremental_output_offset, php::SEEK_SET);
+ shirabe_php_shim::fseek(stdout, 0, shirabe_php_shim::SEEK_END);
+ shirabe_php_shim::fwrite(stdout, line, Some(line.len() as i64));
+ shirabe_php_shim::fseek(
+ stdout,
+ self.incremental_output_offset,
+ shirabe_php_shim::SEEK_SET,
+ );
}
/// Adds a line to the STDERR stream.
pub fn add_error_output(&mut self, line: &str) {
- self.last_output_time = Some(php::microtime());
+ self.last_output_time = Some(shirabe_php_shim::microtime());
let stderr = self.stderr.as_ref().unwrap();
- php::fseek(stderr, 0, php::SEEK_END);
- php::fwrite(stderr, line, Some(line.len() as i64));
- php::fseek(stderr, self.incremental_error_output_offset, php::SEEK_SET);
+ shirabe_php_shim::fseek(stderr, 0, shirabe_php_shim::SEEK_END);
+ shirabe_php_shim::fwrite(stderr, line, Some(line.len() as i64));
+ shirabe_php_shim::fseek(
+ stderr,
+ self.incremental_error_output_offset,
+ shirabe_php_shim::SEEK_SET,
+ );
}
/// Gets the last output time in seconds.
@@ -953,7 +973,7 @@ impl Process {
/// Enables or disables the TTY mode.
pub fn set_tty(&mut self, tty: bool) -> anyhow::Result<&mut Self> {
- if php::DIRECTORY_SEPARATOR == "\\" && tty {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" && tty {
return Err(RuntimeException::new(
"TTY mode is not supported on Windows platform.".to_string(),
)
@@ -994,7 +1014,7 @@ impl Process {
if self.cwd.is_none() {
// getcwd() will return false if any one of the parent directories does not have
// the readable or search mode set, even if the current directory does
- return php::getcwd().filter(|s| !s.is_empty());
+ return shirabe_php_shim::getcwd().filter(|s| !s.is_empty());
}
self.cwd.clone()
@@ -1046,7 +1066,7 @@ impl Process {
}
if let Some(timeout) = self.timeout
- && timeout < php::microtime() - self.starttime.unwrap_or(0.0)
+ && timeout < shirabe_php_shim::microtime() - self.starttime.unwrap_or(0.0)
{
self.stop(0.0, None);
@@ -1058,7 +1078,7 @@ impl Process {
}
if let Some(idle_timeout) = self.idle_timeout
- && idle_timeout < php::microtime() - self.last_output_time.unwrap_or(0.0)
+ && idle_timeout < shirabe_php_shim::microtime() - self.last_output_time.unwrap_or(0.0)
{
self.stop(0.0, None);
@@ -1119,7 +1139,7 @@ impl Process {
*IS_TTY_SUPPORTED.get_or_init(|| {
let mut pipes = IndexMap::new();
- php::proc_open(
+ shirabe_php_shim::proc_open(
"echo 1 >/dev/null",
&[
descriptor(&["file", "/dev/tty", "r"]),
@@ -1140,12 +1160,12 @@ impl Process {
static RESULT: OnceLock<bool> = OnceLock::new();
*RESULT.get_or_init(|| {
- if php::DIRECTORY_SEPARATOR == "\\" {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
return false;
}
let mut pipes = IndexMap::new();
- php::proc_open(
+ shirabe_php_shim::proc_open(
"echo 1 >/dev/null",
&[
descriptor(&["pty"]),
@@ -1164,7 +1184,7 @@ impl Process {
/// Creates the descriptors needed by the proc_open.
fn get_descriptors(&mut self) -> Vec<Descriptor> {
// TODO(plugin): $this->input instanceof \Iterator -> rewind() is not modeled.
- if php::DIRECTORY_SEPARATOR == "\\" {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
self.process_pipes = Some(Box::new(WindowsPipes::new(
self.input.clone(),
!self.output_disabled || self.has_callback,
@@ -1219,17 +1239,19 @@ impl Process {
return;
}
- self.process_information = Some(php::proc_get_status(self.process.as_ref().unwrap()));
+ self.process_information = Some(shirabe_php_shim::proc_get_status(
+ self.process.as_ref().unwrap(),
+ ));
let running = self
.process_information
.as_ref()
.unwrap()
.get("running")
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false);
// In PHP < 8.3, "proc_get_status" only returns the correct exit status on the first call.
- if php::PHP_VERSION_ID < 80300 {
+ if shirabe_php_shim::PHP_VERSION_ID < 80300 {
let exitcode = self
.process_information
.as_ref()
@@ -1253,7 +1275,7 @@ impl Process {
self.read_pipes(
running && blocking,
- php::DIRECTORY_SEPARATOR != "\\" || !running,
+ shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" || !running,
);
if !self.fallback_status.is_empty() && self.is_sigchild_enabled() {
@@ -1278,16 +1300,16 @@ impl Process {
return *v;
}
- if !php::function_exists("phpinfo") {
+ if !shirabe_php_shim::function_exists("phpinfo") {
return *SIGCHILD.get_or_init(|| false);
}
- php::ob_start();
- php::phpinfo(php::INFO_GENERAL);
+ shirabe_php_shim::ob_start();
+ shirabe_php_shim::phpinfo(shirabe_php_shim::INFO_GENERAL);
*SIGCHILD.get_or_init(|| {
- php::str_contains(
- &php::ob_get_clean().unwrap_or_default(),
+ shirabe_php_shim::str_contains(
+ &shirabe_php_shim::ob_get_clean().unwrap_or_default(),
"--enable-sigchild",
)
})
@@ -1359,7 +1381,7 @@ impl Process {
p.close();
}
if self.process.is_some() {
- php::proc_close(self.process.as_ref().unwrap());
+ shirabe_php_shim::proc_close(self.process.as_ref().unwrap());
self.process = None;
}
self.exitcode = self
@@ -1374,7 +1396,7 @@ impl Process {
.process_information
.as_ref()
.and_then(|i| i.get("signaled"))
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false);
let termsig = self
.process_information
@@ -1407,10 +1429,14 @@ impl Process {
self.fallback_status = IndexMap::new();
self.process_information = None;
// php://temp is an in-memory stream; fopen never fails for it.
- self.stdout =
- Some(php::fopen(&format!("php://temp/maxmemory:{}", 1024 * 1024), "w+").unwrap());
- self.stderr =
- Some(php::fopen(&format!("php://temp/maxmemory:{}", 1024 * 1024), "w+").unwrap());
+ self.stdout = Some(
+ shirabe_php_shim::fopen(&format!("php://temp/maxmemory:{}", 1024 * 1024), "w+")
+ .unwrap(),
+ );
+ self.stderr = Some(
+ shirabe_php_shim::fopen(&format!("php://temp/maxmemory:{}", 1024 * 1024), "w+")
+ .unwrap(),
+ );
self.process = None;
self.latest_signal = None;
self.status = Self::STATUS_READY.to_string();
@@ -1434,10 +1460,10 @@ impl Process {
Some(pid) => pid,
};
- if php::DIRECTORY_SEPARATOR == "\\" {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR == "\\" {
let mut output: Vec<String> = Vec::new();
let mut exit_code: i64 = 0;
- php::exec(
+ shirabe_php_shim::exec(
&format!("taskkill /F /T /PID {} 2>&1", pid),
Some(&mut output),
Some(&mut exit_code),
@@ -1456,12 +1482,12 @@ impl Process {
} else {
let ok;
if !self.is_sigchild_enabled() {
- ok = php::proc_terminate(self.process.as_ref().unwrap(), signal);
- } else if php::function_exists("posix_kill") {
- ok = php::posix_kill(pid, signal);
+ ok = shirabe_php_shim::proc_terminate(self.process.as_ref().unwrap(), signal);
+ } else if shirabe_php_shim::function_exists("posix_kill") {
+ ok = shirabe_php_shim::posix_kill(pid, signal);
} else {
let mut pipes = IndexMap::new();
- let opened = php::proc_open(
+ let opened = shirabe_php_shim::proc_open(
&format!("kill -{} {}", signal, pid),
&[
Descriptor::Inherit,
@@ -1474,7 +1500,10 @@ impl Process {
None,
);
ok = match opened {
- Ok(_) => pipes.get(&2).and_then(|p| php::fgets(p, None)).is_none(),
+ Ok(_) => pipes
+ .get(&2)
+ .and_then(|p| shirabe_php_shim::fgets(p, None))
+ .is_none(),
Err(_) => false,
};
}
@@ -1509,10 +1538,10 @@ impl Process {
cmd: &str,
env: &mut IndexMap<String, PhpMixed>,
) -> anyhow::Result<String> {
- let uid = php::uniqid("", true);
+ let uid = shirabe_php_shim::uniqid("", true);
let mut var_count = 0;
let mut var_cache: IndexMap<String, String> = IndexMap::new();
- let cmd = php::preg_replace_callback(
+ let cmd = shirabe_php_shim::preg_replace_callback(
r#"/"(?:(
[^"%!^]*+
(?:
@@ -1533,7 +1562,7 @@ impl Process {
if value.contains('\0') {
value = value.replace('\0', "?");
}
- if php::strpbrk(&value, "\"%!\n").is_none() {
+ if shirabe_php_shim::strpbrk(&value, "\"%!\n").is_none() {
return Ok(format!("\"{}\"", value));
}
@@ -1548,7 +1577,7 @@ impl Process {
}
value = format!(
"\"{}\"",
- php::preg_replace(r#"/(\\*)"/"#, "$1$1\\\"", &value)
+ shirabe_php_shim::preg_replace(r#"/(\\*)"/"#, "$1$1\\\"", &value)
);
var_count += 1;
let var = format!("{}{}", uid, var_count);
@@ -1570,7 +1599,7 @@ impl Process {
.map(|spec| {
format!(
"\"{}\"",
- php::preg_replace(r#"{(\\*+)"}"#, "$1$1\\\"", &spec)
+ shirabe_php_shim::preg_replace(r#"{(\\*+)"}"#, "$1$1\\\"", &spec)
)
})
})
@@ -1618,17 +1647,21 @@ impl Process {
None | Some("") => return "\"\"".to_string(),
Some(a) => a,
};
- if php::DIRECTORY_SEPARATOR != "\\" {
+ if shirabe_php_shim::DIRECTORY_SEPARATOR != "\\" {
return format!("'{}'", argument.replace('\'', "'\\''"));
}
let mut argument = argument.to_string();
if argument.contains('\0') {
argument = argument.replace('\0', "?");
}
- if !php::preg_match(r#"/[()%!^"<>&|\s\[\]=;*?'$]/"#, &argument, &mut Vec::new()) {
+ if !shirabe_php_shim::preg_match(
+ r#"/[()%!^"<>&|\s\[\]=;*?'$]/"#,
+ &argument,
+ &mut Vec::new(),
+ ) {
return argument;
}
- argument = php::preg_replace(r"/(\\+)$/", "$1$1", &argument);
+ argument = shirabe_php_shim::preg_replace(r"/(\\+)$/", "$1$1", &argument);
let mut result = argument;
for (from, to) in [
@@ -1648,7 +1681,7 @@ impl Process {
commandline: &str,
env: &IndexMap<String, PhpMixed>,
) -> anyhow::Result<String> {
- php::preg_replace_callback(
+ shirabe_php_shim::preg_replace_callback(
r#"/"\$\{:([_a-zA-Z]+[_a-zA-Z0-9]*)\}"/"#,
|matches: &[Option<String>]| -> anyhow::Result<String> {
let key = matches.get(1).cloned().flatten().unwrap_or_default();
@@ -1671,7 +1704,7 @@ impl Process {
}
fn get_default_env(&self) -> IndexMap<String, PhpMixed> {
- let env: IndexMap<String, String> = php::getenv_all()
+ let env: IndexMap<String, String> = shirabe_php_shim::getenv_all()
.map(|(k, v)| {
(
k.to_string_lossy().into_owned(),
@@ -1679,7 +1712,7 @@ impl Process {
)
})
.collect();
- let server = php::PHP_SERVER.lock().unwrap();
+ let server = shirabe_php_shim::PHP_SERVER.lock().unwrap();
// non-Windows: array_intersect_key($env, $_SERVER) ?: $env
let mut intersect: IndexMap<String, PhpMixed> = IndexMap::new();
@@ -1697,7 +1730,7 @@ impl Process {
};
// $_ENV + env_map
- let mut result: IndexMap<String, PhpMixed> = php::PHP_ENV
+ let mut result: IndexMap<String, PhpMixed> = shirabe_php_shim::PHP_ENV
.lock()
.unwrap()
.get_all()
@@ -1739,7 +1772,7 @@ impl Drop for Process {
if self
.options
.get("create_new_console")
- .map(php::php_truthy)
+ .map(shirabe_php_shim::php_truthy)
.unwrap_or(false)
{
if let Some(p) = self.process_pipes.as_mut() {
diff --git a/crates/shirabe-external-packages/src/symfony/process/process_utils.rs b/crates/shirabe-external-packages/src/symfony/process/process_utils.rs
index 7287b28..71943b8 100644
--- a/crates/shirabe-external-packages/src/symfony/process/process_utils.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/process_utils.rs
@@ -1,8 +1,7 @@
//! ref: composer/vendor/symfony/process/ProcessUtils.php
-use shirabe_php_shim::{self as php, PhpMixed};
-
use crate::symfony::process::exception::invalid_argument_exception::InvalidArgumentException;
+use shirabe_php_shim::PhpMixed;
/// ProcessUtils is a bunch of utility methods.
#[derive(Debug)]
@@ -12,10 +11,10 @@ impl ProcessUtils {
/// Validates and normalizes a Process input.
pub fn validate_input(caller: &str, input: PhpMixed) -> anyhow::Result<PhpMixed> {
if !input.is_null() {
- if php::is_string(&input) {
+ if shirabe_php_shim::is_string(&input) {
return Ok(input);
}
- if php::is_scalar(&input) {
+ if shirabe_php_shim::is_scalar(&input) {
let s = match &input {
PhpMixed::Bool(b) => {
if *b {