]> _ Git - cubist_net.git/commitdiff
wip #6446 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Nov 2023 11:18:29 +0000 (12:18 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Nov 2023 11:18:29 +0000 (12:18 +0100)
src/Transfer/Driver.php
src/Transfer/Local.php
src/Transfer/SFTP.php

index 7381e8e6d486bf4b828406ab9cb5691b12658dba..33be5eb851c9e9f52d214e74c7e12aac92675cc3 100644 (file)
@@ -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
index b0b1a30d3a517f8d3d61b26ec4cf4f3d2e64dff6..a53b628570e45503d5dc567b2254f61cc4f66f1b 100644 (file)
@@ -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
index fe5215cddfb0422a9d73b4bd2c44e6cc9556f113..ace571743276786c1411908ffce3f5ffa51fcdeb 100644 (file)
@@ -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