| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -5,12 +5,56 @@ namespace App\Factories; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\Builder\CliMenuBuilder; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\CliMenu; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\MenuItem\CheckboxItem; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\Style\SelectableStyle; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					use PhpSchool\CliMenu\MenuItem\MenuMenuItem; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					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 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     *  @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) { | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |