Browse Source

adding #1

release/0.1
Björn 4 years ago
parent
commit
81740ed9d9
5 changed files with 91 additions and 78 deletions
  1. +14
    -52
      app/Commands/NginxVhostsCommand.php
  2. +20
    -0
      app/Facades/Menus/StylesFactory.php
  3. +27
    -26
      app/Helpers/NginxTemplateHelper.php
  4. +0
    -0
      app/Menus/Styles.php
  5. +30
    -0
      app/Menus/StylesFactory.php

+ 14
- 52
app/Commands/NginxVhostsCommand.php View File

@ -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();


+ 20
- 0
app/Facades/Menus/StylesFactory.php View File

@ -0,0 +1,20 @@
<?php
namespace App\Facades\Menus;
use Illuminate\Support\Facades\Facade;
/**
* Nginx
*
* @author Björn Hase
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://github.com/nirgendswo/fuzzy-cms GitHub Repository
*/
class StylesFactory extends Facade
{
protected static function getFacadeAccessor()
{
return 'App\Menus\StylesFactory';
}
}

+ 27
- 26
app/Helpers/NginxTemplateHelper.php View File

@ -11,29 +11,15 @@ namespace App\Helpers;
class NginxTemplateHelper
{
// path for templates files
const TEMPLATES_PATH = '/ressources/templates';
const TEMPLATES_DIR = '/resources/nginx/templates';
// path for custom template files
const CUSTOM_TEMPLATES_PATH = '/ressources/templates/custom';
const TEMPLATES_CUSTOM_DIR = '/resources/nginx/templates/custom';
/**
*
*
*
* @return array
*
*/
private function getTemplates()
{
$results = [];
array_merge(
scandir(self::TEMPLATES_PATH),
scandir(self::CUSTOM_TEMPLATES_PATH)
);
return $templates;
}
// ignore files
const IGNORE_FILES = [
'.', '..'
];
/**
*
@ -45,12 +31,27 @@ class NginxTemplateHelper
{
$results = [];
foreach(scandir(base_dir().$templatePath) as $file) {
foreach(scandir(base_path().$templatePath) as $file) {
if (!in_array($file, self::IGNORE_FILES)) {
$results[] = [
'filename' => $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()


+ 0
- 0
app/Menus/Styles.php View File


+ 30
- 0
app/Menus/StylesFactory.php View File

@ -0,0 +1,30 @@
<?php
namespace App\Menus;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
/**
*
*
*
*/
class StylesFactory
{
/**
* Adding default styles for menus
*
*
* @param CliMenuBuilder $builder [description]
*/
public function setMenuStyles(CliMenuBuilder $builder)
{
$builder->setWidth($builder->getTerminal()->getWidth());
$builder->setBorderLeftWidth(4);
$builder->setBorderColour('magenta');
$builder->setMargin(2);
$builder->setPadding(2, 4);
return $builder;
}
}

Loading…
Cancel
Save