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