Browse Source

adding #14

release/0.1
Björn 4 years ago
parent
commit
5955fb6617
3 changed files with 68 additions and 50 deletions
  1. +1
    -2
      app/Commands/NginxVhostsCommand.php
  2. +20
    -0
      app/Facades/NginxVhostFactory.php
  3. +47
    -48
      app/Factories/NginxVhostFactory.php

+ 1
- 2
app/Commands/NginxVhostsCommand.php View File

@ -9,8 +9,7 @@ use Jenssegers\Blade\Blade;
use App\Facades\Install; use App\Facades\Install;
use App\Facades\NginxVhost; use App\Facades\NginxVhost;
use App\Factories\NginxVhostFactory;
use App\Facades\NginxVhostFactory;
use PhpSchool\CliMenu\Builder\CliMenuBuilder; use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\CliMenu; use PhpSchool\CliMenu\CliMenu;


+ 20
- 0
app/Facades/NginxVhostFactory.php View File

@ -0,0 +1,20 @@
<?php
namespace App\Facades;
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 NginxVhostFactory extends Facade
{
protected static function getFacadeAccessor()
{
return 'App\Factories\NginxVhostFactory';
}
}

+ 47
- 48
app/Factories/NginxVhostFactory.php View File

@ -5,12 +5,56 @@ namespace App\Factories;
use PhpSchool\CliMenu\Builder\CliMenuBuilder; use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\CliMenu; use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\MenuItem\CheckboxItem; use PhpSchool\CliMenu\MenuItem\CheckboxItem;
use PhpSchool\CliMenu\Style\SelectableStyle;
use PhpSchool\CliMenu\MenuItem\MenuMenuItem; use PhpSchool\CliMenu\MenuItem\MenuMenuItem;
class NginxVhostFactory class NginxVhostFactory
{ {
/**
*
* @param [type] $mainmenu
* @param [type] $vhosts
* @param [type] $vhostIndex
*/
public function addVhosts($mainmenu, $vhosts, $vhostIndex)
{
// get items
$items = $mainmenu->getItems();
// new items
$newItems = [];
foreach($items as $index => $item) {
if ($index <= $vhostIndex) {
$newItems[] = $item;
} else {
break;
}
}
// check for linebreak
foreach($items as $index => $item) {
if ($index > $vhostIndex && get_class($item) === 'PhpSchool\CliMenu\MenuItem\LineBreakItem') {
$startIndex = $index;
break;
}
}
// add submenu for each vhost
foreach($vhosts as $vhost) {
$newItems[] = self::createVhostSubmenu($vhost, $mainmenu);
}
// fillup last items from mainmenu
foreach($items as $index => $item) {
if ($index >= $startIndex) {
$newItems[] = $item;
}
}
$mainmenu->setItems($newItems);
return $mainmenu;
}
/** /**
* *
@ -18,7 +62,7 @@ class NginxVhostFactory
* @param [type] $mainmenu * @param [type] $mainmenu
* @return [type] * @return [type]
*/ */
public static function createVhostSubmenu($vhost, $mainmenu)
private function createVhostSubmenu($vhost, $mainmenu)
{ {
$builder = CliMenuBuilder::newSubMenu($mainmenu->getTerminal()); $builder = CliMenuBuilder::newSubMenu($mainmenu->getTerminal());
@ -69,57 +113,12 @@ class NginxVhostFactory
return $item; return $item;
} }
/**
*
*
*/
public static function addVhosts($mainmenu, $vhosts, $vhostIndex)
{
// get items
$items = $mainmenu->getItems();
// new items
$newItems = [];
foreach($items as $index => $item) {
if ($index <= $vhostIndex) {
$newItems[] = $item;
} else {
break;
}
}
// check for linebreak
foreach($items as $index => $item) {
if ($index > $vhostIndex && get_class($item) === 'PhpSchool\CliMenu\MenuItem\LineBreakItem') {
$startIndex = $index;
break;
}
}
// add submenu for each vhost
foreach($vhosts as $vhost) {
$newItems[] = self::createVhostSubmenu($vhost, $mainmenu);
}
// fillup last items from mainmenu
foreach($items as $index => $item) {
if ($index >= $startIndex) {
$newItems[] = $item;
}
}
$mainmenu->setItems($newItems);
return $mainmenu;
}
/** /**
* *
* @param [type] $vhost * @param [type] $vhost
* @return [type] * @return [type]
*/ */
private static function createVhostCheckbox($vhost)
private function createVhostCheckbox($vhost)
{ {
// create checkbox for enabled / disabled // create checkbox for enabled / disabled
$checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($vhost) { $checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($vhost) {


Loading…
Cancel
Save