diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-22 23:41:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-22 23:41:12 +0900 |
| commit | b291e714bc739262140323e08fe2fb9e91e00ee7 (patch) | |
| tree | c95f742064b9000e72b902f88e8905b4017d5dbc /crates/shirabe-external-packages/src/symfony/console/cursor.rs | |
| parent | 99ef82a9807578c1e5749156a027949efaba75c4 (diff) | |
| download | php-shirabe-b291e714bc739262140323e08fe2fb9e91e00ee7.tar.gz php-shirabe-b291e714bc739262140323e08fe2fb9e91e00ee7.tar.zst php-shirabe-b291e714bc739262140323e08fe2fb9e91e00ee7.zip | |
feat(php-shim): implement fopen-family stream API on PhpResource
Redesign PhpResource into a real stream handle (File/Memory backing with
tracked position, eof, closed state) and unify the whole fopen family
(fopen/fwrite/fread/fgets/fgetc/feof/fclose/ftell/fseek/rewind/fstat/
ftruncate/fflush and stream_get_contents/stream_copy_to_stream) on
&PhpResource, replacing the split PhpMixed/PhpResource APIs and their
todo!() stubs. fopen now returns Result; read functions stay String for
now (TODO(phase-e) to move to byte strings).
Propagate the signatures through callers: Process stdout/stderr, Cursor
input, curl header/body handles (extracted into typed maps keyed by job
id), Filesystem copy/safe_copy/files_are_equal, BufferIO, error_handler,
platform, perforce, zip. The proc_open pipe paths cannot carry a
PhpResource in a PhpMixed list, so they are left as todo!() with notes.
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/cursor.rs')
| -rw-r--r-- | crates/shirabe-external-packages/src/symfony/console/cursor.rs | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/cursor.rs b/crates/shirabe-external-packages/src/symfony/console/cursor.rs index 42efff7..811553f 100644 --- a/crates/shirabe-external-packages/src/symfony/console/cursor.rs +++ b/crates/shirabe-external-packages/src/symfony/console/cursor.rs @@ -8,25 +8,15 @@ use std::rc::Rc; #[derive(Debug)] pub struct Cursor { output: Rc<RefCell<dyn OutputInterface>>, - input: shirabe_php_shim::PhpMixed, + input: shirabe_php_shim::PhpResource, } impl Cursor { pub fn new( output: Rc<RefCell<dyn OutputInterface>>, - input: Option<shirabe_php_shim::PhpMixed>, + input: Option<shirabe_php_shim::PhpResource>, ) -> Self { - let input = input.unwrap_or_else(|| { - if shirabe_php_shim::defined("STDIN") { - // PHP uses the `STDIN` resource constant here, but the shim models it as - // `PhpResource` while this field is `PhpMixed` (which has no resource - // variant). Fall back to opening `php://input` so the value stays a - // PhpMixed stream handle. - shirabe_php_shim::fopen("php://input", "r+") - } else { - shirabe_php_shim::fopen("php://input", "r+") - } - }); + let input = input.unwrap_or(shirabe_php_shim::STDIN); Self { output, input } } @@ -228,10 +218,10 @@ impl Cursor { let stty_mode = shirabe_php_shim::shell_exec("stty -g"); shirabe_php_shim::shell_exec("stty -icanon -echo"); - shirabe_php_shim::fwrite(self.input.clone(), "\x1b[6n", 0); + shirabe_php_shim::fwrite(&self.input, "\x1b[6n", None); let code = shirabe_php_shim::trim( - shirabe_php_shim::fread(self.input.clone(), 1024) + shirabe_php_shim::fread(&self.input, 1024) .as_deref() .unwrap_or(""), None, |
