From: Vincent Vanwaelscappel Date: Tue, 7 Nov 2023 11:18:29 +0000 (+0100) Subject: wip #6446 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=ad181c0baff06f6aa41bd2b407cbe170e3c00509;p=cubist_net.git wip #6446 @0.5 --- diff --git a/src/Transfer/Driver.php b/src/Transfer/Driver.php index 7381e8e..33be5eb 100644 --- a/src/Transfer/Driver.php +++ b/src/Transfer/Driver.php @@ -5,49 +5,57 @@ namespace Cubist\Net\Transfer; use Cubist\Util\CommandLine; use Cubist\Util\Text; -abstract class Driver { - - /** - * @var IServer - */ - protected $_server; - - public function __construct(IServer $server) { - - $this->setServer($server); - } - - /** - * @return IServer - */ - public function getServer() { - return $this->_server; - } - - /** - * @param IServer $server - */ - public function setServer($server) { - $this->_server = $server; - } - - public static function cleanInstallDir($path) { - $path = str_replace('/\.{2,}/', '', $path); - $path = preg_replace('/\/{2,}/', '/', $path); - $path = trim($path, '/'); - return Text::str2URL($path, '-', true); - } - - protected function _destPath($path) { - return self::cleanInstallDir($path); - } - - /** - * @param $source string - * @param $dest string - * @param $mirror bool - * @param $dryrun bool - * @return CommandLine - */ - abstract public function copy($source, $dest, $mirror = false, $dryrun = false); +abstract class Driver +{ + + /** + * @var IServer + */ + protected $_server; + + public function __construct(IServer $server) + { + + $this->setServer($server); + } + + /** + * @return IServer + */ + public function getServer() + { + return $this->_server; + } + + /** + * @param IServer $server + */ + public function setServer($server) + { + $this->_server = $server; + } + + public static function cleanInstallDir($path) + { + $path = str_replace('/\.{2,}/', '', $path); + $path = preg_replace('/\/{2,}/', '/', $path); + $path = trim($path, '/'); + return Text::str2URL($path, '-', true); + } + + protected function _destPath($path) + { + return self::cleanInstallDir($path); + } + + /** + * @param $source string + * @param $dest string + * @param $mirror bool + * @param $dryrun bool + * @return CommandLine + */ + abstract public function copy($source, $dest, $mirror = false, $dryrun = false); + + abstract public function copyFile($source, $dest); } \ No newline at end of file diff --git a/src/Transfer/Local.php b/src/Transfer/Local.php index b0b1a30..a53b628 100644 --- a/src/Transfer/Local.php +++ b/src/Transfer/Local.php @@ -4,47 +4,63 @@ namespace Cubist\Net\Transfer; use Cubist\Util\CommandLine\Rsync; -class Local extends Driver { - protected $_rootPath = ''; - - public function __construct(IServer $server, $rootPath = null) { - parent::__construct($server); - if (null !== $rootPath) { - $this->setRootPath($rootPath); - } - } - - /** - * @param string $rootPath - */ - public function setRootPath($rootPath) { - $this->_rootPath = $rootPath; - } - - /** - * @return string - */ - public function getRootPath() { - return $this->_rootPath; - } - - /** - * @param $path - * @return string - */ - protected function _destPath($path) { - return rtrim($this->getRootPath(), '/') . '/' . self::cleanInstallDir($path) . '/'; - } - - public function copy($source, $dest, $mirror = false, $dryrun = false) { - $rsync = new Rsync($source, $dest); - $rsync->setServer($this->getServer()); - $rsync->setBasePath(rtrim($this->getRootPath(), '/') . '/' . ltrim($this->getServer()->getBasePath(), '/')); - $rsync->setMirror($mirror); - $rsync->setDryRun($dryrun); - $rsync->execute(); - return $rsync; - } +class Local extends Driver +{ + protected $_rootPath = ''; + + public function __construct(IServer $server, $rootPath = null) + { + parent::__construct($server); + if (null !== $rootPath) { + $this->setRootPath($rootPath); + } + } + + /** + * @param string $rootPath + */ + public function setRootPath($rootPath) + { + $this->_rootPath = $rootPath; + } + + /** + * @return string + */ + public function getRootPath() + { + return $this->_rootPath; + } + + /** + * @param $path + * @return string + */ + protected function _destPath($path) + { + return rtrim($this->getRootPath(), '/') . '/' . self::cleanInstallDir($path) . '/'; + } + + public function copy($source, $dest, $mirror = false, $dryrun = false) + { + $rsync = new Rsync($source, $dest); + $rsync->setServer($this->getServer()); + $rsync->setBasePath($this->_basePath()); + $rsync->setMirror($mirror); + $rsync->setDryRun($dryrun); + $rsync->execute(); + return $rsync; + } + + protected function _basePath() + { + return rtrim($this->getRootPath(), '/') . '/' . ltrim($this->getServer()->getBasePath(), '/'); + } + + public function copyFile($source, $dest) + { + return copy($source, $this->_basePath() . '/' . $dest); + } } \ No newline at end of file diff --git a/src/Transfer/SFTP.php b/src/Transfer/SFTP.php index fe5215c..ace5717 100644 --- a/src/Transfer/SFTP.php +++ b/src/Transfer/SFTP.php @@ -17,4 +17,9 @@ class SFTP extends Driver { $rclone->execute(); return $rclone; } + + public function copyFile($source, $dest) + { + // TODO: Implement copyFile() method. + } } \ No newline at end of file