|
|
@ -16,7 +16,6 @@ use App\Menus\ItemValidator; |
|
|
|
|
|
|
|
use App\BladeFile; |
|
|
|
use App\Helpers\NginxTemplateHelper; |
|
|
|
|
|
|
|
use App\Facades\TerminalHelper; |
|
|
|
|
|
|
|
/** |
|
|
@ -32,6 +31,26 @@ class TemplateMenuFactory |
|
|
|
// path templates
|
|
|
|
const TEMPLATES_DIR = '/resources/nginx/templates'; |
|
|
|
|
|
|
|
private $configuration = []; |
|
|
|
|
|
|
|
/** |
|
|
|
* default configuration |
|
|
|
* |
|
|
|
* @TODO will be removed after |
|
|
|
* |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
private function getConfiguration() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'domain' => '', |
|
|
|
'root' => '', |
|
|
|
'index' => 'index.php', |
|
|
|
'ssl' => true, |
|
|
|
'redirect_www' => true |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* add item to select template |
|
|
|
* |
|
|
@ -65,24 +84,6 @@ class TemplateMenuFactory |
|
|
|
return $menu; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* default configuration |
|
|
|
* |
|
|
|
* @TODO will be removed after |
|
|
|
* |
|
|
|
* @return array |
|
|
|
*/ |
|
|
|
private function getConfiguration() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
'domain' => '', |
|
|
|
'root' => '', |
|
|
|
'index' => 'index.php', |
|
|
|
'ssl' => true, |
|
|
|
'redirect_www' => true |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* add input item |
|
|
|
* |
|
|
@ -90,18 +91,18 @@ class TemplateMenuFactory |
|
|
|
* @param string $label |
|
|
|
* @param array $configuration |
|
|
|
*/ |
|
|
|
private function addInputItem($key, $label, &$configuration, $itemValidator = NULL) |
|
|
|
private function addInputItem($key, $label, $itemValidator = NULL) |
|
|
|
{ |
|
|
|
$callable = function(CliMenu $menu) use ($key, $label, &$configuration, $itemValidator) |
|
|
|
$callable = function(CliMenu $menu) use ($key, $label, $itemValidator) |
|
|
|
{ |
|
|
|
$input = $menu->askText(); |
|
|
|
|
|
|
|
if ($configuration[$key]) { |
|
|
|
$input->setPlaceholderText($configuration[$key]); |
|
|
|
if ($this->configuration[$key]) { |
|
|
|
$input->setPlaceholderText($this->configuration[$key]); |
|
|
|
} |
|
|
|
|
|
|
|
$result = $input->ask(); |
|
|
|
$configuration[$key] = $result->fetch(); |
|
|
|
$this->configuration[$key] = $result->fetch(); |
|
|
|
|
|
|
|
$menu->getSelectedItem()->setText($label.': '.$result->fetch()); |
|
|
|
|
|
|
@ -122,12 +123,12 @@ class TemplateMenuFactory |
|
|
|
* @param object $bladeFile |
|
|
|
* @param array $configuration |
|
|
|
*/ |
|
|
|
private function addPublishItem($template, $bladeFile, &$configuration) |
|
|
|
private function addPublishItem($template, $bladeFile) |
|
|
|
{ |
|
|
|
$callable = function(CliMenu $menu) use ($template, $bladeFile, &$configuration) |
|
|
|
$callable = function(CliMenu $menu) use ($template, $bladeFile) |
|
|
|
{ |
|
|
|
// getting configuration
|
|
|
|
$data = $configuration; |
|
|
|
$data = $this->configuration; |
|
|
|
|
|
|
|
$validator = v::key('domain', v::domain(false)) |
|
|
|
->key('root', v::notEmpty()) |
|
|
@ -145,12 +146,14 @@ class TemplateMenuFactory |
|
|
|
} else { |
|
|
|
|
|
|
|
// create filename
|
|
|
|
$filename = $configuration['domain'].'.conf'; |
|
|
|
$filename = $this->configuration['domain'].'.conf'; |
|
|
|
|
|
|
|
// write configuration to file
|
|
|
|
$bladeFile->put($template['name'], '/etc/nginx/sites-available/'.$filename, $configuration); |
|
|
|
$bladeFile->put($template['name'], '/etc/nginx/sites-available/'.$filename, $this->configuration); |
|
|
|
$menu->confirm('Success!')->display('Ok!'); |
|
|
|
|
|
|
|
$this->configuration = $this->getConfiguration(); |
|
|
|
|
|
|
|
// invoke action
|
|
|
|
$action = new NginxVhostGoBackAction(); |
|
|
|
is_callable($action($menu)); |
|
|
@ -160,6 +163,24 @@ class TemplateMenuFactory |
|
|
|
return $callable; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* |
|
|
|
* |
|
|
|
*/ |
|
|
|
private function addCancelItem() |
|
|
|
{ |
|
|
|
$callable = function(CliMenu $menu) |
|
|
|
{ |
|
|
|
$this->configuration = $this->getConfiguration(); |
|
|
|
|
|
|
|
$action = new NginxVhostCancelAction(); |
|
|
|
is_callable($action($menu)); |
|
|
|
}; |
|
|
|
|
|
|
|
return $callable; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* adding radio buttons to select php-fpm version |
|
|
|
* |
|
|
@ -167,7 +188,7 @@ class TemplateMenuFactory |
|
|
|
* @param CliMenuBuilder $builder |
|
|
|
* @param array $configuration |
|
|
|
*/ |
|
|
|
private function addPhpFpmItems($builder, &$configuration) |
|
|
|
private function addPhpFpmItems($builder) |
|
|
|
{ |
|
|
|
// get php-fpm services
|
|
|
|
exec('find /lib/systemd/system/ -name "php[0-9\.]*-fpm.service"', $files); |
|
|
@ -180,8 +201,8 @@ class TemplateMenuFactory |
|
|
|
// remove extension
|
|
|
|
$file = str_replace('.service', '', $file); |
|
|
|
|
|
|
|
$builder->addRadioItem($file, function(CliMenu $menu) use (&$configuration) { |
|
|
|
$configuration['phpFpm'] = $menu->getSelectedItem()->getText(); |
|
|
|
$builder->addRadioItem($file, function(CliMenu $menu) { |
|
|
|
$this->configuration['phpFpm'] = $menu->getSelectedItem()->getText(); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -200,41 +221,41 @@ class TemplateMenuFactory |
|
|
|
{ |
|
|
|
$menu = function(CliMenuBuilder $builder) use ($template, $bladeFile) |
|
|
|
{ |
|
|
|
$configuration = $this->getConfiguration(); |
|
|
|
$this->configuration = $this->getConfiguration(); |
|
|
|
|
|
|
|
// create checkbox for ssl
|
|
|
|
$checkboxSSL = new CheckboxItem('ssl', function(CliMenu $menu) use (&$configuration) { |
|
|
|
$configuration['ssl'] = $menu->getSelectedItem()->getChecked(); |
|
|
|
$checkboxSSL = new CheckboxItem('ssl', function(CliMenu $menu) { |
|
|
|
$this->configuration['ssl'] = $menu->getSelectedItem()->getChecked(); |
|
|
|
}); |
|
|
|
|
|
|
|
$checkboxSSL->setChecked($configuration['ssl']); |
|
|
|
$checkboxSSL->setChecked($this->configuration['ssl']); |
|
|
|
|
|
|
|
// create checkbox for redirect from www
|
|
|
|
$checkboxRedirect = new CheckboxItem('redirect www', function(CliMenu $menu) use (&$configuration) { |
|
|
|
$configuration['redirect_www'] = $menu->getSelectedItem()->getChecked(); |
|
|
|
$checkboxRedirect = new CheckboxItem('redirect www', function(CliMenu $menu) { |
|
|
|
$this->configuration['redirect_www'] = $menu->getSelectedItem()->getChecked(); |
|
|
|
}); |
|
|
|
|
|
|
|
$checkboxRedirect->setChecked($configuration['redirect_www']); |
|
|
|
$checkboxRedirect->setChecked($this->configuration['redirect_www']); |
|
|
|
|
|
|
|
$validator = v::key('root', v::directory()); |
|
|
|
$itemValidator = new ItemValidator($validator); |
|
|
|
|
|
|
|
$builder |
|
|
|
->setTitle('Nginx > Add > '.$template['name']) |
|
|
|
->setGoBackButtonText('Cancel') |
|
|
|
->disableDefaultItems() |
|
|
|
|
|
|
|
// input domain
|
|
|
|
->addItem('domain: -', $this->addInputItem('domain', 'domain', $configuration)) |
|
|
|
->addItem('domain: -', $this->addInputItem('domain', 'domain')) |
|
|
|
|
|
|
|
// input root
|
|
|
|
->addItem('root: -', $this->addInputItem('root', 'root', $configuration, $itemValidator)) |
|
|
|
->addItem('root: -', $this->addInputItem('root', 'root', $itemValidator)) |
|
|
|
|
|
|
|
// input index
|
|
|
|
->addItem('index: '.$configuration['index'], $this->addInputItem('index', 'index', $configuration)) |
|
|
|
->addItem('index: '.$this->configuration['index'], $this->addInputItem('index', 'index')) |
|
|
|
->addLineBreak('-'); |
|
|
|
|
|
|
|
// add php-fpm items
|
|
|
|
$builder = $this->addPhpFpmItems($builder, $configuration); |
|
|
|
$builder = $this->addPhpFpmItems($builder); |
|
|
|
|
|
|
|
$builder |
|
|
|
->addLineBreak('-') |
|
|
@ -245,8 +266,9 @@ class TemplateMenuFactory |
|
|
|
->addLineBreak('-') |
|
|
|
|
|
|
|
// create
|
|
|
|
->addItem('publish', $this->addPublishItem($template, $bladeFile, $configuration)) |
|
|
|
->addLineBreak('-'); |
|
|
|
->addItem('Publish', $this->addPublishItem($template, $bladeFile)) |
|
|
|
->addLineBreak('-') |
|
|
|
->addItem('Cancel', $this->addCancelItem()); |
|
|
|
}; |
|
|
|
|
|
|
|
return $menu; |
|
|
|