aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-php-shim')
-rw-r--r--crates/shirabe-php-shim/src/fs.rs5
-rw-r--r--crates/shirabe-php-shim/src/lib.rs14
-rw-r--r--crates/shirabe-php-shim/src/stream.rs80
-rw-r--r--crates/shirabe-php-shim/src/zip.rs4
4 files changed, 100 insertions, 3 deletions
diff --git a/crates/shirabe-php-shim/src/fs.rs b/crates/shirabe-php-shim/src/fs.rs
index ecbe5c4..f12d7bf 100644
--- a/crates/shirabe-php-shim/src/fs.rs
+++ b/crates/shirabe-php-shim/src/fs.rs
@@ -260,8 +260,11 @@ pub fn fopen(file: &str, mode: &str) -> Result<PhpResource, std::io::Error> {
StreamBacking::Memory(std::io::Cursor::new(Vec::new())),
readable,
writable,
+ mode.to_string(),
+ file.to_string(),
));
}
+ let uri = file.to_string();
let mut options = std::fs::OpenOptions::new();
match base_mode.as_str() {
"r" => options.read(true),
@@ -282,6 +285,8 @@ pub fn fopen(file: &str, mode: &str) -> Result<PhpResource, std::io::Error> {
StreamBacking::File(file),
readable,
writable,
+ mode.to_string(),
+ uri,
))
}
diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs
index 267c3b7..8eb8f2f 100644
--- a/crates/shirabe-php-shim/src/lib.rs
+++ b/crates/shirabe-php-shim/src/lib.rs
@@ -383,16 +383,28 @@ pub struct StreamState {
/// only reports true after a read has hit the end; cleared by a seek.
pub(crate) eof: bool,
pub(crate) closed: bool,
+ /// The mode string passed to `fopen`, reported back by `stream_get_meta_data`.
+ pub(crate) mode: String,
+ /// The path/URI the stream was opened from, reported back by `stream_get_meta_data`.
+ pub(crate) uri: String,
}
impl StreamState {
- pub(crate) fn new(backing: StreamBacking, readable: bool, writable: bool) -> PhpResource {
+ pub(crate) fn new(
+ backing: StreamBacking,
+ readable: bool,
+ writable: bool,
+ mode: String,
+ uri: String,
+ ) -> PhpResource {
PhpResource::Stream(std::rc::Rc::new(std::cell::RefCell::new(StreamState {
backing,
readable,
writable,
eof: false,
closed: false,
+ mode,
+ uri,
})))
}
}
diff --git a/crates/shirabe-php-shim/src/stream.rs b/crates/shirabe-php-shim/src/stream.rs
index 44ba0a4..5e43316 100644
--- a/crates/shirabe-php-shim/src/stream.rs
+++ b/crates/shirabe-php-shim/src/stream.rs
@@ -67,6 +67,14 @@ pub fn stream_context_create(
todo!()
}
+pub fn stream_context_get_options(_stream_or_context: &PhpMixed) -> IndexMap<String, PhpMixed> {
+ todo!()
+}
+
+pub fn stream_context_get_params(_stream_or_context: &PhpMixed) -> IndexMap<String, PhpMixed> {
+ todo!()
+}
+
pub fn stream_isatty(stream: PhpResource) -> bool {
stream_isatty_resource(&stream)
}
@@ -124,8 +132,76 @@ pub fn stream_isatty_resource(resource: &PhpResource) -> bool {
}
}
-pub fn stream_get_meta_data(_resource: &PhpResource) -> IndexMap<String, PhpMixed> {
- todo!()
+pub fn stream_get_meta_data(resource: &PhpResource) -> IndexMap<String, PhpMixed> {
+ // (timed_out, blocked, eof, wrapper_type, stream_type, mode, seekable, uri)
+ let (eof, wrapper_type, stream_type, mode, seekable, uri) = match resource {
+ PhpResource::Stdin => (false, "PHP", "STDIO", "r".to_string(), false, "php://stdin"),
+ PhpResource::Stdout => (
+ false,
+ "PHP",
+ "STDIO",
+ "w".to_string(),
+ false,
+ "php://stdout",
+ ),
+ PhpResource::Stderr => (
+ false,
+ "PHP",
+ "STDIO",
+ "w".to_string(),
+ false,
+ "php://stderr",
+ ),
+ PhpResource::Stream(state) => {
+ let state = state.borrow();
+ let (wrapper_type, stream_type) = match &state.backing {
+ StreamBacking::Memory(_) => {
+ if state.uri.starts_with("php://temp") {
+ ("PHP", "TEMP")
+ } else {
+ ("PHP", "MEMORY")
+ }
+ }
+ StreamBacking::File(_) => ("plainfile", "STDIO"),
+ };
+ return build_meta_data(
+ state.eof,
+ wrapper_type,
+ stream_type,
+ state.mode.clone(),
+ true,
+ &state.uri,
+ );
+ }
+ };
+ build_meta_data(eof, wrapper_type, stream_type, mode, seekable, uri)
+}
+
+fn build_meta_data(
+ eof: bool,
+ wrapper_type: &str,
+ stream_type: &str,
+ mode: String,
+ seekable: bool,
+ uri: &str,
+) -> IndexMap<String, PhpMixed> {
+ let mut map = IndexMap::new();
+ map.insert("timed_out".to_string(), PhpMixed::Bool(false));
+ map.insert("blocked".to_string(), PhpMixed::Bool(true));
+ map.insert("eof".to_string(), PhpMixed::Bool(eof));
+ map.insert(
+ "wrapper_type".to_string(),
+ PhpMixed::String(wrapper_type.to_string()),
+ );
+ map.insert(
+ "stream_type".to_string(),
+ PhpMixed::String(stream_type.to_string()),
+ );
+ map.insert("mode".to_string(), PhpMixed::String(mode));
+ map.insert("unread_bytes".to_string(), PhpMixed::Int(0));
+ map.insert("seekable".to_string(), PhpMixed::Bool(seekable));
+ map.insert("uri".to_string(), PhpMixed::String(uri.to_string()));
+ map
}
pub fn stream_set_blocking(_resource: &PhpResource, _enable: bool) -> bool {
diff --git a/crates/shirabe-php-shim/src/zip.rs b/crates/shirabe-php-shim/src/zip.rs
index 5ef99bb..08662e6 100644
--- a/crates/shirabe-php-shim/src/zip.rs
+++ b/crates/shirabe-php-shim/src/zip.rs
@@ -49,6 +49,10 @@ impl ZipArchive {
todo!()
}
+ pub fn get_from_name(&self, _name: &str) -> Option<String> {
+ todo!()
+ }
+
pub fn get_stream(&self, _name: &str) -> Option<crate::PhpResource> {
todo!()
}