diff options
Diffstat (limited to 'crates/shirabe-external-packages/src/symfony/console/question')
4 files changed, 213 insertions, 3 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs index 24d434d..b862eb8 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question/choice_question.rs @@ -3,6 +3,7 @@ use crate::symfony::console::exception::invalid_argument_exception::InvalidArgumentException; use crate::symfony::console::exception::logic_exception::LogicException; use crate::symfony::console::question::Question; +use crate::symfony::console::question::QuestionInterface; use indexmap::IndexMap; use shirabe_php_shim::PhpMixed; @@ -83,6 +84,16 @@ impl ChoiceQuestion { self } + /// Inherited from Question. Sets the maximum number of attempts. + pub fn set_max_attempts( + &mut self, + attempts: Option<i64>, + ) -> Result<&mut Self, InvalidArgumentException> { + self.inner.set_max_attempts(attempts)?; + + Ok(self) + } + /// Sets the error message for invalid values. /// /// The error message has a string placeholder (%s) for the invalid value. @@ -229,6 +240,58 @@ impl ChoiceQuestion { } } +impl QuestionInterface for ChoiceQuestion { + fn get_question(&self) -> &str { + self.inner.get_question() + } + + fn get_default(&self) -> PhpMixed { + self.inner.get_default() + } + + fn is_multiline(&self) -> bool { + self.inner.is_multiline() + } + + fn is_hidden(&self) -> bool { + self.inner.is_hidden() + } + + fn is_hidden_fallback(&self) -> bool { + self.inner.is_hidden_fallback() + } + + fn get_autocompleter_values(&self) -> Option<Vec<PhpMixed>> { + self.inner.get_autocompleter_values() + } + + fn get_autocompleter_callback(&self) -> Option<&(dyn Fn(&str) -> Option<Vec<PhpMixed>>)> { + self.inner.get_autocompleter_callback() + } + + fn get_validator( + &self, + ) -> Option<&(dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>)> { + self.inner.get_validator() + } + + fn get_max_attempts(&self) -> Option<i64> { + self.inner.get_max_attempts() + } + + fn get_normalizer(&self) -> Option<&(dyn Fn(PhpMixed) -> PhpMixed)> { + self.inner.get_normalizer() + } + + fn is_trimmable(&self) -> bool { + self.inner.is_trimmable() + } + + fn as_choice(&self) -> Option<&ChoiceQuestion> { + Some(self) + } +} + /// array_search operates over the choice values as strings; this projects the /// choices map's values into the string-keyed form the shim expects. fn choices_as_str(choices: &IndexMap<String, PhpMixed>) -> IndexMap<String, String> { diff --git a/crates/shirabe-external-packages/src/symfony/console/question/confirmation_question.rs b/crates/shirabe-external-packages/src/symfony/console/question/confirmation_question.rs index 5076d84..74039d0 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/confirmation_question.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question/confirmation_question.rs @@ -1,6 +1,8 @@ //! ref: composer/vendor/symfony/console/Question/ConfirmationQuestion.php +use crate::symfony::console::exception::invalid_argument_exception::InvalidArgumentException; use crate::symfony::console::question::Question; +use crate::symfony::console::question::QuestionInterface; use shirabe_php_shim::PhpMixed; /// Represents a yes/no question. @@ -57,3 +59,55 @@ impl ConfirmationQuestion { }) } } + +impl QuestionInterface for ConfirmationQuestion { + fn get_question(&self) -> &str { + self.inner.get_question() + } + + fn get_default(&self) -> PhpMixed { + self.inner.get_default() + } + + fn is_multiline(&self) -> bool { + self.inner.is_multiline() + } + + fn is_hidden(&self) -> bool { + self.inner.is_hidden() + } + + fn is_hidden_fallback(&self) -> bool { + self.inner.is_hidden_fallback() + } + + fn get_autocompleter_values(&self) -> Option<Vec<PhpMixed>> { + self.inner.get_autocompleter_values() + } + + fn get_autocompleter_callback(&self) -> Option<&(dyn Fn(&str) -> Option<Vec<PhpMixed>>)> { + self.inner.get_autocompleter_callback() + } + + fn get_validator( + &self, + ) -> Option<&(dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>)> { + self.inner.get_validator() + } + + fn get_max_attempts(&self) -> Option<i64> { + self.inner.get_max_attempts() + } + + fn get_normalizer(&self) -> Option<&(dyn Fn(PhpMixed) -> PhpMixed)> { + self.inner.get_normalizer() + } + + fn is_trimmable(&self) -> bool { + self.inner.is_trimmable() + } + + fn as_confirmation(&self) -> Option<&ConfirmationQuestion> { + Some(self) + } +} diff --git a/crates/shirabe-external-packages/src/symfony/console/question/mod.rs b/crates/shirabe-external-packages/src/symfony/console/question/mod.rs index 06e0c2c..06d03b4 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question/mod.rs @@ -1,6 +1,6 @@ -pub mod choice_question; -pub mod confirmation_question; -pub mod question; +mod choice_question; +mod confirmation_question; +mod question; pub use choice_question::*; pub use confirmation_question::*; diff --git a/crates/shirabe-external-packages/src/symfony/console/question/question.rs b/crates/shirabe-external-packages/src/symfony/console/question/question.rs index 9ec3aef..c93a71e 100644 --- a/crates/shirabe-external-packages/src/symfony/console/question/question.rs +++ b/crates/shirabe-external-packages/src/symfony/console/question/question.rs @@ -2,8 +2,53 @@ use crate::symfony::console::exception::invalid_argument_exception::InvalidArgumentException; use crate::symfony::console::exception::logic_exception::LogicException; +use crate::symfony::console::question::choice_question::ChoiceQuestion; +use crate::symfony::console::question::confirmation_question::ConfirmationQuestion; use shirabe_php_shim::PhpMixed; +/// Polymorphic boundary for the Symfony Console Question hierarchy. +/// +/// PHP has no `QuestionInterface`; `Question` is a concrete class extended by +/// `ChoiceQuestion`/`ConfirmationQuestion`. Modelling those subclasses as +/// `inner: Question` composition loses subtype identity, so consumers that take +/// a `Question` and run `instanceof` checks are expressed here as a trait whose +/// `as_choice`/`as_confirmation` downcasts stand in for `instanceof`. +pub trait QuestionInterface: std::fmt::Debug { + fn get_question(&self) -> &str; + + fn get_default(&self) -> PhpMixed; + + fn is_multiline(&self) -> bool; + + fn is_hidden(&self) -> bool; + + fn is_hidden_fallback(&self) -> bool; + + fn get_autocompleter_values(&self) -> Option<Vec<PhpMixed>>; + + fn get_autocompleter_callback(&self) -> Option<&(dyn Fn(&str) -> Option<Vec<PhpMixed>>)>; + + fn get_validator( + &self, + ) -> Option<&(dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>)>; + + fn get_max_attempts(&self) -> Option<i64>; + + fn get_normalizer(&self) -> Option<&(dyn Fn(PhpMixed) -> PhpMixed)>; + + fn is_trimmable(&self) -> bool; + + /// Models `$question instanceof ChoiceQuestion`. + fn as_choice(&self) -> Option<&ChoiceQuestion> { + None + } + + /// Models `$question instanceof ConfirmationQuestion`. + fn as_confirmation(&self) -> Option<&ConfirmationQuestion> { + None + } +} + /// Represents a Question. pub struct Question { question: String, @@ -275,3 +320,51 @@ impl Question { self } } + +impl QuestionInterface for Question { + fn get_question(&self) -> &str { + self.get_question() + } + + fn get_default(&self) -> PhpMixed { + self.get_default() + } + + fn is_multiline(&self) -> bool { + self.is_multiline() + } + + fn is_hidden(&self) -> bool { + self.is_hidden() + } + + fn is_hidden_fallback(&self) -> bool { + self.is_hidden_fallback() + } + + fn get_autocompleter_values(&self) -> Option<Vec<PhpMixed>> { + self.get_autocompleter_values() + } + + fn get_autocompleter_callback(&self) -> Option<&(dyn Fn(&str) -> Option<Vec<PhpMixed>>)> { + self.get_autocompleter_callback() + } + + fn get_validator( + &self, + ) -> Option<&(dyn Fn(Option<PhpMixed>) -> Result<PhpMixed, InvalidArgumentException>)> { + self.get_validator() + } + + fn get_max_attempts(&self) -> Option<i64> { + self.get_max_attempts() + } + + fn get_normalizer(&self) -> Option<&(dyn Fn(PhpMixed) -> PhpMixed)> { + self.get_normalizer() + } + + fn is_trimmable(&self) -> bool { + self.is_trimmable() + } +} |
