diff options
| -rw-r--r-- | crates/shirabe-php-shim/src/lib.rs | 83 | ||||
| -rw-r--r-- | crates/shirabe/src/dependency_resolver/rule_set_iterator.rs | 93 |
2 files changed, 176 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 5a77a4c..1a4da1c 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -83,6 +83,21 @@ pub struct InvalidArgumentException { pub code: i64, } +#[derive(Debug)] +pub struct LogicException { + pub message: String, + pub code: i64, +} + +#[derive(Debug)] +pub struct ErrorException { + pub message: String, + pub code: i64, + pub severity: i64, + pub filename: String, + pub lineno: i64, +} + pub fn is_bool(value: &PhpMixed) -> bool { todo!() } @@ -191,6 +206,7 @@ pub fn error_reporting(level: Option<i64>) -> i64 { todo!() } +pub const E_ALL: i64 = 32767; pub const E_WARNING: i64 = 2; pub const E_NOTICE: i64 = 8; pub const E_USER_WARNING: i64 = 512; @@ -301,6 +317,27 @@ impl ZipArchive { pub fn get_stream(&self, name: &str) -> Option<PhpMixed> { todo!() } + + pub fn add_empty_dir(&self, local_name: &str) -> bool { + todo!() + } + + pub fn add_file(&self, filepath: &str, local_name: &str) -> bool { + todo!() + } + + pub fn set_external_attributes_name(&self, name: &str, opsys: i64, attr: i64) -> bool { + todo!() + } + + pub fn get_status_string(&self) -> String { + todo!() + } +} + +impl ZipArchive { + pub const CREATE: i64 = 1; + pub const OPSYS_UNIX: i64 = 3; } pub trait JsonSerializable { @@ -331,6 +368,52 @@ pub fn chmod(path: &str, mode: u32) -> bool { todo!() } +pub fn strpbrk(haystack: &str, char_list: &str) -> Option<String> { + todo!() +} + +pub fn rawurldecode(s: &str) -> String { + todo!() +} + +pub fn rawurlencode(s: &str) -> String { + todo!() +} + +pub fn base64_encode(data: &str) -> String { + todo!() +} + +pub fn fileperms(path: &str) -> i64 { + todo!() +} + +pub const FILTER_VALIDATE_BOOLEAN: i64 = 258; + +pub fn filter_var(value: &str, filter: i64) -> bool { + todo!() +} + +pub fn ini_get(option: &str) -> Option<String> { + todo!() +} + +pub fn set_error_handler(callback: fn(i64, &str, &str, i64) -> bool) { + todo!() +} + +pub fn debug_backtrace() -> Vec<IndexMap<String, Box<PhpMixed>>> { + todo!() +} + +pub const PHP_VERSION: &str = "8.1.0"; + +pub const STDERR: i64 = 2; + +pub fn is_resource(value: &PhpMixed) -> bool { + todo!() +} + #[derive(Debug)] pub struct RarEntry; diff --git a/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs b/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs index 6012876..e2b67f4 100644 --- a/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs +++ b/crates/shirabe/src/dependency_resolver/rule_set_iterator.rs @@ -1 +1,94 @@ //! ref: composer/src/Composer/DependencyResolver/RuleSetIterator.php + +use indexmap::IndexMap; +use crate::dependency_resolver::rule::Rule; + +/// Implements PHP \Iterator over a grouped rule set. +#[derive(Debug)] +pub struct RuleSetIterator { + pub(crate) rules: IndexMap<i64, Vec<Rule>>, + pub(crate) types: Vec<i64>, + pub(crate) current_offset: i64, + pub(crate) current_type: i64, + pub(crate) current_type_offset: i64, +} + +impl RuleSetIterator { + pub fn new(rules: IndexMap<i64, Vec<Rule>>) -> Self { + let mut types: Vec<i64> = rules.keys().copied().collect(); + types.sort(); + let mut iter = Self { + rules, + types, + current_offset: 0, + current_type: -1, + current_type_offset: 0, + }; + iter.rewind(); + iter + } + + pub fn current(&self) -> &Rule { + &self.rules[&self.current_type][self.current_offset as usize] + } + + pub fn key(&self) -> i64 { + self.current_type + } + + pub fn next(&mut self) { + self.current_offset += 1; + + if !self.rules.contains_key(&self.current_type) { + return; + } + + if self.current_offset >= self.rules[&self.current_type].len() as i64 { + self.current_offset = 0; + + loop { + self.current_type_offset += 1; + + if self.types.get(self.current_type_offset as usize).is_none() { + self.current_type = -1; + break; + } + + self.current_type = self.types[self.current_type_offset as usize]; + + if self.rules[&self.current_type].len() != 0 { + break; + } + } + } + } + + pub fn rewind(&mut self) { + self.current_offset = 0; + self.current_type_offset = -1; + self.current_type = -1; + + loop { + self.current_type_offset += 1; + + if self.types.get(self.current_type_offset as usize).is_none() { + self.current_type = -1; + break; + } + + self.current_type = self.types[self.current_type_offset as usize]; + + if self.rules[&self.current_type].len() != 0 { + break; + } + } + } + + pub fn valid(&self) -> bool { + if let Some(rules) = self.rules.get(&self.current_type) { + rules.get(self.current_offset as usize).is_some() + } else { + false + } + } +} |
