|
@ -5,13 +5,14 @@ namespace App\Commands; |
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
|
use Illuminate\Console\Scheduling\Schedule; |
|
|
use LaravelZero\Framework\Commands\Command; |
|
|
use LaravelZero\Framework\Commands\Command; |
|
|
use Illuminate\Support\Facades\File; |
|
|
use Illuminate\Support\Facades\File; |
|
|
use Jenssegers\Blade\Blade; |
|
|
|
|
|
|
|
|
|
|
|
use App\Facades\Install; |
|
|
use App\Facades\Install; |
|
|
use App\Facades\NginxVhost; |
|
|
use App\Facades\NginxVhost; |
|
|
use App\Facades\NginxVhostFactory; |
|
|
use App\Facades\NginxVhostFactory; |
|
|
use App\Facades\TerminalHelper; |
|
|
use App\Facades\TerminalHelper; |
|
|
|
|
|
|
|
|
|
|
|
use App\BladeFile; |
|
|
|
|
|
|
|
|
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; |
|
@ -101,17 +102,17 @@ class NginxVhostsCommand extends Command |
|
|
// getting templates
|
|
|
// getting templates
|
|
|
$templates = $this->getTemplates(); |
|
|
$templates = $this->getTemplates(); |
|
|
|
|
|
|
|
|
$menu = function(CliMenuBuilder $builder) use ($templates) |
|
|
|
|
|
{ |
|
|
|
|
|
// writing configuration
|
|
|
|
|
|
$blade = new Blade(base_path().self::TEMPLATES_DIR, base_path().'/storage/cache'); |
|
|
|
|
|
|
|
|
// create blade
|
|
|
|
|
|
$bladeFile = new BladeFile(self::TEMPLATES_DIR); |
|
|
|
|
|
|
|
|
|
|
|
$menu = function(CliMenuBuilder $builder) use ($templates, $bladeFile) |
|
|
|
|
|
{ |
|
|
$builder |
|
|
$builder |
|
|
->setTitle('Nginx > Add') |
|
|
->setTitle('Nginx > Add') |
|
|
->setGoBackButtonText('Back'); |
|
|
->setGoBackButtonText('Back'); |
|
|
|
|
|
|
|
|
foreach($templates as $template) { |
|
|
foreach($templates as $template) { |
|
|
$submenuCallable = $this->createConfiguration($template, $blade); |
|
|
|
|
|
|
|
|
$submenuCallable = $this->createConfiguration($template, $bladeFile); |
|
|
$builder |
|
|
$builder |
|
|
->addSubMenu($template['name'], $submenuCallable); |
|
|
->addSubMenu($template['name'], $submenuCallable); |
|
|
} |
|
|
} |
|
@ -130,11 +131,9 @@ class NginxVhostsCommand extends Command |
|
|
* @param Blade $blade |
|
|
* @param Blade $blade |
|
|
* @return CliMenuBuilder |
|
|
* @return CliMenuBuilder |
|
|
*/ |
|
|
*/ |
|
|
private function createConfiguration($template, $blade) |
|
|
|
|
|
|
|
|
private function createConfiguration($template, $bladeFile) |
|
|
{ |
|
|
{ |
|
|
$self = $this; |
|
|
|
|
|
|
|
|
|
|
|
$menu = function(CliMenuBuilder $builder) use ($template, $blade, $self) |
|
|
|
|
|
|
|
|
$menu = function(CliMenuBuilder $builder) use ($template, $bladeFile) |
|
|
{ |
|
|
{ |
|
|
$configuration = [ |
|
|
$configuration = [ |
|
|
'domain' => '', |
|
|
'domain' => '', |
|
@ -196,7 +195,7 @@ class NginxVhostsCommand extends Command |
|
|
->addLineBreak('-') |
|
|
->addLineBreak('-') |
|
|
|
|
|
|
|
|
// create
|
|
|
// create
|
|
|
->addItem('Create', function(CliMenu $menu) use (&$configuration, $template, $blade, $self) { |
|
|
|
|
|
|
|
|
->addItem('Create', function(CliMenu $menu) use (&$configuration, $template, $bladeFile) { |
|
|
|
|
|
|
|
|
$data = $configuration; |
|
|
$data = $configuration; |
|
|
|
|
|
|
|
@ -217,14 +216,11 @@ class NginxVhostsCommand extends Command |
|
|
TerminalHelper::confirmArray($menu, $errors); |
|
|
TerminalHelper::confirmArray($menu, $errors); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
// render configuration
|
|
|
|
|
|
$content = $blade->render($template['name'], $configuration); |
|
|
|
|
|
|
|
|
|
|
|
// create filename
|
|
|
// create filename
|
|
|
$filename = $configuration['domain'].'.conf'; |
|
|
$filename = $configuration['domain'].'.conf'; |
|
|
|
|
|
|
|
|
// write configuration to file
|
|
|
// write configuration to file
|
|
|
file_put_contents('/etc/nginx/sites-available/'.$filename, $content); |
|
|
|
|
|
|
|
|
$bladeFile->put($template['name'], '/etc/nginx/sites-available/'.$filename, $configuration); |
|
|
|
|
|
|
|
|
$menu->confirm('Success!')->display('Ok!'); |
|
|
$menu->confirm('Success!')->display('Ok!'); |
|
|
|
|
|
|
|
|