diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-28 17:45:06 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-28 17:45:26 +0900 |
| commit | 53f1fb395f33e0fb8db9aebd09ea9082f650f9f1 (patch) | |
| tree | f9e8bf0e9d4b1e98cce383574fb6a13b684fff08 /crates/shirabe-external-packages/src | |
| parent | 212f5cd75b1403ee75ffa44d7ebdb181174340c0 (diff) | |
| download | php-shirabe-53f1fb395f33e0fb8db9aebd09ea9082f650f9f1.tar.gz php-shirabe-53f1fb395f33e0fb8db9aebd09ea9082f650f9f1.tar.zst php-shirabe-53f1fb395f33e0fb8db9aebd09ea9082f650f9f1.zip | |
refactor: add linter
Diffstat (limited to 'crates/shirabe-external-packages/src')
49 files changed, 229 insertions, 191 deletions
diff --git a/crates/shirabe-external-packages/src/composer/mod.rs b/crates/shirabe-external-packages/src/composer.rs index 907f985..907f985 100644 --- a/crates/shirabe-external-packages/src/composer/mod.rs +++ b/crates/shirabe-external-packages/src/composer.rs diff --git a/crates/shirabe-external-packages/src/composer/ca_bundle/mod.rs b/crates/shirabe-external-packages/src/composer/ca_bundle.rs index 2a32509..2a32509 100644 --- a/crates/shirabe-external-packages/src/composer/ca_bundle/mod.rs +++ b/crates/shirabe-external-packages/src/composer/ca_bundle.rs diff --git a/crates/shirabe-external-packages/src/composer/pcre/mod.rs b/crates/shirabe-external-packages/src/composer/pcre.rs index 20c37d0..20c37d0 100644 --- a/crates/shirabe-external-packages/src/composer/pcre/mod.rs +++ b/crates/shirabe-external-packages/src/composer/pcre.rs diff --git a/crates/shirabe-external-packages/src/composer/pcre/preg.rs b/crates/shirabe-external-packages/src/composer/pcre/preg.rs index 2c7430d..b4def4d 100644 --- a/crates/shirabe-external-packages/src/composer/pcre/preg.rs +++ b/crates/shirabe-external-packages/src/composer/pcre/preg.rs @@ -12,12 +12,11 @@ //! See docs/dev/regex-porting.md for more detailed regex porting rules. use indexmap::IndexMap; +pub use shirabe_php_shim::CaptureKey; use shirabe_php_shim::{ PREG_OFFSET_CAPTURE, PREG_SET_ORDER, PREG_SPLIT_OFFSET_CAPTURE, PREG_UNMATCHED_AS_NULL, }; -pub use shirabe_php_shim::CaptureKey; - #[derive(Debug)] pub struct Preg; diff --git a/crates/shirabe-external-packages/src/composer/xdebug_handler/mod.rs b/crates/shirabe-external-packages/src/composer/xdebug_handler.rs index c95f237..c95f237 100644 --- a/crates/shirabe-external-packages/src/composer/xdebug_handler/mod.rs +++ b/crates/shirabe-external-packages/src/composer/xdebug_handler.rs diff --git a/crates/shirabe-external-packages/src/psr/mod.rs b/crates/shirabe-external-packages/src/psr.rs index 1e6bbb8..1e6bbb8 100644 --- a/crates/shirabe-external-packages/src/psr/mod.rs +++ b/crates/shirabe-external-packages/src/psr.rs diff --git a/crates/shirabe-external-packages/src/psr/log/mod.rs b/crates/shirabe-external-packages/src/psr/log.rs index 17d71b7..17d71b7 100644 --- a/crates/shirabe-external-packages/src/psr/log/mod.rs +++ b/crates/shirabe-external-packages/src/psr/log.rs diff --git a/crates/shirabe-external-packages/src/seld/mod.rs b/crates/shirabe-external-packages/src/seld.rs index b7c12c4..b7c12c4 100644 --- a/crates/shirabe-external-packages/src/seld/mod.rs +++ b/crates/shirabe-external-packages/src/seld.rs diff --git a/crates/shirabe-external-packages/src/seld/json_lint/mod.rs b/crates/shirabe-external-packages/src/seld/json_lint.rs index 8027cb2..8027cb2 100644 --- a/crates/shirabe-external-packages/src/seld/json_lint/mod.rs +++ b/crates/shirabe-external-packages/src/seld/json_lint.rs diff --git a/crates/shirabe-external-packages/src/seld/json_lint/json_parser.rs b/crates/shirabe-external-packages/src/seld/json_lint/json_parser.rs index 7cdf73b..317b4e5 100644 --- a/crates/shirabe-external-packages/src/seld/json_lint/json_parser.rs +++ b/crates/shirabe-external-packages/src/seld/json_lint/json_parser.rs @@ -1,13 +1,10 @@ //! ref: composer/vendor/seld/jsonlint/src/Seld/JsonLint/JsonParser.php -use std::collections::HashMap; - -use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; - use super::DuplicateKeyException; use super::ParsingException; use super::lexer::{Lexer, YylLoc}; +use indexmap::IndexMap; +use shirabe_php_shim::PhpMixed; /// Semantic value held on the parser value stack ($vstack). Most values are JSON values (PhpMixed), /// but object members are represented as a `[key, value]` pair while being reduced. @@ -42,10 +39,10 @@ enum ActionResult { #[derive(Debug)] pub struct JsonParser { - productions_: HashMap<i64, (i64, i64)>, - terminals_: HashMap<i64, &'static str>, - table: Vec<HashMap<i64, TableAction>>, - default_actions: HashMap<i64, (i64, i64)>, + productions_: IndexMap<i64, (i64, i64)>, + terminals_: IndexMap<i64, &'static str>, + table: Vec<IndexMap<i64, TableAction>>, + default_actions: IndexMap<i64, (i64, i64)>, } /// Per-parse mutable state. PHP keeps `$flags`/`$stack`/`$vstack`/`$lstack` on the parser instance; @@ -81,7 +78,7 @@ impl JsonParser { pub const ALLOW_DUPLICATE_KEYS_TO_ARRAY: u32 = 16; pub fn new() -> Self { - let productions_: HashMap<i64, (i64, i64)> = [ + let productions_: IndexMap<i64, (i64, i64)> = [ (1, (3, 1)), (2, (5, 1)), (3, (7, 1)), @@ -107,7 +104,7 @@ impl JsonParser { .into_iter() .collect(); - let terminals_: HashMap<i64, &'static str> = [ + let terminals_: IndexMap<i64, &'static str> = [ (2, "error"), (4, "STRING"), (6, "NUMBER"), @@ -127,7 +124,7 @@ impl JsonParser { let table = build_table(); - let default_actions: HashMap<i64, (i64, i64)> = [(16, (2, 6))].into_iter().collect(); + let default_actions: IndexMap<i64, (i64, i64)> = [(16, (2, 6))].into_iter().collect(); Self { productions_, @@ -790,9 +787,9 @@ fn trim_bytes(input: &[u8]) -> Vec<u8> { } /// Builds the LALR parse `table`. Indexed by state id (0..=31). -fn build_table() -> Vec<HashMap<i64, TableAction>> { +fn build_table() -> Vec<IndexMap<i64, TableAction>> { use TableAction::{Action, Goto}; - let mut t: Vec<HashMap<i64, TableAction>> = (0..32).map(|_| HashMap::new()).collect(); + let mut t: Vec<IndexMap<i64, TableAction>> = (0..32).map(|_| IndexMap::new()).collect(); let mut set = |state: usize, entries: &[(i64, TableAction)]| { for (sym, act) in entries { diff --git a/crates/shirabe-external-packages/src/seld/signal/mod.rs b/crates/shirabe-external-packages/src/seld/signal.rs index 16f5151..16f5151 100644 --- a/crates/shirabe-external-packages/src/seld/signal/mod.rs +++ b/crates/shirabe-external-packages/src/seld/signal.rs diff --git a/crates/shirabe-external-packages/src/symfony/mod.rs b/crates/shirabe-external-packages/src/symfony.rs index 9c572b2..9c572b2 100644 --- a/crates/shirabe-external-packages/src/symfony/mod.rs +++ b/crates/shirabe-external-packages/src/symfony.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/mod.rs b/crates/shirabe-external-packages/src/symfony/console.rs index 986c9ca..986c9ca 100644 --- a/crates/shirabe-external-packages/src/symfony/console/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/attribute/mod.rs b/crates/shirabe-external-packages/src/symfony/console/attribute.rs index 241eb67..241eb67 100644 --- a/crates/shirabe-external-packages/src/symfony/console/attribute/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/attribute.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/command/mod.rs b/crates/shirabe-external-packages/src/symfony/console/command.rs index b17d7f5..b17d7f5 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs b/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs index 3ed968e..7df1f80 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command/complete_command.rs @@ -1,11 +1,5 @@ //! ref: composer/vendor/symfony/console/Command/CompleteCommand.php -use indexmap::IndexMap; -use shirabe_php_shim::PhpMixed; -use std::cell::RefCell; -use std::ops::{Deref, DerefMut}; -use std::rc::Rc; - use crate::symfony::console::command::command::{Command, CommandData}; use crate::symfony::console::completion::completion_input::CompletionInput; use crate::symfony::console::completion::completion_suggestions::{ @@ -15,6 +9,11 @@ use crate::symfony::console::completion::output::completion_output_interface::Co use crate::symfony::console::input::input_interface::InputInterface; use crate::symfony::console::input::input_option::InputOption; use crate::symfony::console::output::output_interface::OutputInterface; +use indexmap::IndexMap; +use shirabe_php_shim::PhpMixed; +use std::cell::RefCell; +use std::ops::{Deref, DerefMut}; +use std::rc::Rc; /// Responsible for providing the values to the shell completion. #[derive(Debug)] diff --git a/crates/shirabe-external-packages/src/symfony/console/command_loader/mod.rs b/crates/shirabe-external-packages/src/symfony/console/command_loader.rs index 97b3f54..97b3f54 100644 --- a/crates/shirabe-external-packages/src/symfony/console/command_loader/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/command_loader.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/completion/mod.rs b/crates/shirabe-external-packages/src/symfony/console/completion.rs index cb7f1d1..cb7f1d1 100644 --- a/crates/shirabe-external-packages/src/symfony/console/completion/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/completion.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs b/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs index fe979cd..e0b8e09 100644 --- a/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/completion/completion_input.rs @@ -1,10 +1,9 @@ //! ref: composer/vendor/symfony/console/Completion/CompletionInput.php -use shirabe_php_shim::PhpMixed; - use crate::symfony::console::input::argv_input::ArgvInput; use crate::symfony::console::input::input_definition::InputDefinition; use crate::symfony::console::input::input_option::InputOption; +use shirabe_php_shim::PhpMixed; /// An input specialized for shell completion. /// diff --git a/crates/shirabe-external-packages/src/symfony/console/completion/output/mod.rs b/crates/shirabe-external-packages/src/symfony/console/completion/output.rs index 6bb0a2e..6bb0a2e 100644 --- a/crates/shirabe-external-packages/src/symfony/console/completion/output/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/completion/output.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/descriptor/mod.rs b/crates/shirabe-external-packages/src/symfony/console/descriptor.rs index 9f85f92..9f85f92 100644 --- a/crates/shirabe-external-packages/src/symfony/console/descriptor/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/descriptor.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/exception/mod.rs b/crates/shirabe-external-packages/src/symfony/console/exception.rs index 356b595..356b595 100644 --- a/crates/shirabe-external-packages/src/symfony/console/exception/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/exception.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/formatter/mod.rs b/crates/shirabe-external-packages/src/symfony/console/formatter.rs index 716d3fb..716d3fb 100644 --- a/crates/shirabe-external-packages/src/symfony/console/formatter/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/formatter.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/mod.rs b/crates/shirabe-external-packages/src/symfony/console/helper.rs index 8aed672..8aed672 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs index 030fda4..d3731b1 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/debug_formatter_helper.rs @@ -158,7 +158,7 @@ impl DebugFormatterHelper { } fn get_border(&self, id: &str) -> String { - format!("<bg={}> </>", COLORS[self.started[id].border as usize],) + format!("<bg={}> </>", COLORS[self.started[id].border as usize]) } } diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs b/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs index e1dbd1e..e26915e 100644 --- a/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs +++ b/crates/shirabe-external-packages/src/symfony/console/helper/formatter_helper.rs @@ -16,7 +16,7 @@ pub struct FormatterHelper { impl FormatterHelper { /// Formats a message within a section. pub fn format_section(&self, section: &str, message: &str, style: &str) -> String { - format!("<{}>[{}]</{}> {}", style, section, style, message,) + format!("<{}>[{}]</{}> {}", style, section, style, message) } /// Formats a message as a block of text. @@ -60,7 +60,7 @@ impl FormatterHelper { let mut i = 0; while i < messages.len() { - messages[i] = format!("<{}>{}</{}>", style, messages[i].clone(), style,); + messages[i] = format!("<{}>{}</{}>", style, messages[i].clone(), style); i += 1; } diff --git a/crates/shirabe-external-packages/src/symfony/console/input/mod.rs b/crates/shirabe-external-packages/src/symfony/console/input.rs index d4813b4..d4813b4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs index c1a708a..ad06da7 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs @@ -317,7 +317,7 @@ impl ArgvInput { let option_name = self.inner.definition.negation_to_name(name)?; if !matches!(value, PhpMixed::Null) { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: format!("The \"--{}\" option does not accept a value.", name,), + message: format!("The \"--{}\" option does not accept a value.", name), code: 0, }) .into()); @@ -333,7 +333,7 @@ impl ArgvInput { if !matches!(value, PhpMixed::Null) && !option.accept_value() { return Err(RuntimeException(shirabe_php_shim::RuntimeException { - message: format!("The \"--{}\" option does not accept a value.", name,), + message: format!("The \"--{}\" option does not accept a value.", name), code: 0, }) .into()); diff --git a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs index 051d8bd..eeea48c 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs @@ -259,7 +259,7 @@ impl ArrayInput { if option.is_value_required() { return Err(InvalidOptionException(InvalidArgumentException( shirabe_php_shim::InvalidArgumentException { - message: format!("The \"--{}\" option requires a value.", name,), + message: format!("The \"--{}\" option requires a value.", name), code: 0, }, )) diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs index a1d3d30..279811f 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input_definition.rs @@ -260,14 +260,14 @@ impl InputDefinition { && !option.equals(existing) { return Err(LogicException(shirabe_php_shim::LogicException { - message: format!("An option named \"{}\" already exists.", option.get_name(),), + message: format!("An option named \"{}\" already exists.", option.get_name()), code: 0, }) .into()); } if self.negations.contains_key(option.get_name()) { return Err(LogicException(shirabe_php_shim::LogicException { - message: format!("An option named \"{}\" already exists.", option.get_name(),), + message: format!("An option named \"{}\" already exists.", option.get_name()), code: 0, }) .into()); diff --git a/crates/shirabe-external-packages/src/symfony/console/output/mod.rs b/crates/shirabe-external-packages/src/symfony/console/output.rs index 23a8e15..23a8e15 100644 --- a/crates/shirabe-external-packages/src/symfony/console/output/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/output.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/question/mod.rs b/crates/shirabe-external-packages/src/symfony/console/question.rs index 06d03b4..06d03b4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/signal_registry/mod.rs b/crates/shirabe-external-packages/src/symfony/console/signal_registry.rs index a07ca01..a07ca01 100644 --- a/crates/shirabe-external-packages/src/symfony/console/signal_registry/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/signal_registry.rs diff --git a/crates/shirabe-external-packages/src/symfony/console/style/mod.rs b/crates/shirabe-external-packages/src/symfony/console/style.rs index efc54e1..efc54e1 100644 --- a/crates/shirabe-external-packages/src/symfony/console/style/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/style.rs diff --git a/crates/shirabe-external-packages/src/symfony/filesystem/mod.rs b/crates/shirabe-external-packages/src/symfony/filesystem.rs index 24be2ed..24be2ed 100644 --- a/crates/shirabe-external-packages/src/symfony/filesystem/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/filesystem.rs diff --git a/crates/shirabe-external-packages/src/symfony/filesystem/exception/mod.rs b/crates/shirabe-external-packages/src/symfony/filesystem/exception.rs index 2c19405..2c19405 100644 --- a/crates/shirabe-external-packages/src/symfony/filesystem/exception/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/filesystem/exception.rs diff --git a/crates/shirabe-external-packages/src/symfony/finder/mod.rs b/crates/shirabe-external-packages/src/symfony/finder.rs index 4b2d4b8..4b2d4b8 100644 --- a/crates/shirabe-external-packages/src/symfony/finder/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/finder.rs diff --git a/crates/shirabe-external-packages/src/symfony/finder/finder.rs b/crates/shirabe-external-packages/src/symfony/finder/finder.rs index 95ca5a4..2a7e544 100644 --- a/crates/shirabe-external-packages/src/symfony/finder/finder.rs +++ b/crates/shirabe-external-packages/src/symfony/finder/finder.rs @@ -9,10 +9,9 @@ use crate::composer::pcre::{CaptureKey, Preg}; use crate::symfony::finder::glob::Glob; use chrono::{NaiveDate, NaiveDateTime}; -use indexmap::IndexMap; +use indexmap::{IndexMap, IndexSet}; use shirabe_php_shim::{file_exists, glob, is_dir, preg_quote, rtrim}; use std::cell::RefCell; -use std::collections::HashSet; use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; @@ -448,7 +447,7 @@ impl Finder { relative_dir: &str, depth: i64, max_depth: i64, - excluded_dirs: &HashSet<String>, + excluded_dirs: &IndexSet<String>, excluded_pattern: &Option<String>, out: &mut Vec<Entry>, ) { @@ -553,8 +552,8 @@ impl Finder { /// Reproduces `ExcludeDirectoryFilterIterator`'s constructor split between simple /// directory names and `/`-containing path patterns. -fn build_exclude(directories: &[String]) -> (HashSet<String>, Option<String>) { - let mut excluded_dirs = HashSet::new(); +fn build_exclude(directories: &[String]) -> (IndexSet<String>, Option<String>) { + let mut excluded_dirs = IndexSet::new(); let mut patterns: Vec<String> = Vec::new(); for directory in directories { @@ -579,7 +578,7 @@ fn build_exclude(directories: &[String]) -> (HashSet<String>, Option<String>) { /// `ExcludeDirectoryFilterIterator::accept`. fn exclude_accept( entry: &Entry, - excluded_dirs: &HashSet<String>, + excluded_dirs: &IndexSet<String>, excluded_pattern: &Option<String>, ) -> bool { if excluded_dirs.contains(&entry.filename) && entry.is_dir { diff --git a/crates/shirabe-external-packages/src/symfony/process/mod.rs b/crates/shirabe-external-packages/src/symfony/process.rs index 15967be..15967be 100644 --- a/crates/shirabe-external-packages/src/symfony/process/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/process.rs 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/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 { diff --git a/crates/shirabe-external-packages/src/symfony/string/mod.rs b/crates/shirabe-external-packages/src/symfony/string.rs index 139d726..139d726 100644 --- a/crates/shirabe-external-packages/src/symfony/string/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/string.rs |
