From 8a128239d994c278d94904a98ca646eedbe47e4e Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Tue, 27 Aug 2019 11:21:39 +0200
Subject: [PATCH] Creo una classe filtro.

---
 src/Vola/UploadFile/FileUp.php |  123 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 123 insertions(+), 0 deletions(-)

diff --git a/src/Vola/UploadFile/FileUp.php b/src/Vola/UploadFile/FileUp.php
index 909e1ec..166988a 100644
--- a/src/Vola/UploadFile/FileUp.php
+++ b/src/Vola/UploadFile/FileUp.php
@@ -21,6 +21,9 @@
 
     private $request;
     private $beanFile;
+
+    /* @var $logger WrapLog */
+    private $logger;
     private $pathMap;
 
     public static function create($pathMap = null)
@@ -31,6 +34,12 @@
         $instance->pathMap = $pathMap;
 
         return $instance;
+    }
+
+    public function setLogger($logger)
+    {
+        $this->logger = WrapLog::create($logger);
+        return $this;
     }
 
     /**
@@ -100,6 +109,120 @@
         return $this;
     }
 
+    public function getRequestPathForUpload()
+    {
+        return $this->request->pathForUpload;
+    }
+
+    /**
+     * Ricostruisco i dati del BEAN del file caricato sul sistema
+     */
+    public function getFileBean()
+    {
+        if (!empty($_FILES)) {
+            $this->setTempNomeFile($_FILES['file']['tmp_name']);
+            $this->setOrigNomeFile($_FILES['file']['name']);
+            $this->setSizeFile($_FILES['file']['size']);
+        } else {
+            $this->setOrigNomeFile('');
+        }
+        return $this;
+    }
+
+    public function setTempNomeFile($x)
+    {
+        $this->beanFile->tempNomeFile = $x;
+    }
+
+    public function setOrigNomeFile($x)
+    {
+        $this->beanFile->origNomeFile = $x;
+    }
+
+    public function setSizeFile($x)
+    {
+        $this->beanFile->sizeFile = $x;
+    }
+
+    public function getTempNomeFile()
+    {
+        return $this->beanFile->tempNomeFile;
+    }
+
+    /**
+     * Ritorno l'estensione del file caricato dall'utente
+     * @return string Estenzione del file
+     */
+    public function getOrigNomeFileExt()
+    {
+        $path_info = pathinfo($this->getOrigNomeFile());
+        return $path_info['extension'];
+    }
+
+    public function getOrigNomeFile()
+    {
+        return $this->beanFile->origNomeFile;
+    }
+
+    public function getSizeFile()
+    {
+        return $this->beanFile->sizeFile;
+    }
+
+    /**
+     * Il tipo di operazione richiesta nella chiamata.
+     * Per selezionare il case switch da attivare
+     * @return string operazione da attivare
+     */
+    public function getOperazione()
+    {
+        return $this->request->operazione;
+    }
+
+    /**
+     * ricostruisco il nome del file da registrare su disco.
+     *
+     * Vengono ripuliti i caratteri strani e le lettere accentate.
+     * @return string
+     */
+    public function getNomeFileDisco()
+    {
+        $rand = $this->getRequestRandomValue();
+        $nome = $this->getOrigNomeFile();
+        return self::getNomeFile($rand, $nome);
+    }
+
+    public function getRequestRandomValue()
+    {
+        return $this->request->rand_value;
+    }
+
+    /**
+     * ricostruisco il nome del file da registrare su disco.
+     *
+     * Vengono ripuliti i caratteri strani e le lettere accentate.
+     * @param type $rand
+     * @param string $nome
+     * @return string
+     */
+    public static function getNomeFile($rand, $nome)
+    {
+        return $rand . "_" . FileUpload::clearNomeFile($nome);
+    }
+
+    /**
+     * @deprecated 0.3.2 utilizzare toString
+     */
+    public function stampaTutto()
+    {
+        if ($this->logger instanceof WrapLog) {
+            $this->logger->debug($this->request);
+            $this->logger->debug($this->beanFile);
+        } else {
+            error_log('errorlog non attivo');
+        }
+    }
+
     public function __toString()
     {
         return $this->toString();

--
Gitblit v1.8.0