mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
refactoring (#116)
- refactoring architecture - fix incomplete ssh logs - code editor for scripts in the app - remove Jobs and SSHCommands
This commit is contained in:
88
app/SSH/Services/PHP/PHP.php
Normal file
88
app/SSH/Services/PHP/PHP.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\SSH\Services\PHP;
|
||||
|
||||
use App\Exceptions\SSHCommandError;
|
||||
use App\Models\Service;
|
||||
use App\SSH\HasScripts;
|
||||
use App\SSH\Services\ServiceInterface;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PHP implements ServiceInterface
|
||||
{
|
||||
use HasScripts;
|
||||
|
||||
protected Service $service;
|
||||
|
||||
public function __construct(Service $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function install(): void
|
||||
{
|
||||
$server = $this->service->server;
|
||||
$server->ssh()->exec(
|
||||
$this->getScript('install-php.sh', [
|
||||
'version' => $this->service->version,
|
||||
'user' => $server->getSshUser(),
|
||||
]),
|
||||
'install-php-'.$this->service->version
|
||||
);
|
||||
}
|
||||
|
||||
public function uninstall(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript('uninstall-php.sh', [
|
||||
'version' => $this->service->version,
|
||||
]),
|
||||
'uninstall-php-'.$this->service->version
|
||||
);
|
||||
}
|
||||
|
||||
public function setDefaultCli(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript('change-default-php.sh', [
|
||||
'version' => $this->service->version,
|
||||
]),
|
||||
'change-default-php'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SSHCommandError
|
||||
*/
|
||||
public function installExtension($name): void
|
||||
{
|
||||
$result = $this->service->server->ssh()->exec(
|
||||
$this->getScript('install-php-extension.sh', [
|
||||
'version' => $this->service->version,
|
||||
'name' => $name,
|
||||
]),
|
||||
'install-php-extension-'.$name
|
||||
);
|
||||
$result = Str::substr($result, strpos($result, '[PHP Modules]'));
|
||||
if (! Str::contains($result, $name)) {
|
||||
throw new SSHCommandError('Failed to install extension');
|
||||
}
|
||||
}
|
||||
|
||||
public function installComposer(): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
$this->getScript('install-composer.sh'),
|
||||
'install-composer'
|
||||
);
|
||||
}
|
||||
|
||||
public function getPHPIni(): string
|
||||
{
|
||||
return $this->service->server->ssh()->exec(
|
||||
$this->getScript('get-php-ini.sh', [
|
||||
'version' => $this->service->version,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user