From afb70751607b4ad7e2f1fcfe9a8766be9408d220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 6 Aug 2020 00:03:31 +0200 Subject: [PATCH] adding #21 --- app/Commands/NginxVhostsCommand.php | 17 ++++----- app/Factories/NginxVhostFactory.php | 12 +++++-- app/Menus/Nginx/NginxVhostGoBackAction.php | 36 +++++++++++++++++++ resources/nginx/templates/wordpress.blade.php | 4 +-- 4 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 app/Menus/Nginx/NginxVhostGoBackAction.php diff --git a/app/Commands/NginxVhostsCommand.php b/app/Commands/NginxVhostsCommand.php index 00c1ba8..e28e3b0 100644 --- a/app/Commands/NginxVhostsCommand.php +++ b/app/Commands/NginxVhostsCommand.php @@ -13,6 +13,7 @@ use App\Facades\TerminalHelper; use App\Facades\Menus\StylesFactory; use App\Helpers\NginxTemplateHelper; +use App\Menus\Nginx\NginxVhostGoBackAction; use App\BladeFile; @@ -161,7 +162,7 @@ class NginxVhostsCommand extends Command $file = str_replace('.service', '', $file); $builder->addRadioItem($file, function(CliMenu $menu) use (&$configuration) { - $configuration['php_fpm'] = $menu->getSelectedItem()->getText(); + $configuration['phpFpm'] = $menu->getSelectedItem()->getText(); }); } @@ -184,7 +185,7 @@ class NginxVhostsCommand extends Command $validator = v::key('domain', v::domain(false)) ->key('root', v::directory()) ->key('index', v::file()) - ->key('php_fpm', v::notEmpty()); + ->key('phpFpm', v::notEmpty()); try { $validator->assert($data); @@ -201,17 +202,11 @@ class NginxVhostsCommand extends Command // write configuration to file $bladeFile->put($template['name'], '/etc/nginx/sites-available/'.$filename, $configuration); - $menu->confirm('Success!')->display('Ok!'); - // prepare for close current submenu and open mainmenu - $parent = $menu->getParent(); - $menu->closeThis(); - - $mainmenu = $parent->getParent(); - - $mainmenu = NginxVhostFactory::addVhosts($mainmenu, NginxVhost::find(), self::VHOST_INDEX); - $mainmenu->open(); + // invoke action + $action = new NginxVhostGoBackAction(); + is_callable($action($menu)); } }) ->addLineBreak('-'); diff --git a/app/Factories/NginxVhostFactory.php b/app/Factories/NginxVhostFactory.php index beb3756..9562e23 100644 --- a/app/Factories/NginxVhostFactory.php +++ b/app/Factories/NginxVhostFactory.php @@ -9,6 +9,10 @@ use PhpSchool\CliMenu\MenuItem\MenuMenuItem; use PhpSchool\CliMenu\Style\SelectableStyle; use PhpSchool\CliMenu\Style\ItemStyle; +use PhpSchool\CliMenu\Action\ExitAction; + +use App\Menus\Nginx\NginxVhostGoBackAction; + class NginxVhostFactory { /** @@ -84,7 +88,7 @@ class NginxVhostFactory $builder ->setTitle('Nginx > '.$vhost['domain']) - ->setGoBackButtonText('Back') + ->disableDefaultItems() // edit configuration ->addItem('edit', function(CliMenu $menu) use ($vhost) { @@ -130,7 +134,9 @@ class NginxVhostFactory }) ->addLineBreak('-') ->addMenuItem($checkbox) - ->addLineBreak('-'); + ->addLineBreak('-') + ->addItem('Back', new NginxVhostGoBackAction()) + ->addItem('Exit', new ExitAction()); $submenu = $builder->build(); @@ -172,7 +178,7 @@ class NginxVhostFactory exec('nginx -c /etc/nginx/nginx.conf -t 2>&1', $output); $result = preg_match_all("/syntax is ok/", implode(' ', $output), $output); - // restart if success message was found + // restart if success message was found if ($result > 0) { exec('service nginx restart'); $menu->confirm('Success! ')->display('OK!'); diff --git a/app/Menus/Nginx/NginxVhostGoBackAction.php b/app/Menus/Nginx/NginxVhostGoBackAction.php new file mode 100644 index 0000000..85632c6 --- /dev/null +++ b/app/Menus/Nginx/NginxVhostGoBackAction.php @@ -0,0 +1,36 @@ + + */ +class NginxVhostGoBackAction +{ + // index for vhosts + const VHOST_INDEX = 0; + + /** + * + * @param CliMenu $menu [description] + * @return [type] [description] + */ + public function __invoke(CliMenu $menu): void + { + $parent = $menu->getParent(); + $menu->closeThis(); + + if ($parent->getParent()) { + $menu = $parent->getParent(); + } else { + $menu = $parent; + } + + $menu = NginxVhostFactory::addVhosts($menu, NginxVhost::find(), self::VHOST_INDEX); + $menu->open(); + } +} diff --git a/resources/nginx/templates/wordpress.blade.php b/resources/nginx/templates/wordpress.blade.php index b3190fa..8bf7014 100644 --- a/resources/nginx/templates/wordpress.blade.php +++ b/resources/nginx/templates/wordpress.blade.php @@ -35,12 +35,10 @@ deny all; } - find /lib/systemd/system/ -name 'php[0-9\.]*-fpm.service'php7.2-fpm - # php-fpm configuration. location ~ \.php(/|$) { fastcgi_split_path_info ^(.+\.php)(.*)$; - fastcgi_pass unix:/var/run/php/{{ $phpFpmVersion }}.sock; + fastcgi_pass unix:/var/run/php/{{ $phpFpm }}.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root;