diff --git a/app/Commands/NginxVhostsCommand.php b/app/Commands/NginxVhostsCommand.php index fd0f192..8049453 100644 --- a/app/Commands/NginxVhostsCommand.php +++ b/app/Commands/NginxVhostsCommand.php @@ -9,8 +9,7 @@ use Jenssegers\Blade\Blade; use App\Facades\Install; use App\Facades\NginxVhost; - -use App\Factories\NginxVhostFactory; +use App\Facades\NginxVhostFactory; use PhpSchool\CliMenu\Builder\CliMenuBuilder; use PhpSchool\CliMenu\CliMenu; diff --git a/app/Facades/NginxVhostFactory.php b/app/Facades/NginxVhostFactory.php new file mode 100644 index 0000000..b47525d --- /dev/null +++ b/app/Facades/NginxVhostFactory.php @@ -0,0 +1,20 @@ +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 * @return [type] */ - public static function createVhostSubmenu($vhost, $mainmenu) + private function createVhostSubmenu($vhost, $mainmenu) { $builder = CliMenuBuilder::newSubMenu($mainmenu->getTerminal()); @@ -69,57 +113,12 @@ class NginxVhostFactory 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 * @return [type] */ - private static function createVhostCheckbox($vhost) + private function createVhostCheckbox($vhost) { // create checkbox for enabled / disabled $checkbox = new CheckboxItem('enabled', function(CliMenu $menu) use ($vhost) {