Browse Source

adding #21

release/0.1
Björn 4 years ago
parent
commit
afb7075160
4 changed files with 52 additions and 17 deletions
  1. +6
    -11
      app/Commands/NginxVhostsCommand.php
  2. +9
    -3
      app/Factories/NginxVhostFactory.php
  3. +36
    -0
      app/Menus/Nginx/NginxVhostGoBackAction.php
  4. +1
    -3
      resources/nginx/templates/wordpress.blade.php

+ 6
- 11
app/Commands/NginxVhostsCommand.php View File

@ -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('-');


+ 9
- 3
app/Factories/NginxVhostFactory.php View File

@ -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!');


+ 36
- 0
app/Menus/Nginx/NginxVhostGoBackAction.php View File

@ -0,0 +1,36 @@
<?php
namespace App\Menus\Nginx;
use PhpSchool\CliMenu\CliMenu;
use App\Facades\NginxVhost;
use App\Facades\NginxVhostFactory;
/**
* @author Aydin Hassan <aydin@hotmail.co.uk>
*/
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();
}
}

+ 1
- 3
resources/nginx/templates/wordpress.blade.php View File

@ -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;


Loading…
Cancel
Save