]> _ Git - cubist_net.git/commitdiff
wip #7175 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Nov 2024 13:27:40 +0000 (14:27 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 5 Nov 2024 13:27:40 +0000 (14:27 +0100)
.editorconfig [new file with mode: 0644]
composer.json
src/Transfer/Driver.php
src/Transfer/FTP.php
src/Transfer/Local.php
src/Transfer/S3.php [new file with mode: 0644]

diff --git a/.editorconfig b/.editorconfig
new file mode 100644 (file)
index 0000000..6f313c6
--- /dev/null
@@ -0,0 +1,15 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+trim_trailing_whitespace = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.yml]
+indent_size = 2
index cfb3895175e7148e7a2a83676ffc68a82ccb2546..590a5b135b695b11ba6cbde31977fab1a173e06d 100644 (file)
@@ -25,7 +25,8 @@
     "php": ">=7.0.0",
     "ext-ssh2": "*",
     "cubist/util": "dev-master",
-    "ext-ftp": "*"
+    "ext-ftp": "*",
+    "aws/aws-sdk-php": "^3.325"
   },
   "suggest": {
 
index c09678360b72cdb61dbc635bcf52f85453538daf..0561b161140618f60c4cbf455b99540a40bf727a 100644 (file)
@@ -52,16 +52,17 @@ abstract class Driver
 
     abstract protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false);
 
-        /**
+    /**
      * @param $source string
      * @param $dest string
      * @param $mirror bool
      * @param $dryrun bool
      * @return CommandLine
      */
-    public function copy($source, $dest, $mirror = false, $dryrun = false) {
-        if($this->checkConnexion() !== true) {
-            throw new \Exception('Unabled to connect to this server (error code : '. $this->checkConnexion() .' )');
+    public function copy($source, $dest, $mirror = false, $dryrun = false)
+    {
+        if ($this->checkConnexion() !== true) {
+            throw new \Exception('Unabled to connect to this server (error code : ' . $this->checkConnexion() . ' )');
         }
         return $this->synchronizeFiles($source, $dest, $mirror, $dryrun);
     }
index ab2b3855689b4dc3c5d08b91b8b3bc4ef4bb876c..9bfbaabe755fae3c084992b9b529a479b8d792bb 100644 (file)
@@ -5,7 +5,8 @@ namespace Cubist\Net\Transfer;
 use Cubist\Util\CommandLine\LFTP;
 use Cubist\Util\Files\Files;
 
-class FTP extends Driver {
+class FTP extends Driver
+{
 
     const ERROR_MISSING_HOST = 0;
 
@@ -19,7 +20,8 @@ class FTP extends Driver {
 
     protected $port = 21;
 
-    protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false) {
+    protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false)
+    {
         $lftp = new LFTP();
         $lftp->setServer($this->getServer());
         $lftp->setSrc($source);
@@ -30,37 +32,38 @@ class FTP extends Driver {
         return $lftp;
     }
 
-    public function checkConnexion($data = []) {
+    public function checkConnexion($data = [])
+    {
 
         $data['port'] = $data['port'] ?? $this->port;
         $data = [
             'username' => $data['username'] ?? $this->getServer()->getUsername(),
             'password' => $data['password'] ?? $this->getServer()->getPassword(),
             'host' => $data['host'] ?? $this->getServer()->getHost(),
-            'port' => array_key_exists('port',$data) ? $data['port'] : $this->getServer()->getPort(),
+            'port' => array_key_exists('port', $data) ? $data['port'] : $this->getServer()->getPort(),
         ];
 
-        if(!$data['host']) {
+        if (!$data['host']) {
             return self::ERROR_MISSING_HOST;
         } else {
             try {
                 $ftp = $data['port'] ? ftp_connect($data['host'], $data['port']) : ftp_connect($data['host']);
-            } catch(\Exception $e) {
+            } catch (\Exception $e) {
                 return static::ERROR_INVALID_PARAM;
             }
 
-            if($ftp) {
+            if ($ftp) {
                 if (@ftp_login($ftp, $data['username'], $data['password'])) {
                     try {
                         $tmp = Files::tempnam(); //on créé un fichier temporaire
-                        $this->copyFile($tmp,$this->getServer()->getBasePath());
-                    } catch(\Exception $e) {
+                        $this->copyFile($tmp, $this->getServer()->getBasePath());
+                    } catch (\Exception $e) {
                         return static::ERROR_SEND_FILE;
                     }
 
-                    $file = $this->getServer()->getBasePath().$this->getTestFilename($tmp);
+                    $file = $this->getServer()->getBasePath() . $this->getTestFilename($tmp);
                     $contents = ftp_raw($ftp, "SIZE $file");
-                    if(strstr($contents[0],"213")) { //on vérifie si le code 213 est présent
+                    if (strstr($contents[0], "213")) { //on vérifie si le code 213 est présent
                         ftp_raw($ftp, "DELE $file"); //on supprime le fichier distant
                         unlink($tmp); //on supprime le fichier en local
                         ftp_close($ftp);
@@ -78,8 +81,9 @@ class FTP extends Driver {
 
     }
 
-    public function getTestFilename($file) {
-        $filepath = explode('/',$file);
+    public function getTestFilename($file)
+    {
+        $filepath = explode('/', $file);
         return end($filepath);
     }
 }
\ No newline at end of file
index 0169b95738afbdadf68c7d45139411af61a2f757..beb00a2f141514a8ae48b33cb74188b659e73e15 100644 (file)
@@ -75,8 +75,9 @@ class Local extends Driver
         return copy($source, $this->_basePath() . '/' . $dest);
     }
 
-    public function checkConnexion($data = []) {
-        if(file_exists($this->getRootPath().'status')) {
+    public function checkConnexion($data = [])
+    {
+        if (file_exists($this->getRootPath() . 'status')) {
             return true;
         } else {
             return static::ERROR_FOLDER_UNMOUNT;
diff --git a/src/Transfer/S3.php b/src/Transfer/S3.php
new file mode 100644 (file)
index 0000000..9e51851
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace Cubist\Net\Transfer;
+
+class S3 extends Driver
+{
+
+    public function checkConnexion($data = [])
+    {
+
+    }
+
+    protected function synchronizeFiles($source, $dest, $mirror = false, $dryrun = false)
+    {
+
+    }
+}