From 62af4cea9e87f4c4e7f5f1a8b5ba299b11752f98 Mon Sep 17 00:00:00 2001 From: Funky Waddle Date: Sat, 21 Feb 2026 19:12:38 -0600 Subject: [PATCH] feat: implement core console interfaces and attributes --- src/Attributes/Arg.php | 17 +++++ src/Attributes/Cmd.php | 17 +++++ src/Attributes/HasAttributes.php | 75 ++++++++++++++++++++++ src/Attributes/Opt.php | 17 +++++ src/CommandInterface.php | 24 +++++++ src/ConsoleExceptionInterface.php | 9 +++ src/ConsoleMiddlewareInterface.php | 15 +++++ src/ExitCode.php | 19 ++++++ src/Helpers/MarkdownConverterInterface.php | 12 ++++ src/Helpers/ProgressBarInterface.php | 14 ++++ src/Helpers/TableInterface.php | 20 ++++++ src/InputInterface.php | 14 ++++ src/InteractionInterface.php | 19 ++++++ src/OutputInterface.php | 26 ++++++++ src/Verbosity.php | 14 ++++ 15 files changed, 312 insertions(+) create mode 100644 src/Attributes/Arg.php create mode 100644 src/Attributes/Cmd.php create mode 100644 src/Attributes/HasAttributes.php create mode 100644 src/Attributes/Opt.php create mode 100644 src/CommandInterface.php create mode 100644 src/ConsoleExceptionInterface.php create mode 100644 src/ConsoleMiddlewareInterface.php create mode 100644 src/ExitCode.php create mode 100644 src/Helpers/MarkdownConverterInterface.php create mode 100644 src/Helpers/ProgressBarInterface.php create mode 100644 src/Helpers/TableInterface.php create mode 100644 src/InputInterface.php create mode 100644 src/InteractionInterface.php create mode 100644 src/OutputInterface.php create mode 100644 src/Verbosity.php diff --git a/src/Attributes/Arg.php b/src/Attributes/Arg.php new file mode 100644 index 0000000..2b75ec7 --- /dev/null +++ b/src/Attributes/Arg.php @@ -0,0 +1,17 @@ +getAttributes(Cmd::class)[0] ?? null; + if ($attr === null) { + return ''; + } + /** @var Cmd $meta */ + $meta = $attr->newInstance(); + return $meta->name; + } + + public function getDescription(): string + { + $ref = new ReflectionClass($this); + $attr = $ref->getAttributes(Cmd::class)[0] ?? null; + if ($attr === null) { + return ''; + } + /** @var Cmd $meta */ + $meta = $attr->newInstance(); + return $meta->description; + } + + /** + * @return array + */ + public function getArguments(): array + { + $ref = new ReflectionClass($this); + $attrs = $ref->getAttributes(Arg::class); + $out = []; + foreach ($attrs as $attr) { + /** @var Arg $a */ + $a = $attr->newInstance(); + $out[$a->name] = $a->description; + } + return $out; + } + + /** + * @return array + */ + public function getOptions(): array + { + $ref = new ReflectionClass($this); + $attrs = $ref->getAttributes(Opt::class); + $out = []; + foreach ($attrs as $attr) { + /** @var Opt $o */ + $o = $attr->newInstance(); + $out[$o->name] = $o->description; + } + return $out; + } +} diff --git a/src/Attributes/Opt.php b/src/Attributes/Opt.php new file mode 100644 index 0000000..226fa05 --- /dev/null +++ b/src/Attributes/Opt.php @@ -0,0 +1,17 @@ + Name => Description + */ + public function getArguments(): array; + + /** + * @return array Name => Description + */ + public function getOptions(): array; + + public function execute(InputInterface $input, OutputInterface $output): int; +} diff --git a/src/ConsoleExceptionInterface.php b/src/ConsoleExceptionInterface.php new file mode 100644 index 0000000..72aea25 --- /dev/null +++ b/src/ConsoleExceptionInterface.php @@ -0,0 +1,9 @@ + $headers + */ + public function setHeaders(array $headers): void; + + /** + * @param array $row + */ + public function addRow(array $row): void; + + public function render(): void; +} diff --git a/src/InputInterface.php b/src/InputInterface.php new file mode 100644 index 0000000..2923412 --- /dev/null +++ b/src/InputInterface.php @@ -0,0 +1,14 @@ + $choices + */ + public function choice(string $question, array $choices, mixed $default = null): mixed; +} diff --git a/src/OutputInterface.php b/src/OutputInterface.php new file mode 100644 index 0000000..37af621 --- /dev/null +++ b/src/OutputInterface.php @@ -0,0 +1,26 @@ +