aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/shirabe-php-shim/src/array.rs33
-rw-r--r--crates/shirabe-php-shim/src/fs.rs38
-rw-r--r--crates/shirabe-php-shim/src/openssl.rs29
-rw-r--r--crates/shirabe-php-shim/src/runtime.rs20
-rw-r--r--crates/shirabe-php-shim/src/stream.rs28
-rw-r--r--crates/shirabe-php-shim/src/string.rs47
-rw-r--r--crates/shirabe-php-shim/src/var.rs6
7 files changed, 1 insertions, 200 deletions
diff --git a/crates/shirabe-php-shim/src/array.rs b/crates/shirabe-php-shim/src/array.rs
index 86a78dd2..c4cb2d6e 100644
--- a/crates/shirabe-php-shim/src/array.rs
+++ b/crates/shirabe-php-shim/src/array.rs
@@ -395,14 +395,6 @@ pub fn array_splice<T>(
array.splice(start..end, replacement).collect()
}
-pub fn array_pop_first<T>(array: &mut Vec<T>) -> Option<T> {
- if array.is_empty() {
- None
- } else {
- Some(array.remove(0))
- }
-}
-
pub fn array_merge_recursive(arrays: Vec<PhpMixed>) -> PhpMixed {
let mut acc: Vec<(MergeKey, PhpMixed)> = Vec::new();
let mut next_int: i64 = 0;
@@ -533,17 +525,6 @@ where
_array.iter().map(_callback).collect()
}
-pub fn array_filter_use_key(
- _array: &IndexMap<String, PhpMixed>,
- _callback: Box<dyn Fn(&str) -> bool>,
-) -> IndexMap<String, PhpMixed> {
- _array
- .iter()
- .filter(|(k, _)| _callback(k.as_str()))
- .map(|(k, v)| (k.clone(), v.clone()))
- .collect()
-}
-
pub fn array_chunk<T: Clone>(_array: &[T], _size: i64, _preserve_keys: bool) -> Vec<Vec<T>> {
_array.chunks(_size as usize).map(|c| c.to_vec()).collect()
}
@@ -686,16 +667,6 @@ pub fn sort<T: Ord>(_array: &mut Vec<T>) {
_array.sort();
}
-pub fn sort_with_flags<T: Ord>(array: &mut [T], flags: i64) {
- if flags != SORT_REGULAR {
- // TODO(phase-c): flag-specific comparison (SORT_NUMERIC/SORT_STRING/
- // SORT_NATURAL/SORT_FLAG_CASE) cannot be expressed for a generic
- // `T: Ord` element. No caller passes a non-regular flag yet.
- todo!("sort() with flags other than SORT_REGULAR");
- }
- array.sort();
-}
-
pub const SORT_REGULAR: i64 = 0;
pub const SORT_NUMERIC: i64 = 1;
pub const SORT_STRING: i64 = 2;
@@ -744,10 +715,6 @@ pub fn sort_natural_flag_case(values: &mut [String]) {
values.sort_by(|a, b| crate::strnatcasecmp(a, b).cmp(&0));
}
-pub fn count_mixed(value: &PhpMixed) -> i64 {
- count(value) as i64
-}
-
pub fn count(value: &PhpMixed) -> usize {
match value {
PhpMixed::List(items) => items.len(),
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index 7a8114bb..b4010bb0 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -834,13 +834,6 @@ pub fn filemtime(_filename: impl AsRef<std::path::Path>) -> Option<i64> {
.map(|d| d.as_secs() as i64)
}
-pub fn fileowner(_filename: impl AsRef<std::path::Path>) -> Option<i64> {
- use std::os::unix::fs::MetadataExt;
- std::fs::metadata(_filename.as_ref())
- .ok()
- .map(|m| m.uid() as i64)
-}
-
pub fn unlink(path: impl AsRef<std::path::Path>) -> bool {
std::fs::remove_file(path).is_ok()
}
@@ -1028,29 +1021,6 @@ pub fn sys_get_temp_dir() -> String {
std::env::temp_dir().to_string_lossy().into_owned()
}
-pub fn tempnam(_dir: impl AsRef<std::path::Path>, _prefix: &str) -> Option<String> {
- use std::os::unix::fs::PermissionsExt;
- // TODO(phase-c): PHP falls back to the system temp dir when $dir is not writable; that fallback
- // is not implemented here.
- for _ in 0..1000 {
- let name = format!("{}{:08x}", _prefix, fastrand::u32(..));
- let path = _dir.as_ref().join(name);
- match std::fs::OpenOptions::new()
- .write(true)
- .create_new(true)
- .open(&path)
- {
- Ok(_) => {
- // PHP creates the file with 0600 permissions.
- let _ = std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o600));
- return path.to_str().map(ToOwned::to_owned);
- }
- Err(_) => continue,
- }
- }
- None
-}
-
// A directory-handle resource. This is a distinct resource kind from the byte streams modeled by
// PhpResource; readdir/closedir have no callers yet, so it only records the opened path.
// TODO(phase-c): give it real readdir/closedir behavior (cursor over the entries) when needed.
@@ -1111,14 +1081,6 @@ pub fn dirname(path: &str) -> String {
}
}
-pub fn dirname_levels(path: &str, levels: i64) -> String {
- let mut result = path.to_string();
- for _ in 0..levels {
- result = dirname(&result);
- }
- result
-}
-
pub fn basename(path: &str) -> String {
// PHP basename(): the trailing name component, after stripping trailing directory separators.
let trimmed = path.trim_end_matches(['/', '\\']);
diff --git a/crates/shirabe-php-shim/src/openssl.rs b/crates/shirabe-php-shim/src/openssl.rs
index 41dda0e3..d24caa63 100644
--- a/crates/shirabe-php-shim/src/openssl.rs
+++ b/crates/shirabe-php-shim/src/openssl.rs
@@ -11,32 +11,3 @@ pub fn openssl_x509_parse(
) -> Option<IndexMap<String, PhpMixed>> {
todo!()
}
-
-pub fn openssl_get_publickey(_certificate: &str) -> Option<PhpMixed> {
- todo!()
-}
-
-pub fn openssl_pkey_get_details(_key: PhpMixed) -> Option<IndexMap<String, PhpMixed>> {
- todo!()
-}
-
-pub fn openssl_verify(
- _data: &str,
- _signature: &[u8],
- _pub_key_id: PhpMixed,
- _algorithm: PhpMixed,
-) -> i64 {
- todo!()
-}
-
-pub fn openssl_pkey_get_public(_public_key: &str) -> PhpMixed {
- todo!()
-}
-
-pub fn openssl_get_md_methods() -> Vec<String> {
- todo!()
-}
-
-pub fn openssl_free_key(_key: PhpMixed) {
- todo!()
-}
diff --git a/crates/shirabe-php-shim/src/runtime.rs b/crates/shirabe-php-shim/src/runtime.rs
index ed159abb..b95c594f 100644
--- a/crates/shirabe-php-shim/src/runtime.rs
+++ b/crates/shirabe-php-shim/src/runtime.rs
@@ -368,11 +368,6 @@ pub fn require_php_file(_filename: &str) -> PhpMixed {
todo!()
}
-pub fn php_require(_file: &str) -> PhpMixed {
- // TODO(php-runtime): see require_php_file.
- todo!()
-}
-
pub fn memory_get_usage() -> i64 {
// TODO(phase-c): return PHP's actual emalloc-tracked memory usage instead of a stub 0.
0
@@ -407,21 +402,6 @@ pub fn error_get_last() -> Option<IndexMap<String, PhpMixed>> {
None
}
-pub fn globals_get(_name: &str) -> PhpMixed {
- // TODO(php-runtime): the PHP $GLOBALS superglobal is not modeled in the shim.
- todo!()
-}
-
-pub fn globals_set(_name: &str, _value: PhpMixed) {
- // TODO(php-runtime): the PHP $GLOBALS superglobal is not modeled in the shim.
- todo!()
-}
-
-pub fn clone<T: Clone>(_value: T) -> T {
- // PHP's `clone` makes a (shallow) copy of an object; Rust's Clone is the closest equivalent.
- _value
-}
-
pub fn ini_set(_varname: &str, _value: &str) -> Option<String> {
// TODO(php-runtime): ini_set must return the previous value and have its override observed by a
// subsequent ini_get; ini_get is currently a static lookup, so overrides cannot be wired up yet.
diff --git a/crates/shirabe-php-shim/src/stream.rs b/crates/shirabe-php-shim/src/stream.rs
index 50f984b5..daf4c0af 100644
--- a/crates/shirabe-php-shim/src/stream.rs
+++ b/crates/shirabe-php-shim/src/stream.rs
@@ -20,14 +20,6 @@ pub fn stream_resolve_include_path(filename: impl AsRef<std::path::Path>) -> Opt
todo!()
}
-/// PHP `stream_get_contents()` with an explicit max length.
-pub fn stream_get_contents_with_max(
- stream: &PhpResource,
- max_length: Option<i64>,
-) -> Option<String> {
- stream_read_remaining(stream, max_length)
-}
-
// Reads from the stream's current position: all remaining bytes, or up to `max_length` when given
// (a negative max means "until end").
fn stream_read_remaining(stream: &PhpResource, max_length: Option<i64>) -> Option<String> {
@@ -64,7 +56,7 @@ fn stream_read_remaining(stream: &PhpResource, max_length: Option<i64>) -> Optio
// A stream context is modeled as an object holding the two arrays PHP keeps for it: the per-wrapper
// `options` and the `params`. This is a self-contained value, so it round-trips through the
-// accessors below without any registry.
+// accessor below without any registry.
pub fn stream_context_create(
options: &IndexMap<String, PhpMixed>,
params: Option<&IndexMap<String, PhpMixed>>,
@@ -89,24 +81,6 @@ pub fn stream_context_get_options(stream_or_context: &PhpMixed) -> IndexMap<Stri
}
}
-pub fn stream_context_get_params(stream_or_context: &PhpMixed) -> IndexMap<String, PhpMixed> {
- let (options, params) = match stream_or_context {
- PhpMixed::Object(context) | PhpMixed::Array(context) => (
- context.get("options").cloned().unwrap_or_default(),
- context
- .get("params")
- .and_then(PhpMixed::as_array)
- .cloned()
- .unwrap_or_default(),
- ),
- _ => (PhpMixed::default(), IndexMap::new()),
- };
- // PHP exposes the wrapper options under an "options" key alongside the params.
- let mut result = params;
- result.insert("options".to_string(), options);
- result
-}
-
pub fn stream_isatty(stream: PhpResource) -> bool {
stream_isatty_resource(&stream)
}
diff --git a/crates/shirabe-php-shim/src/string.rs b/crates/shirabe-php-shim/src/string.rs
index 331a4ceb..575bc16d 100644
--- a/crates/shirabe-php-shim/src/string.rs
+++ b/crates/shirabe-php-shim/src/string.rs
@@ -834,53 +834,6 @@ fn php_to_float(v: &PhpMixed) -> f64 {
}
}
-pub fn html_entity_decode(_s: &str) -> String {
- // TODO(phase-c): only numeric entities and the most common named entities (the HTML 4.01 markup
- // set PHP enables by default) are decoded; the full named-entity table is not ported.
- let chars: Vec<char> = _s.chars().collect();
- let mut out = String::with_capacity(_s.len());
- let mut i = 0;
- while i < chars.len() {
- if chars[i] == '&' {
- if let Some(rel) = chars[i + 1..].iter().position(|&c| c == ';') {
- let entity: String = chars[i + 1..i + 1 + rel].iter().collect();
- if let Some(decoded) = decode_html_entity(&entity) {
- out.push_str(&decoded);
- i = i + 1 + rel + 1;
- continue;
- }
- }
- out.push('&');
- i += 1;
- } else {
- out.push(chars[i]);
- i += 1;
- }
- }
- out
-}
-
-fn decode_html_entity(entity: &str) -> Option<String> {
- if let Some(num) = entity.strip_prefix('#') {
- let code = if let Some(hex) = num.strip_prefix('x').or_else(|| num.strip_prefix('X')) {
- u32::from_str_radix(hex, 16).ok()?
- } else {
- num.parse::<u32>().ok()?
- };
- return char::from_u32(code).map(|c| c.to_string());
- }
- // PHP's default flags (ENT_QUOTES | ENT_HTML401) do not include the XML-only `apos`.
- let c = match entity {
- "amp" => '&',
- "lt" => '<',
- "gt" => '>',
- "quot" => '"',
- "nbsp" => '\u{00A0}',
- _ => return None,
- };
- Some(c.to_string())
-}
-
pub fn bin2hex(_data: &[u8]) -> String {
_data.iter().map(|b| format!("{:02x}", b)).collect()
}
diff --git a/crates/shirabe-php-shim/src/var.rs b/crates/shirabe-php-shim/src/var.rs
index 8697097d..af3c1b3b 100644
--- a/crates/shirabe-php-shim/src/var.rs
+++ b/crates/shirabe-php-shim/src/var.rs
@@ -206,12 +206,6 @@ pub fn loosely_compare(a: &str, b: &str) -> std::cmp::Ordering {
}
}
-pub fn instance_of<T>(_value: &PhpMixed) -> bool {
- // TODO(php-runtime): PHP `instanceof` needs the runtime class of the value, which PhpMixed::Object
- // does not carry.
- todo!()
-}
-
pub fn is_subclass_of(_object_or_class: &PhpMixed, _class_name: &str, _allow_string: bool) -> bool {
// TODO(php-runtime): requires runtime class ancestry, which PhpMixed::Object does not carry.
todo!()