aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/question/strict_confirmation_question.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-24 00:49:51 +0900
committernsfisis <nsfisis@gmail.com>2026-06-24 00:49:51 +0900
commit27c961ee7bee5c775e1902e59f74a9871d31321d (patch)
treede18246316956b7fd91c07c616d855819351c387 /crates/shirabe/src/question/strict_confirmation_question.rs
parent340164c64e90d44b1bdf620b514166db1f76cc98 (diff)
downloadphp-shirabe-27c961ee7bee5c775e1902e59f74a9871d31321d.tar.gz
php-shirabe-27c961ee7bee5c775e1902e59f74a9871d31321d.tar.zst
php-shirabe-27c961ee7bee5c775e1902e59f74a9871d31321d.zip
feat(question): model Question hierarchy via QuestionInterface trait
Introduce a QuestionInterface trait that the base Question and all its subclasses (ChoiceQuestion, ConfirmationQuestion, StrictConfirmationQuestion) implement, with as_choice/as_confirmation downcasts standing in for PHP's instanceof. Consumers (QuestionHelper, SymfonyQuestionHelper, SymfonyStyle, ConsoleIO) now take a QuestionInterface boundary generically. This fixes the instanceof emulation, which previously went through as_any().downcast_ref on a concrete &Question and always returned None, and unblocks the select/confirm/choice paths that were left as todo!() because a polymorphic ChoiceQuestion/ConfirmationQuestion could not be passed to ask. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/question/strict_confirmation_question.rs')
-rw-r--r--crates/shirabe/src/question/strict_confirmation_question.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/crates/shirabe/src/question/strict_confirmation_question.rs b/crates/shirabe/src/question/strict_confirmation_question.rs
index 8d4239b..a464d65 100644
--- a/crates/shirabe/src/question/strict_confirmation_question.rs
+++ b/crates/shirabe/src/question/strict_confirmation_question.rs
@@ -3,8 +3,10 @@
use shirabe_external_packages::composer::pcre::Preg;
use shirabe_external_packages::symfony::console::exception::InvalidArgumentException;
use shirabe_external_packages::symfony::console::question::Question;
+use shirabe_external_packages::symfony::console::question::QuestionInterface;
use shirabe_php_shim::{PhpMixed, empty, is_bool};
+#[derive(Debug)]
pub struct StrictConfirmationQuestion {
inner: Question,
true_answer_regex: String,
@@ -80,3 +82,54 @@ impl StrictConfirmationQuestion {
})
}
}
+
+// PHP: `class StrictConfirmationQuestion extends Question` (not ConfirmationQuestion),
+// so it is not an instanceof ChoiceQuestion/ConfirmationQuestion and keeps the default
+// downcasts returning None.
+impl QuestionInterface for StrictConfirmationQuestion {
+ 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()
+ }
+}