diff --git a/app/Commands/NginxVhostsCommand.php b/app/Commands/NginxVhostsCommand.php index f396880..0263cf5 100644 --- a/app/Commands/NginxVhostsCommand.php +++ b/app/Commands/NginxVhostsCommand.php @@ -10,6 +10,9 @@ use App\Facades\Install; use App\Facades\NginxVhost; use App\Facades\NginxVhostFactory; use App\Facades\TerminalHelper; +use App\Facades\Menus\StylesFactory; + +use App\Helpers\NginxTemplateHelper; use App\BladeFile; @@ -55,43 +58,6 @@ class NginxVhostsCommand extends Command */ protected $description = 'Create and Manage Nginx Vhosts'; - /** - * - * @param string $prefix [description] - * @return [type] [description] - */ - private function getTemplates($prefix = '') - { - // templates - $templates = []; - - // getting templates - $files = scandir(base_path().self::TEMPLATES_DIR); - - foreach($files as $file) { - - // create filepath - $filepath = base_path().self::TEMPLATES_DIR.'/'.$file; - - // getting info - $pathinfo = pathinfo($filepath); - - // if extension isset and php - if (isset($pathinfo['extension']) && $pathinfo['extension'] === 'php') { - - $name = str_replace('.blade.php', '', $file); - - $templates[] = [ - 'name' => $name, - 'file' => $file, - 'filepath' => $filepath - ]; - } - } - - return $templates; - } - /** * * @@ -99,19 +65,18 @@ class NginxVhostsCommand extends Command */ private function selectTemplate() { - // getting templates - $templates = $this->getTemplates(); - - // create blade - $bladeFile = new BladeFile(self::TEMPLATES_DIR); - - $menu = function(CliMenuBuilder $builder) use ($templates, $bladeFile) + $menu = function(CliMenuBuilder $builder) { + // create blade + $bladeFile = new BladeFile(self::TEMPLATES_DIR); + $builder ->setTitle('Nginx > Add') ->setGoBackButtonText('Back'); - foreach($templates as $template) { + $nginxTemplateHelper = new NginxTemplateHelper(); + + foreach($nginxTemplateHelper->find() as $template) { $submenuCallable = $this->createConfiguration($template, $bladeFile); $builder ->addSubMenu($template['name'], $submenuCallable); @@ -250,21 +215,18 @@ class NginxVhostsCommand extends Command $submenuSelectTemplate = $this->selectTemplate(); // create menu - $mainmenu = $this->menu('Nginx') + $builder = $this->menu('Nginx') // add Submenu for select templates ->addLineBreak('-') ->addSubMenu('Add', $submenuSelectTemplate); - $mainmenu->addLineBreak('-'); + $builder->addLineBreak('-'); // apperance - $mainmenu->setWidth($mainmenu->getTerminal()->getWidth()); - $mainmenu->setBorderLeftWidth(4); - $mainmenu->setBorderColour('magenta'); - $mainmenu->setMargin(2); + $builder = StylesFactory::setMenuStyles($builder); - $mainmenu = $mainmenu->build(); + $mainmenu = $builder->build(); // remove first item $items = $mainmenu->getItems(); diff --git a/app/Facades/Menus/StylesFactory.php b/app/Facades/Menus/StylesFactory.php new file mode 100644 index 0000000..5d84672 --- /dev/null +++ b/app/Facades/Menus/StylesFactory.php @@ -0,0 +1,20 @@ + $file, - 'path' => $templatePath - ]; + + // create filepath + $filepath = base_path().$templatePath.'/'.$file; + + // getting info + $pathinfo = pathinfo($filepath); + + // if extension isset and php + if (isset($pathinfo['extension']) && $pathinfo['extension'] === 'php') { + + $name = str_replace('.blade.php', '', $file); + + $results[] = [ + 'name' => $name, + 'file' => $file, + 'filepath' => $filepath + ]; + + } } } @@ -58,7 +59,7 @@ class NginxTemplateHelper } /** - * getting templates + * getting templates * */ public function find() diff --git a/app/Menus/Styles.php b/app/Menus/Styles.php deleted file mode 100644 index e69de29..0000000 diff --git a/app/Menus/StylesFactory.php b/app/Menus/StylesFactory.php new file mode 100644 index 0000000..17668b8 --- /dev/null +++ b/app/Menus/StylesFactory.php @@ -0,0 +1,30 @@ +setWidth($builder->getTerminal()->getWidth()); + $builder->setBorderLeftWidth(4); + $builder->setBorderColour('magenta'); + $builder->setMargin(2); + $builder->setPadding(2, 4); + + return $builder; + } +} \ No newline at end of file