From 0c8da1b9e4a2def6d36c0c83c3dde6d019398280 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Tue, 16 Jan 2018 19:15:15 +0100
Subject: [PATCH] Refactor decodifico il path dalla mappa e dalla request
---
src/Vola/UploadFile/FileUp.php | 87 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 86 insertions(+), 1 deletions(-)
diff --git a/src/Vola/UploadFile/FileUp.php b/src/Vola/UploadFile/FileUp.php
index 03bd09f..909e1ec 100644
--- a/src/Vola/UploadFile/FileUp.php
+++ b/src/Vola/UploadFile/FileUp.php
@@ -21,12 +21,83 @@
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.
+ *
+ * Ricavo dalla mappa il path su cui memorizzare il file corrente, sulla base del parametro
+ * passato nella Request. Se non trovo corrispondenza viene lanciata eccezione.
+ * @param array $cfgPathMap elenco percorsi validi per la memorizzazione.
+ * @return \Upload_FileUp fluent style
+ * @throws Upload_Exc_Error
+ */
+ public function decodeUploadPath(array $cfgPathMap)
+ {
+ $this->pathMap = $cfgPathMap;
+ $key = $this->getRequestValue('dirDestinazione', null);
+
+ $path = $this->getMapValue($key);
+ $pathDocumentRoot = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT');
+
+ //genero il percorso reale dove andrà salvato il file
+ $this->request->pathForUpload = $pathDocumentRoot. '/../' . $path;
+ return $this;
+ }
+
+ /**
+ * Ritorno il valore della Request preso dalla chiamata.
+ *
+ * Se non è definito ritorno il valore di default|null
+ * @param string $nomeParam
+ * @param string $default
+ * @return mixed null|valore chiamata
+ */
+ public function getRequestValue($nomeParam, $default = null)
+ {
+ if (isset($this->request->{$nomeParam})) {
+ return $this->request->{$nomeParam};
+ }
+ return $default;
+ }
+
+ /**
+ * 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()
@@ -64,5 +135,19 @@
}
}
+ /**
+ * Decodifico mediante la mappa il percorso da utilizzare.
+ * @param $chiave della Request per il percorso
+ * @return mixed path associato
+ * @throws Upload_Exc_Error
+ * @since 0.3.2
+ */
+ protected function getMapValue($chiave)
+ {
+ if (!isset($cfgPathMap[$chiave])) {
+ throw new Upload_Exc_Error('Decodifica chiave percorso non definita');
+ }
+ return $cfgPathMap[$chiave];
+ }
}
--
Gitblit v1.8.0