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