|
@ -7,10 +7,13 @@ use PhpSchool\CliMenu\CliMenu; |
|
|
use PhpSchool\CliMenu\MenuItem\CheckboxItem; |
|
|
use PhpSchool\CliMenu\MenuItem\CheckboxItem; |
|
|
use PhpSchool\CliMenu\Style\SelectableStyle; |
|
|
use PhpSchool\CliMenu\Style\SelectableStyle; |
|
|
use PhpSchool\CliMenu\MenuItem\MenuMenuItem; |
|
|
use PhpSchool\CliMenu\MenuItem\MenuMenuItem; |
|
|
|
|
|
use PhpSchool\CliMenu\MenuItem\StaticItem; |
|
|
|
|
|
|
|
|
use Respect\Validation\Validator as v; |
|
|
use Respect\Validation\Validator as v; |
|
|
use Respect\Validation\Exceptions\NestedValidationException; |
|
|
use Respect\Validation\Exceptions\NestedValidationException; |
|
|
|
|
|
|
|
|
|
|
|
use App\Menus\ItemValidator; |
|
|
|
|
|
|
|
|
use App\BladeFile; |
|
|
use App\BladeFile; |
|
|
use App\Helpers\NginxTemplateHelper; |
|
|
use App\Helpers\NginxTemplateHelper; |
|
|
|
|
|
|
|
@ -87,9 +90,9 @@ class TemplateMenuFactory |
|
|
* @param string $label |
|
|
* @param string $label |
|
|
* @param array $configuration |
|
|
* @param array $configuration |
|
|
*/ |
|
|
*/ |
|
|
private function addInputItem($key, $label, &$configuration) |
|
|
|
|
|
|
|
|
private function addInputItem($key, $label, &$configuration, $itemValidator = NULL) |
|
|
{ |
|
|
{ |
|
|
$callable = function(CliMenu $menu) use ($key, $label, &$configuration) |
|
|
|
|
|
|
|
|
$callable = function(CliMenu $menu) use ($key, $label, &$configuration, $itemValidator) |
|
|
{ |
|
|
{ |
|
|
$input = $menu->askText(); |
|
|
$input = $menu->askText(); |
|
|
|
|
|
|
|
@ -101,6 +104,11 @@ class TemplateMenuFactory |
|
|
$configuration[$key] = $result->fetch(); |
|
|
$configuration[$key] = $result->fetch(); |
|
|
|
|
|
|
|
|
$menu->getSelectedItem()->setText($label.': '.$result->fetch()); |
|
|
$menu->getSelectedItem()->setText($label.': '.$result->fetch()); |
|
|
|
|
|
|
|
|
|
|
|
if ($itemValidator) { |
|
|
|
|
|
$itemValidator->validate($menu, $menu->getSelectedItem(), [ $key => $result->fetch() ]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$menu->redraw(); |
|
|
$menu->redraw(); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -121,12 +129,9 @@ class TemplateMenuFactory |
|
|
// getting configuration
|
|
|
// getting configuration
|
|
|
$data = $configuration; |
|
|
$data = $configuration; |
|
|
|
|
|
|
|
|
// add directory for validator to check if file exits
|
|
|
|
|
|
$data['index'] = $data['root'].'/'.$data['index']; |
|
|
|
|
|
|
|
|
|
|
|
$validator = v::key('domain', v::domain(false)) |
|
|
$validator = v::key('domain', v::domain(false)) |
|
|
->key('root', v::directory()) |
|
|
|
|
|
->key('index', v::file()) |
|
|
|
|
|
|
|
|
->key('root', v::notEmpty()) |
|
|
|
|
|
->key('index', v::notEmpty()) |
|
|
->key('phpFpm', v::notEmpty()); |
|
|
->key('phpFpm', v::notEmpty()); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
@ -211,6 +216,9 @@ class TemplateMenuFactory |
|
|
|
|
|
|
|
|
$checkboxRedirect->setChecked($configuration['redirect_www']); |
|
|
$checkboxRedirect->setChecked($configuration['redirect_www']); |
|
|
|
|
|
|
|
|
|
|
|
$validator = v::key('root', v::directory()); |
|
|
|
|
|
$itemValidator = new ItemValidator($validator); |
|
|
|
|
|
|
|
|
$builder |
|
|
$builder |
|
|
->setTitle('Nginx > Add > '.$template['name']) |
|
|
->setTitle('Nginx > Add > '.$template['name']) |
|
|
->setGoBackButtonText('Cancel') |
|
|
->setGoBackButtonText('Cancel') |
|
@ -219,7 +227,7 @@ class TemplateMenuFactory |
|
|
->addItem('domain: -', $this->addInputItem('domain', 'domain', $configuration)) |
|
|
->addItem('domain: -', $this->addInputItem('domain', 'domain', $configuration)) |
|
|
|
|
|
|
|
|
// input root
|
|
|
// input root
|
|
|
->addItem('root: -', $this->addInputItem('root', 'root', $configuration)) |
|
|
|
|
|
|
|
|
->addItem('root: -', $this->addInputItem('root', 'root', $configuration, $itemValidator)) |
|
|
|
|
|
|
|
|
// input index
|
|
|
// input index
|
|
|
->addItem('index: '.$configuration['index'], $this->addInputItem('index', 'index', $configuration)) |
|
|
->addItem('index: '.$configuration['index'], $this->addInputItem('index', 'index', $configuration)) |
|
|