diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-14 00:15:52 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-14 00:15:52 +0900 |
| commit | fe15d4dba4530f574856a6c443a3f665aa5abe7a (patch) | |
| tree | d7dc0433e40a2c38c50daf399ec8a3de5c2ac307 /crates/shirabe-external-packages | |
| parent | e165b2ffa32e21c50787ae7227dc5333131d1414 (diff) | |
| download | php-shirabe-fe15d4dba4530f574856a6c443a3f665aa5abe7a.tar.gz php-shirabe-fe15d4dba4530f574856a6c443a3f665aa5abe7a.tar.zst php-shirabe-fe15d4dba4530f574856a6c443a3f665aa5abe7a.zip | |
feat(console): implement get_command_name_before_binding via input clone
Replace the todo!() stub with the real Symfony logic: clone the input,
bind it against the application definition (ignoring binding errors), and
read the first argument so the command name is detected even when global
options precede it.
Add a dup() method to InputInterface to model PHP's clone, derive Clone on
the input types, and treat InvalidArgument/InvalidOption/MissingInput as
ignorable ExceptionInterface errors during the pre-binding probe.
Diffstat (limited to 'crates/shirabe-external-packages')
5 files changed, 19 insertions, 4 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs index 765f601..4772cdb 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/argv_input.rs @@ -24,7 +24,7 @@ use shirabe_php_shim::PhpMixed; /// When passing an argument to the constructor, be sure that it respects /// the same rules as the argv one. It's almost always better to use the /// `StringInput` when you want to provide your own input. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ArgvInput { pub(crate) inner: Input, tokens: Vec<String>, @@ -543,6 +543,10 @@ impl ArgvInput { } impl InputInterface for ArgvInput { + fn dup(&self) -> std::rc::Rc<std::cell::RefCell<dyn InputInterface>> { + std::rc::Rc::new(std::cell::RefCell::new(self.clone())) + } + fn get_first_argument(&self) -> Option<String> { ArgvInput::get_first_argument(self) } diff --git a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs index ccc1916..705c997 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/array_input.rs @@ -14,7 +14,7 @@ use shirabe_php_shim::PhpMixed; /// /// PHP arrays can mix integer and string keys; `parameters` preserves both the /// key type (`PhpMixed::Int` / `PhpMixed::String`) and the insertion order. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ArrayInput { pub(crate) inner: Input, parameters: Vec<(PhpMixed, PhpMixed)>, @@ -298,6 +298,10 @@ impl ArrayInput { } impl InputInterface for ArrayInput { + fn dup(&self) -> std::rc::Rc<std::cell::RefCell<dyn InputInterface>> { + std::rc::Rc::new(std::cell::RefCell::new(self.clone())) + } + fn get_first_argument(&self) -> Option<String> { ArrayInput::get_first_argument(self).map(|v| shirabe_php_shim::php_to_string(&v)) } diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input.rs b/crates/shirabe-external-packages/src/symfony/console/input/input.rs index 2c9a3a6..2881ccb 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input.rs @@ -11,7 +11,7 @@ use shirabe_php_shim::PhpMixed; /// * `ArgvInput`: The input comes from the CLI arguments (argv) /// * `StringInput`: The input is provided as a string /// * `ArrayInput`: The input is provided as an array -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Input { pub(crate) definition: InputDefinition, pub(crate) stream: PhpMixed, diff --git a/crates/shirabe-external-packages/src/symfony/console/input/input_interface.rs b/crates/shirabe-external-packages/src/symfony/console/input/input_interface.rs index d271845..09ffd26 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/input_interface.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/input_interface.rs @@ -2,6 +2,9 @@ use crate::symfony::console::input::input_definition::InputDefinition; use shirabe_php_shim::PhpMixed; pub trait InputInterface: std::fmt::Debug + shirabe_php_shim::AsAny { + /// Models PHP's `clone` operatior. + fn dup(&self) -> std::rc::Rc<std::cell::RefCell<dyn InputInterface>>; + fn get_first_argument(&self) -> Option<String>; fn has_parameter_option(&self, values: PhpMixed, only_params: bool) -> bool; diff --git a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs index bbc9e86..4f2a045 100644 --- a/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs +++ b/crates/shirabe-external-packages/src/symfony/console/input/string_input.rs @@ -10,7 +10,7 @@ use shirabe_php_shim::PhpMixed; /// Usage: /// /// $input = new StringInput('foo --bar="foobar"'); -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct StringInput { pub(crate) inner: ArgvInput, } @@ -122,6 +122,10 @@ impl StringInput { } impl InputInterface for StringInput { + fn dup(&self) -> std::rc::Rc<std::cell::RefCell<dyn InputInterface>> { + std::rc::Rc::new(std::cell::RefCell::new(self.clone())) + } + fn get_first_argument(&self) -> Option<String> { self.inner.get_first_argument() } |
