From f65dd8e20a841b140b8a93e52dd75f767f4114f8 Mon Sep 17 00:00:00 2001 From: Drajat Hasan Date: Sun, 27 Dec 2020 00:22:31 +0700 Subject: [PATCH] Add : Docgenerator --- src/SLiMSTarsius/Docgenerator.php | 76 +++++++++++++++++++ src/SLiMSTarsius/Parser.php | 9 ++- src/SLiMSTarsius/Plugin.php | 36 ++++++--- src/SLiMSTarsius/Tarmagick.php | 24 ++++-- .../plugins/buku_induk/buku_induk.plugin.php | 15 ---- tests/plugins/buku_induk/index.php | 60 --------------- 6 files changed, 125 insertions(+), 95 deletions(-) create mode 100644 src/SLiMSTarsius/Docgenerator.php delete mode 100644 tests/plugins/buku_induk/buku_induk.plugin.php delete mode 100644 tests/plugins/buku_induk/index.php diff --git a/src/SLiMSTarsius/Docgenerator.php b/src/SLiMSTarsius/Docgenerator.php new file mode 100644 index 0000000..cc17416 --- /dev/null +++ b/src/SLiMSTarsius/Docgenerator.php @@ -0,0 +1,76 @@ +arguments[$map[$id]] = [str_replace('-', '', $value[0]), $value[1]]; + if (isset($value[0]) && isset($value[1])) + { + $this->arguments[$map[$id]] = [str_replace('-', '', $value[0]), $value[1]]; + } + else + { + \SLiMSTarsius\Docgenerator::firstMeet(); exit; + } } unset($this->arguments[$id]); } diff --git a/src/SLiMSTarsius/Plugin.php b/src/SLiMSTarsius/Plugin.php index 06ac974..93231b2 100644 --- a/src/SLiMSTarsius/Plugin.php +++ b/src/SLiMSTarsius/Plugin.php @@ -3,11 +3,13 @@ * @author Drajat Hasan * @email drajathasan20@gmail.com * @create date 2020-12-26 17:02:45 - * @modify date 2020-12-26 17:03:16 + * @modify date 2020-12-27 00:20:27 */ namespace SLiMSTarsius; +use \SLiMSTarsius\Docgenerator as dg; + class Plugin { public $env; @@ -26,7 +28,7 @@ public function create($dest, $pluginName) 'version' => 'Version (Minimal gunakan semantic versioning)', 'author' => 'Author (Pembuat)', 'author_uri' => 'Author URI (Halaman profil pembuat)', - 'target_module' => 'Modul tujuan?', + 'target_module' => 'Modul tujuan', 'label_menu' => 'Teks yang muncul di Menu?' ]; @@ -35,13 +37,13 @@ public function create($dest, $pluginName) if (count($pluginName) > 1) { - die("Hanya bisa membuat 1 plugin dalam 1 perintah!\n"); + dg::failedMsg("{pointMsg}", 'Hanya bisa membuat 1 plugin dalam 1 perintah!'); } $pluginName = $pluginName[0]; // set message - echo 'Membuat plugin '.$pluginName."\n"; + echo "\nMembuat plugin \e[36m$pluginName\033[0m\n\n"; // get information and make plugin $this->makeInteractive($interactiveMap) ->makePlugin($pluginName, $destinantion, $template); @@ -52,7 +54,7 @@ private function makeInteractive($label) if (is_array($label)) { foreach ($label as $key => $question) { - echo $question.' plugin? [tuliskan] '; + echo "\e[1m$question plugin?\033[0m [tuliskan] "; $this->interactiveResponse[$key] = trim(fgets(STDIN)); } @@ -60,7 +62,7 @@ private function makeInteractive($label) } else { - die('Label harus Array!'); + dg::failedMsg("{pointMsg} harus Array!", 'Label'); } } @@ -78,8 +80,18 @@ private function makePlugin($pluginName, $destDir, $template) $this->interactiveResponse['date_created'] = date('Y-m-d H:i:s'); foreach ($this->interactiveResponse as $key => $value) { - $dotPlugin = str_replace('{'.$key.'}', $value, $dotPlugin); - $indexPlugin = str_replace('{'.$key.'}', $value, $indexPlugin); + if (!empty(trim($this->interactiveResponse[$key]))) + { + $dotPlugin = str_replace('{'.$key.'}', $value, $dotPlugin); + $indexPlugin = str_replace('{'.$key.'}', $value, $indexPlugin); + } + else + { + // remove directory + rmdir($destDir.$pluginName); + // set message + dg::failedMsg("Parameter {pointMsg} tidak boleh kosong!", $key); + } } try { @@ -89,20 +101,20 @@ private function makePlugin($pluginName, $destDir, $template) if ($dotPlugin && $indexPlugin) { - echo "Berhasil membuat plugin $pluginName \n"; + dg::successMsg("{pointMsg}", "\nBerhasil membuat plugin $pluginName"); } } catch (\ErrorException $e) { - die("Gagal membuat plugin $pluginName : \n ".$e->getMessage()); + dg::failedMsg("Gagal membuat plugin {pointMsg} : $e->getMessage()", $pluginName); } } else { - die('Gagal membuat direktori plugin!'); + dg::failedMsg("{pointMsg}", "Gagal membuat direktori plugin"); } } else { - die('Plugin sudah ada. Ingin membuat plugin lagi? Hapus plugin yang sudah ada.'."\n"); + dg::failedMsg("{pointMsg}", "Plugin sudah ada. Ingin membuat plugin lagi? Hapus plugin yang sudah ada."); } } } \ No newline at end of file diff --git a/src/SLiMSTarsius/Tarmagick.php b/src/SLiMSTarsius/Tarmagick.php index f62cf07..4f5eb03 100644 --- a/src/SLiMSTarsius/Tarmagick.php +++ b/src/SLiMSTarsius/Tarmagick.php @@ -3,7 +3,7 @@ * @author Drajat Hasan * @email drajathasan20@gmail.com * @create date 2020-12-26 17:02:45 - * @modify date 2020-12-26 17:03:16 + * @modify date 2020-12-27 00:20:21 */ namespace SLiMSTarsius; @@ -17,7 +17,21 @@ class Tarmagick public static function plugin($action) { self::getEnvironment(self::$dir); - echo (new \SLiMSTarsius\Plugin(self::$environment))->$action(self::$dir, self::$parameter); + + try { + $Plugin = new \SLiMSTarsius\Plugin(self::$environment); + + if (method_exists($Plugin, $action)) + { + $Plugin->$action(self::$dir, self::$parameter); + } + else + { + throw new \ErrorException($action); + } + } catch (\ErrorException $e) { + \SLiMSTarsius\Docgenerator::failedMsg("Metode {pointMsg} tidak ada!", $e->getMessage()); + } } public static function module($action) @@ -60,14 +74,10 @@ public static function startup($mainDirectory) self::$parameter = $parser->arguments['parameter']; return self::$method($parser->arguments['method'][1]); } - else - { - echo "Metode tidak tersedia!"; - } } else { - echo "Hai, ini tarsius perkakas pengemban untuk SLiMS :D \n"; + \SLiMSTarsius\Docgenerator::firstMeet(); } } } \ No newline at end of file diff --git a/tests/plugins/buku_induk/buku_induk.plugin.php b/tests/plugins/buku_induk/buku_induk.plugin.php deleted file mode 100644 index 2eeda37..0000000 --- a/tests/plugins/buku_induk/buku_induk.plugin.php +++ /dev/null @@ -1,15 +0,0 @@ -registerMenu('bibliography', 'Buku Induk', __DIR__ . '/index.php'); diff --git a/tests/plugins/buku_induk/index.php b/tests/plugins/buku_induk/index.php deleted file mode 100644 index 81e77b2..0000000 --- a/tests/plugins/buku_induk/index.php +++ /dev/null @@ -1,60 +0,0 @@ -' . __('You are not authorized to view this section') . ''); -} - -function httpQuery($query = []) -{ - return http_build_query(array_unique(array_merge($_GET, $query))); -} - -$page_title = 'Buku Induk'; - -/* Action Area */ - -/* End Action Area */ -?> - - -