mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-05 07:52:34 +00:00
#591 - php
This commit is contained in:
@ -21,6 +21,13 @@ public function change(Server $server, array $input): void
|
||||
$this->validate($server, $input);
|
||||
/** @var Service $service */
|
||||
$service = $server->php($input['version']);
|
||||
|
||||
if ($service->is_default) {
|
||||
throw ValidationException::withMessages(
|
||||
['version' => __('This version is already the default CLI')]
|
||||
);
|
||||
}
|
||||
|
||||
/** @var PHP $handler */
|
||||
$handler = $service->handler();
|
||||
$handler->setDefaultCli();
|
||||
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\PHP;
|
||||
|
||||
use App\Enums\PHP;
|
||||
use App\Enums\ServiceStatus;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class InstallNewPHP
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
*/
|
||||
public function install(Server $server, array $input): void
|
||||
{
|
||||
$php = new Service([
|
||||
'server_id' => $server->id,
|
||||
'type' => 'php',
|
||||
'type_data' => [
|
||||
'extensions' => [],
|
||||
'settings' => config('core.php_settings'),
|
||||
],
|
||||
'name' => 'php',
|
||||
'version' => $input['version'],
|
||||
'status' => ServiceStatus::INSTALLING,
|
||||
'is_default' => false,
|
||||
]);
|
||||
$php->save();
|
||||
|
||||
dispatch(function () use ($php): void {
|
||||
$php->handler()->install();
|
||||
$php->status = ServiceStatus::READY;
|
||||
$php->save();
|
||||
})->catch(function () use ($php): void {
|
||||
$php->delete();
|
||||
})->onConnection('ssh');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<string>>
|
||||
*/
|
||||
public static function rules(Server $server): array
|
||||
{
|
||||
return [
|
||||
'version' => [
|
||||
'required',
|
||||
Rule::in(config('core.php_versions')),
|
||||
Rule::notIn(array_merge($server->installedPHPVersions(), [PHP::NONE])),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use App\SSH\Services\PHP\PHP;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@ -12,11 +13,11 @@ class InstallPHPExtension
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function install(Server $server, array $input): Service
|
||||
{
|
||||
Validator::make($input, self::rules($server))->validate();
|
||||
|
||||
/** @var Service $service */
|
||||
$service = $server->php($input['version']);
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
use App\Models\Service;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@ -21,6 +22,8 @@ class UpdatePHPIni
|
||||
*/
|
||||
public function update(Server $server, array $input): void
|
||||
{
|
||||
Validator::make($input, self::rules($server))->validate();
|
||||
|
||||
/** @var Service $service */
|
||||
$service = $server->php($input['version']);
|
||||
|
||||
|
@ -26,6 +26,7 @@ public function install(Server $server, array $input): Service
|
||||
'version' => $input['version'],
|
||||
'status' => ServiceStatus::INSTALLING,
|
||||
]);
|
||||
$service->is_default = ! $server->defaultService($input['type']);
|
||||
|
||||
Validator::make($input, $service->handler()->creationRules($input))->validate();
|
||||
|
||||
|
87
app/Http/Controllers/PHPController.php
Normal file
87
app/Http/Controllers/PHPController.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\PHP\ChangeDefaultCli;
|
||||
use App\Actions\PHP\GetPHPIni;
|
||||
use App\Actions\PHP\InstallPHPExtension;
|
||||
use App\Actions\PHP\UpdatePHPIni;
|
||||
use App\Exceptions\SSHError;
|
||||
use App\Http\Resources\ServiceResource;
|
||||
use App\Models\Server;
|
||||
use App\Models\Service;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Spatie\RouteAttributes\Attributes\Get;
|
||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||
use Spatie\RouteAttributes\Attributes\Patch;
|
||||
use Spatie\RouteAttributes\Attributes\Post;
|
||||
use Spatie\RouteAttributes\Attributes\Prefix;
|
||||
|
||||
#[Prefix('servers/{server}/php')]
|
||||
#[Middleware(['auth', 'has-project'])]
|
||||
class PHPController extends Controller
|
||||
{
|
||||
#[Get('/', name: 'php')]
|
||||
public function index(Server $server): Response
|
||||
{
|
||||
$this->authorize('viewAny', [Service::class, $server]);
|
||||
|
||||
$installedVersions = Service::query()
|
||||
->where('type', 'php')
|
||||
->where('server_id', $server->id)
|
||||
->simplePaginate(config('web.pagination_size'));
|
||||
|
||||
return Inertia::render('php/index', [
|
||||
'installedVersions' => ServiceResource::collection($installedVersions),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Get('/{service}/ini', name: 'php.ini')]
|
||||
public function ini(Request $request, Server $server, Service $service): JsonResponse
|
||||
{
|
||||
$this->authorize('view', $service);
|
||||
|
||||
$ini = app(GetPHPIni::class)->getIni($server, $request->input());
|
||||
|
||||
return response()->json([
|
||||
'ini' => $ini,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Patch('/{service}/ini', name: 'php.ini.update')]
|
||||
public function updateIni(Request $request, Server $server, Service $service): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $service);
|
||||
|
||||
app(UpdatePHPIni::class)->update($server, $request->input());
|
||||
|
||||
return back()->with('success', 'PHP ini file updated successfully.');
|
||||
}
|
||||
|
||||
#[Post('/{service}/install-extension', name: 'php.install-extension')]
|
||||
public function installExtension(Request $request, Server $server, Service $service): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $service);
|
||||
|
||||
app(InstallPHPExtension::class)->install($server, $request->input());
|
||||
|
||||
return back()->with('info', 'PHP extension is being installed.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
#[Post('/{service}/default-cli', name: 'php.default-cli')]
|
||||
public function defaultCli(Request $request, Server $server, Service $service): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $service);
|
||||
|
||||
app(ChangeDefaultCli::class)->change($server, $request->input());
|
||||
|
||||
return back()->with('success', 'Default PHP CLI changed to '.$service->version.'.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user