diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-24 00:47:20 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-24 00:47:53 +0900 |
| commit | 340164c64e90d44b1bdf620b514166db1f76cc98 (patch) | |
| tree | 86195fe5ff8582b64e0324e9f40619e36c04948f /crates/shirabe-php-shim/src/stream.rs | |
| parent | 8fe3390d064303b86133a1d2983144a4818a7121 (diff) | |
| download | php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.tar.gz php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.tar.zst php-shirabe-340164c64e90d44b1bdf620b514166db1f76cc98.zip | |
test: port more unimplemented tests
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/stream.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/stream.rs | 80 |
1 files changed, 78 insertions, 2 deletions
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 { |
