aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-symfony-console/src/descriptor/descriptor.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-09 11:19:03 +0900
committernsfisis <nsfisis@gmail.com>2026-08-09 11:19:03 +0900
commit6051927c8fa32cfffa102d2a170c5a6cf747a1b9 (patch)
tree3fe6769c90cb03ca8f1b9b825e38ad459182361e /crates/shirabe-symfony-console/src/descriptor/descriptor.rs
parente3e8806aec771e482899ed3470e920f7b291fa95 (diff)
downloadphp-shirabe-6051927c8fa32cfffa102d2a170c5a6cf747a1b9.tar.gz
php-shirabe-6051927c8fa32cfffa102d2a170c5a6cf747a1b9.tar.zst
php-shirabe-6051927c8fa32cfffa102d2a170c5a6cf747a1b9.zip
refactor(symfony-console): extract symfony/console into the shirabe-symfony-console crate
Move `Symfony\Component\Console` out of shirabe-external-packages and into its own crate, so the path is `shirabe_symfony_console::application::Application` instead of `shirabe_external_packages::symfony::console::application::Application`. The `delegate_to_inner!` and `delegate_command_trait_impls_to_inner!` macros move with it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-symfony-console/src/descriptor/descriptor.rs')
-rw-r--r--crates/shirabe-symfony-console/src/descriptor/descriptor.rs97
1 files changed, 97 insertions, 0 deletions
diff --git a/crates/shirabe-symfony-console/src/descriptor/descriptor.rs b/crates/shirabe-symfony-console/src/descriptor/descriptor.rs
new file mode 100644
index 00000000..f3647d7c
--- /dev/null
+++ b/crates/shirabe-symfony-console/src/descriptor/descriptor.rs
@@ -0,0 +1,97 @@
+//! ref: composer/vendor/symfony/console/Descriptor/Descriptor.php
+
+use crate::application::Application;
+use crate::command::command::Command;
+use crate::descriptor::descriptor_interface::{DescribableObject, DescriptorInterface};
+use crate::input::input_argument::InputArgument;
+use crate::input::input_definition::InputDefinition;
+use crate::input::input_option::InputOption;
+use crate::output::output_interface::OutputInterface;
+use indexmap::IndexMap;
+use shirabe_php_shim::PhpMixed;
+
+/// @internal
+pub trait Descriptor: DescriptorInterface {
+ fn output(&self) -> std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>;
+
+ fn set_output(&mut self, output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>);
+
+ fn describe(
+ &mut self,
+ output: std::rc::Rc<std::cell::RefCell<dyn OutputInterface>>,
+ object: DescribableObject,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<()> {
+ self.set_output(output);
+
+ // PHP dispatches via `$object instanceof ...`; the explicit `DescribableObject` enum makes
+ // that dispatch a `match`.
+ match object {
+ DescribableObject::InputArgument(argument) => {
+ self.describe_input_argument(&argument, options)?;
+ }
+ DescribableObject::InputOption(option) => {
+ self.describe_input_option(&option, options)?;
+ }
+ DescribableObject::InputDefinition(definition) => {
+ self.describe_input_definition(&definition, options)?;
+ }
+ DescribableObject::Command(command) => {
+ self.describe_command(&*command.borrow(), options)?;
+ }
+ DescribableObject::Application(application) => {
+ self.describe_application(application, options)?;
+ }
+ }
+
+ Ok(())
+ }
+
+ /// Writes content to output.
+ fn write(&self, content: &str, decorated: bool) {
+ self.output().borrow().write(
+ &[content.to_string()],
+ false,
+ if decorated {
+ crate::output::output_interface::OUTPUT_NORMAL
+ } else {
+ crate::output::output_interface::OUTPUT_RAW
+ },
+ );
+ }
+
+ /// Describes an InputArgument instance.
+ fn describe_input_argument(
+ &mut self,
+ argument: &InputArgument,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<()>;
+
+ /// Describes an InputOption instance.
+ fn describe_input_option(
+ &mut self,
+ option: &InputOption,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<()>;
+
+ /// Describes an InputDefinition instance.
+ fn describe_input_definition(
+ &mut self,
+ definition: &InputDefinition,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<()>;
+
+ /// Describes a Command instance.
+ fn describe_command(
+ &mut self,
+ command: &dyn Command,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<()>;
+
+ /// Describes an Application instance.
+ fn describe_application(
+ &mut self,
+ application: std::rc::Rc<std::cell::RefCell<dyn Application>>,
+ options: IndexMap<String, PhpMixed>,
+ ) -> anyhow::Result<()>;
+}