From 1f9243993367c95b49cc1d18d5fb86693342a92d Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Tue, 16 Jan 2018 18:53:38 +0100
Subject: [PATCH] Decodifico la chiave per determinare il path di savataggio
---
tests/Vola/UploadFile/FileUpTest.php | 8 ++++
src/Vola/UploadFile/FileUp.php | 54 ++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletions(-)
diff --git a/src/Vola/UploadFile/FileUp.php b/src/Vola/UploadFile/FileUp.php
index 03bd09f..e96add0 100644
--- a/src/Vola/UploadFile/FileUp.php
+++ b/src/Vola/UploadFile/FileUp.php
@@ -21,14 +21,66 @@
private $request;
private $beanFile;
- public static function create()
+ private $pathMap;
+
+ public static function create($pathMap = null)
{
$instance = new self();
$instance->request = new stdClass();
$instance->beanFile = new stdClass();
+ $instance->pathMap = $pathMap;
+
return $instance;
}
+ /**
+ * Imposto i path di destinazione del file
+ * @param string $cfgClassName nome della classe con i parametri di configurazione da utilizzare
+ * @return \Upload_FileUp
+ * @throws Upload_Exc_Error
+ */
+ public function setUploadPath(array $cfgPathKey)
+ {
+
+ $key = $this->request->dirDestinazione;
+ if (isset($cfgPathKey[$key])) {
+ $path = $cfgPathKey[$key];
+ $this->request->pathForUpload = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') . '/../' . $path;
+ } else {
+ throw new Upload_Exc_Error('Decodifica chiave percorso non definita');
+ }
+ return $this;
+ }
+
+ /**
+ * Recupero i parametri passati in GET nella chiamata.
+ *
+ * Costruisco una request con i parametri standard della chiamata: ope|dest|rand_value
+ * @return \Upload_FileUp
+ * @deprecated 0.3.2 usare readRequest();
+ */
+ public function getParametri()
+ {
+ $this->readRequest();
+ return $this;
+ }
+
+ /**
+ * Recupero i parametri passati in GET nella chiamata.
+ *
+ * Costruisco una request con i parametri standard della chiamata: ope|dest|rand_value
+ * @return \Upload_FileUp
+ * @since 0.3.2
+ */
+ public function readRequest()
+ {
+ $this->request->operazione = $_REQUEST['ope'];
+ $this->request->dirDestinazione = $_REQUEST['dest'];
+ $this->request->rand_value = $_REQUEST['rand_value'];
+
+ return $this;
+ }
+
public function __toString()
{
return $this->toString();
diff --git a/tests/Vola/UploadFile/FileUpTest.php b/tests/Vola/UploadFile/FileUpTest.php
index 4e5de34..538d077 100644
--- a/tests/Vola/UploadFile/FileUpTest.php
+++ b/tests/Vola/UploadFile/FileUpTest.php
@@ -35,4 +35,12 @@
$this->assertEquals($atteso, $this->object->toString());
$this->assertEquals($atteso, $text);
}
+
+ /**
+ * @expectedException Upload_Exc_Error
+ */
+ public function testExcepitonNessunaMappaPerDecodifica(){
+ $this->object->setUploadPath(array());
+ }
+
}
\ No newline at end of file
--
Gitblit v1.8.0