Desacople e inyeccion de dependencias

This commit is contained in:
imnavajas
2025-07-22 16:01:34 +02:00
parent a1aaa095d4
commit 9ed397e9ad
9 changed files with 391 additions and 154 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace App\Libraries;
use phpseclib3\Net\SFTP;
use Config\PresupuestoSFTP;
class SftpClientWrapper
{
protected SFTP $client;
public function __construct(PresupuestoSFTP $config)
{
$this->client = new SFTP($config->host, $config->port);
$this->client->login($config->username, $config->password);
}
public function upload(string $local, string $remote): bool
{
return $this->client->put($remote, $local, SFTP::SOURCE_LOCAL_FILE);
}
public function delete(string $remote): bool
{
return $this->client->delete($remote);
}
public function exists(string $remote): bool
{
return $this->client->file_exists($remote);
}
public function mkdir(string $remote): bool
{
return $this->client->mkdir($remote, true);
}
public function chmod(string $path, int $permissions): bool
{
return $this->client->chmod($permissions, $path);
}
}