diff options
Diffstat (limited to 'crates')
14 files changed, 5 insertions, 401 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/console_events.rs b/crates/shirabe-external-packages/src/symfony/console/console_events.rs deleted file mode 100644 index d316f8a..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/console_events.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! ref: composer/vendor/symfony/console/ConsoleEvents.php - -/// Contains all events dispatched by an Application. -#[derive(Debug)] -pub struct ConsoleEvents; - -impl ConsoleEvents { - /// The COMMAND event allows you to attach listeners before any command is - /// executed by the console. It also allows you to modify the command, input and output - /// before they are handed to the command. - pub const COMMAND: &'static str = "console.command"; - - /// The SIGNAL event allows you to perform some actions - /// after the command execution was interrupted. - pub const SIGNAL: &'static str = "console.signal"; - - /// The TERMINATE event allows you to attach listeners after a command is - /// executed by the console. - pub const TERMINATE: &'static str = "console.terminate"; - - /// The ERROR event occurs when an uncaught exception or error appears. - /// - /// This event allows you to deal with the exception/error or - /// to modify the thrown exception. - pub const ERROR: &'static str = "console.error"; - - /// Event aliases. These aliases can be consumed by RegisterListenersPass. - pub const ALIASES: &'static [(&'static str, &'static str)] = &[ - ( - "Symfony\\Component\\Console\\Event\\ConsoleCommandEvent", - Self::COMMAND, - ), - ( - "Symfony\\Component\\Console\\Event\\ConsoleErrorEvent", - Self::ERROR, - ), - ( - "Symfony\\Component\\Console\\Event\\ConsoleSignalEvent", - Self::SIGNAL, - ), - ( - "Symfony\\Component\\Console\\Event\\ConsoleTerminateEvent", - Self::TERMINATE, - ), - ]; -} diff --git a/crates/shirabe-external-packages/src/symfony/console/event/console_command_event.rs b/crates/shirabe-external-packages/src/symfony/console/event/console_command_event.rs deleted file mode 100644 index b20c84c..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/event/console_command_event.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! ref: composer/vendor/symfony/console/Event/ConsoleCommandEvent.php - -use super::console_event::ConsoleEvent; -use crate::symfony::console::command::command::Command; -use crate::symfony::console::input::input_interface::InputInterface; -use crate::symfony::console::output::output_interface::OutputInterface; - -/// Allows to do things before the command is executed, like skipping the command or -/// executing code before the command is going to be executed. -/// -/// Changing the input arguments will have no effect. -#[derive(Debug)] -pub struct ConsoleCommandEvent { - inner: ConsoleEvent, - command_should_run: bool, -} - -impl ConsoleCommandEvent { - pub const RETURN_CODE_DISABLED: i64 = 113; - - pub fn new( - command: Option<Box<dyn Command>>, - input: Box<dyn InputInterface>, - output: Box<dyn OutputInterface>, - ) -> Self { - Self { - inner: ConsoleEvent::new(command, input, output), - command_should_run: true, - } - } - - pub fn disable_command(&mut self) -> bool { - self.command_should_run = false; - self.command_should_run - } - - pub fn enable_command(&mut self) -> bool { - self.command_should_run = true; - self.command_should_run - } - - pub fn command_should_run(&self) -> bool { - self.command_should_run - } -} diff --git a/crates/shirabe-external-packages/src/symfony/console/event/console_error_event.rs b/crates/shirabe-external-packages/src/symfony/console/event/console_error_event.rs deleted file mode 100644 index 26bc908..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/event/console_error_event.rs +++ /dev/null @@ -1,54 +0,0 @@ -//! ref: composer/vendor/symfony/console/Event/ConsoleErrorEvent.php - -use super::console_event::ConsoleEvent; -use crate::symfony::console::command::command::Command; -use crate::symfony::console::input::input_interface::InputInterface; -use crate::symfony::console::output::output_interface::OutputInterface; - -#[derive(Debug)] -pub struct ConsoleErrorEvent { - inner: ConsoleEvent, - error: Box<dyn std::error::Error + Send + Sync>, - exit_code: Option<i64>, -} - -impl ConsoleErrorEvent { - pub fn new( - input: Box<dyn InputInterface>, - output: Box<dyn OutputInterface>, - error: Box<dyn std::error::Error + Send + Sync>, - command: Option<Box<dyn Command>>, - ) -> Self { - Self { - inner: ConsoleEvent::new(command, input, output), - error, - exit_code: None, - } - } - - pub fn get_error(&self) -> &(dyn std::error::Error + Send + Sync) { - self.error.as_ref() - } - - pub fn set_error(&mut self, error: Box<dyn std::error::Error + Send + Sync>) { - self.error = error; - } - - pub fn set_exit_code(&mut self, exit_code: i64) { - self.exit_code = Some(exit_code); - // TODO: The PHP implementation uses \ReflectionProperty to forcibly set the `code` - // field on the error object. This requires a Reflection API equivalent; review needed. - todo!("set error code via reflection equivalent") - } - - pub fn get_exit_code(&self) -> i64 { - match self.exit_code { - Some(code) => code, - None => { - // PHP: is_int($error->getCode()) && 0 !== $error->getCode() ? $error->getCode() : 1 - // Throwable::getCode() has no direct equivalent on std::error::Error. - todo!("retrieve error code from Throwable equivalent") - } - } - } -} diff --git a/crates/shirabe-external-packages/src/symfony/console/event/console_event.rs b/crates/shirabe-external-packages/src/symfony/console/event/console_event.rs deleted file mode 100644 index cade304..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/event/console_event.rs +++ /dev/null @@ -1,42 +0,0 @@ -//! ref: composer/vendor/symfony/console/Event/ConsoleEvent.php - -use crate::symfony::console::command::command::Command; -use crate::symfony::console::input::input_interface::InputInterface; -use crate::symfony::console::output::output_interface::OutputInterface; -use crate::symfony::contracts::event_dispatcher::event::Event; - -/// Allows to inspect input and output of a command. -#[derive(Debug)] -pub struct ConsoleEvent { - inner: Event, - pub(crate) command: Option<Box<dyn Command>>, - input: Box<dyn InputInterface>, - output: Box<dyn OutputInterface>, -} - -impl ConsoleEvent { - pub fn new( - command: Option<Box<dyn Command>>, - input: Box<dyn InputInterface>, - output: Box<dyn OutputInterface>, - ) -> Self { - Self { - inner: Event, - command, - input, - output, - } - } - - pub fn get_command(&self) -> Option<&dyn Command> { - self.command.as_deref() - } - - pub fn get_input(&self) -> &dyn InputInterface { - self.input.as_ref() - } - - pub fn get_output(&self) -> &dyn OutputInterface { - self.output.as_ref() - } -} diff --git a/crates/shirabe-external-packages/src/symfony/console/event/console_signal_event.rs b/crates/shirabe-external-packages/src/symfony/console/event/console_signal_event.rs deleted file mode 100644 index 6d9633c..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/event/console_signal_event.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! ref: composer/vendor/symfony/console/Event/ConsoleSignalEvent.php - -use super::console_event::ConsoleEvent; -use crate::symfony::console::command::command::Command; -use crate::symfony::console::input::input_interface::InputInterface; -use crate::symfony::console::output::output_interface::OutputInterface; - -#[derive(Debug)] -pub struct ConsoleSignalEvent { - inner: ConsoleEvent, - handling_signal: i64, -} - -impl ConsoleSignalEvent { - pub fn new( - command: Box<dyn Command>, - input: Box<dyn InputInterface>, - output: Box<dyn OutputInterface>, - handling_signal: i64, - ) -> Self { - Self { - inner: ConsoleEvent::new(Some(command), input, output), - handling_signal, - } - } - - pub fn get_handling_signal(&self) -> i64 { - self.handling_signal - } -} diff --git a/crates/shirabe-external-packages/src/symfony/console/event/console_terminate_event.rs b/crates/shirabe-external-packages/src/symfony/console/event/console_terminate_event.rs deleted file mode 100644 index cfa4f4f..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/event/console_terminate_event.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! ref: composer/vendor/symfony/console/Event/ConsoleTerminateEvent.php - -use super::console_event::ConsoleEvent; -use crate::symfony::console::command::command::Command; -use crate::symfony::console::input::input_interface::InputInterface; -use crate::symfony::console::output::output_interface::OutputInterface; - -/// Allows to manipulate the exit code of a command after its execution. -#[derive(Debug)] -pub struct ConsoleTerminateEvent { - inner: ConsoleEvent, - exit_code: i64, -} - -impl ConsoleTerminateEvent { - pub fn new( - command: Box<dyn Command>, - input: Box<dyn InputInterface>, - output: Box<dyn OutputInterface>, - exit_code: i64, - ) -> Self { - let mut instance = Self { - inner: ConsoleEvent::new(Some(command), input, output), - exit_code: 0, - }; - instance.set_exit_code(exit_code); - instance - } - - pub fn set_exit_code(&mut self, exit_code: i64) { - self.exit_code = exit_code; - } - - pub fn get_exit_code(&self) -> i64 { - self.exit_code - } -} diff --git a/crates/shirabe-external-packages/src/symfony/console/event/mod.rs b/crates/shirabe-external-packages/src/symfony/console/event/mod.rs deleted file mode 100644 index efc6b2d..0000000 --- a/crates/shirabe-external-packages/src/symfony/console/event/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub mod console_command_event; -pub mod console_error_event; -pub mod console_event; -pub mod console_signal_event; -pub mod console_terminate_event; - -pub use console_command_event::*; -pub use console_error_event::*; -pub use console_event::*; -pub use console_signal_event::*; -pub use console_terminate_event::*; diff --git a/crates/shirabe-external-packages/src/symfony/console/mod.rs b/crates/shirabe-external-packages/src/symfony/console/mod.rs index 688d21f..986c9ca 100644 --- a/crates/shirabe-external-packages/src/symfony/console/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/console/mod.rs @@ -4,10 +4,8 @@ pub mod color; pub mod command; pub mod command_loader; pub mod completion; -pub mod console_events; pub mod cursor; pub mod descriptor; -pub mod event; pub mod exception; pub mod formatter; pub mod helper; @@ -24,10 +22,8 @@ pub use color::*; pub use command::*; pub use command_loader::*; pub use completion::*; -pub use console_events::*; pub use cursor::*; pub use descriptor::*; -pub use event::*; pub use exception::*; pub use formatter::*; pub use helper::*; diff --git a/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/event.rs b/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/event.rs deleted file mode 100644 index ddf08a5..0000000 --- a/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/event.rs +++ /dev/null @@ -1,12 +0,0 @@ -#[derive(Debug)] -pub struct Event; - -impl Event { - pub fn is_propagation_stopped(&self) -> bool { - todo!() - } - - pub fn stop_propagation(&mut self) { - todo!() - } -} diff --git a/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/event_dispatcher_interface.rs b/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/event_dispatcher_interface.rs deleted file mode 100644 index f09b264..0000000 --- a/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/event_dispatcher_interface.rs +++ /dev/null @@ -1,6 +0,0 @@ -use shirabe_php_shim::PhpMixed; - -/// Mirror of PSR-14 / Symfony's `EventDispatcherInterface`. -pub trait EventDispatcherInterface: std::fmt::Debug { - fn dispatch(&self, event: PhpMixed, event_name: &str) -> PhpMixed; -} diff --git a/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/mod.rs b/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/mod.rs deleted file mode 100644 index 44a34e1..0000000 --- a/crates/shirabe-external-packages/src/symfony/contracts/event_dispatcher/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod event; -pub mod event_dispatcher_interface; - -pub use event::*; -pub use event_dispatcher_interface::*; diff --git a/crates/shirabe-external-packages/src/symfony/contracts/mod.rs b/crates/shirabe-external-packages/src/symfony/contracts/mod.rs deleted file mode 100644 index 36260a8..0000000 --- a/crates/shirabe-external-packages/src/symfony/contracts/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod event_dispatcher; - -pub use event_dispatcher::*; diff --git a/crates/shirabe-external-packages/src/symfony/mod.rs b/crates/shirabe-external-packages/src/symfony/mod.rs index e61fa72..e4feb6f 100644 --- a/crates/shirabe-external-packages/src/symfony/mod.rs +++ b/crates/shirabe-external-packages/src/symfony/mod.rs @@ -1,12 +1,10 @@ pub mod console; -pub mod contracts; pub mod filesystem; pub mod finder; pub mod process; pub mod string; pub use console::*; -pub use contracts::*; pub use filesystem::*; pub use finder::*; pub use process::*; diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index bc58297..00453f8 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -13,11 +13,6 @@ use shirabe_external_packages::symfony::console::command::signalable_command_int use shirabe_external_packages::symfony::console::command_loader::command_loader_interface::CommandLoaderInterface; use shirabe_external_packages::symfony::console::completion::completion_input::CompletionInput; use shirabe_external_packages::symfony::console::completion::completion_suggestions::CompletionSuggestions; -use shirabe_external_packages::symfony::console::console_events::ConsoleEvents; -use shirabe_external_packages::symfony::console::event::console_command_event::ConsoleCommandEvent; -use shirabe_external_packages::symfony::console::event::console_error_event::ConsoleErrorEvent; -use shirabe_external_packages::symfony::console::event::console_signal_event::ConsoleSignalEvent; -use shirabe_external_packages::symfony::console::event::console_terminate_event::ConsoleTerminateEvent; use shirabe_external_packages::symfony::console::exception::CommandNotFoundException; use shirabe_external_packages::symfony::console::exception::ExceptionInterface; use shirabe_external_packages::symfony::console::exception::invalid_argument_exception::InvalidArgumentException as ConsoleInvalidArgumentException; @@ -53,7 +48,6 @@ use shirabe_external_packages::symfony::console::signal_registry::signal_registr use shirabe_external_packages::symfony::console::style::style_interface::StyleInterface; use shirabe_external_packages::symfony::console::style::symfony_style::SymfonyStyle; use shirabe_external_packages::symfony::console::terminal::Terminal; -use shirabe_external_packages::symfony::contracts::event_dispatcher::event_dispatcher_interface::EventDispatcherInterface; use shirabe_external_packages::symfony::process::exception::ProcessTimedOutException; use shirabe_php_shim::{ LogicException as ShimLogicException, PHP_BINARY, PHP_VERSION, PHP_VERSION_ID, PhpMixed, @@ -136,7 +130,6 @@ pub struct Application { auto_exit: bool, definition: Option<std::rc::Rc<std::cell::RefCell<InputDefinition>>>, helper_set: Option<std::rc::Rc<std::cell::RefCell<HelperSet>>>, - dispatcher: Option<std::rc::Rc<std::cell::RefCell<dyn EventDispatcherInterface>>>, terminal: Terminal, default_command: String, single_command: bool, @@ -207,7 +200,6 @@ impl Application { auto_exit: true, definition: None, helper_set: None, - dispatcher: None, terminal: Terminal::new(), default_command: "list".to_string(), single_command: false, @@ -1298,15 +1290,6 @@ impl Application { /// are carried here under a `base_` prefix (`base_run`, `base_do_run`, `base_get_help`, /// `base_get_default_input_definition`, `base_get_default_commands`). impl Application { - /// @final - pub fn set_dispatcher( - &mut self, - dispatcher: std::rc::Rc<std::cell::RefCell<dyn EventDispatcherInterface>>, - ) { - // TODO(plugin): the event dispatcher drives ConsoleEvents listeners (plugins). - self.dispatcher = Some(dispatcher); - } - pub fn set_command_loader(&mut self, command_loader: Box<dyn CommandLoaderInterface>) { self.command_loader = Some(command_loader); } @@ -1515,29 +1498,6 @@ impl Application { }; if single_alternative.is_none() || !input.borrow().is_interactive() { - let mut e = e; - if self.dispatcher.is_some() { - // TODO(plugin): dispatch ConsoleErrorEvent so listeners can handle/replace the error. - let _event = ConsoleErrorEvent::new( - todo!("wrap input as Box<dyn InputInterface> for the event"), - todo!("wrap output as Box<dyn OutputInterface> for the event"), - todo!("wrap anyhow::Error as Box<dyn Error> for the event"), - None, - ); - let event: ConsoleErrorEvent = _event; - self.dispatcher - .as_ref() - .unwrap() - .borrow_mut() - .dispatch(todo!("event object"), ConsoleEvents::ERROR); - - if event.get_exit_code() == 0 { - return Ok(0); - } - - e = todo!("event.get_error() converted back to anyhow::Error"); - } - return Err(e); } @@ -1565,23 +1525,6 @@ impl Application { ), false, ) { - if self.dispatcher.is_some() { - // TODO(plugin): dispatch ConsoleErrorEvent for the declined-alternative case. - let event = ConsoleErrorEvent::new( - todo!("wrap input as Box<dyn InputInterface>"), - todo!("wrap output as Box<dyn OutputInterface>"), - todo!("wrap error as Box<dyn Error>"), - None, - ); - self.dispatcher - .as_ref() - .unwrap() - .borrow_mut() - .dispatch(todo!("event object"), ConsoleEvents::ERROR); - - return Ok(event.get_exit_code()); - } - return Ok(1); } @@ -2471,7 +2414,7 @@ impl Application { let command_signals: Vec<i64> = Vec::new(); let _ = std::marker::PhantomData::<dyn SignalableCommandInterface>; - if !command_signals.is_empty() || self.dispatcher.is_some() { + if !command_signals.is_empty() { if self.signal_registry.is_none() { return Err(ConsoleRuntimeException(shirabe_php_shim::RuntimeException { message: "Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that \"pcntl_*\" functions are not disabled by your php.ini's \"disable_functions\" directive.".to_string(), @@ -2491,58 +2434,16 @@ impl Application { } } - if self.dispatcher.is_some() { - // TODO(plugin): for each signal, register a handler that dispatches ConsoleSignalEvent. - for &signal in &self.signals_to_dispatch_event.clone() { - let _event = ConsoleSignalEvent::new( - todo!("Box<dyn SymfonyCommand>"), - todo!("Box<dyn InputInterface>"), - todo!("Box<dyn OutputInterface>"), - signal, - ); - todo!("register signal handler dispatching ConsoleEvents::SIGNAL"); - } - } - for _signal in command_signals { // $this->signalRegistry->register($signal, [$command, 'handleSignal']); todo!("register command->handle_signal as signal handler"); } } - if self.dispatcher.is_none() { - return command.borrow_mut().run( - &mut *borrow_input_mut(&input), - &mut *borrow_output_mut(&output), - ); - } - - // bind before the console.command event, so the listeners have access to input options/arguments - match (|| -> anyhow::Result<()> { - command.borrow_mut().merge_application_definition(true); - input.borrow_mut().bind(command.borrow().get_definition())?; - Ok(()) - })() { - Ok(()) => {} - Err(e) => { - // ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition - if !is_exception_interface(&e) { - return Err(e); - } - } - } - - // TODO(plugin): the whole dispatcher block below drives ConsoleCommandEvent / - // ConsoleErrorEvent / ConsoleTerminateEvent. The event objects require Box<dyn ...> - // wrappers for input/output/command and the dispatcher's dispatch() contract; their - // construction is left to the plugin/event design. - let _ = ConsoleCommandEvent::RETURN_CODE_DISABLED; - let _ = std::marker::PhantomData::<( - ConsoleCommandEvent, - ConsoleErrorEvent, - ConsoleTerminateEvent, - )>; - todo!("dispatcher-driven command run (console.command / console.error / console.terminate)") + command.borrow_mut().run( + &mut *borrow_input_mut(&input), + &mut *borrow_output_mut(&output), + ) } /// Gets the name of the command based on input. |
