From c1a71edbba66fb48b325e96529f6067c876c06c4 Mon Sep 17 00:00:00 2001 From: Ryuk <41i.6h0rb4n1@gmail.com> Date: Thu, 3 Sep 2020 19:24:49 +0430 Subject: [PATCH] Add cli for creating controllers and middlewares --- bin/console | 67 +++++++++++++++++++++++++++++ src/Template/ControllerTemplate.php | 18 ++++++++ src/Template/MiddlewareTemplate.php | 21 +++++++++ 3 files changed, 106 insertions(+) create mode 100644 bin/console create mode 100644 src/Template/ControllerTemplate.php create mode 100644 src/Template/MiddlewareTemplate.php diff --git a/bin/console b/bin/console new file mode 100644 index 0000000..b352690 --- /dev/null +++ b/bin/console @@ -0,0 +1,67 @@ +#!/usr/bin/php + [ + 'controller', + 'middleware', + ] +]; + +$commandOption = null; +foreach ($argv as $arg) { + foreach (array_keys($commands) as $command) { + if (strpos($arg, $command . ':') === 0) { + $commandOption = explode($command . ':', $arg)[1]; + break; + } + } +} + +if (!$commandOption || !in_array($commandOption, $commands[$command])) { + echo 'Options:' . PHP_EOL; + echo ' make:controller Create a new Controller' . PHP_EOL; + echo ' make:middleware Create a new Middleware' . PHP_EOL; + + exit; +} + +if ($command == 'make') { + $defaulDirectory = explode('/vendor/', getcwd())[0] . '/' . ucfirst($commandOption) . 's'; + $directory = readline('Enter the target directory [' . $defaulDirectory . ']:') ?: $defaulDirectory; + + if (!is_dir($directory)) { + echo PHP_EOL . 'ERROR: ' . 'The specified directory does not exist!' . PHP_EOL; + + exit; + } + + + $className = readline("Enter the {$commandOption} name:"); + + $defaulNamespace = ucfirst($commandOption) . 's'; + $namespace = readline('Enter the target namespace [' . $defaulNamespace . ']:') ?: $defaulNamespace; + + try { + ob_start(); + echo 'getMessage() . PHP_EOL; + } +} \ No newline at end of file diff --git a/src/Template/ControllerTemplate.php b/src/Template/ControllerTemplate.php new file mode 100644 index 0000000..6b33fef --- /dev/null +++ b/src/Template/ControllerTemplate.php @@ -0,0 +1,18 @@ + + +namespace ; + +/** + * Class + + * + * @package + +*/ +class + +{ + public function main() + { + } +} \ No newline at end of file diff --git a/src/Template/MiddlewareTemplate.php b/src/Template/MiddlewareTemplate.php new file mode 100644 index 0000000..b7fa5f1 --- /dev/null +++ b/src/Template/MiddlewareTemplate.php @@ -0,0 +1,21 @@ + + +namespace ; + +/** + * Class + + * + * @package + +*/ +class + +{ + public function handle() + { + // your middleware codes + + return true; + } +} \ No newline at end of file