From 9120e92384a39c05bd8761b453136933d9386ea9 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Fri, 29 Dec 2017 18:27:56 +0100
Subject: [PATCH] Gestione errore mediante exception

---
 src/UploadFile/SetupUpload.class.php |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/UploadFile/SetupUpload.class.php b/src/UploadFile/SetupUpload.class.php
index 75b32d0..e21e31d 100644
--- a/src/UploadFile/SetupUpload.class.php
+++ b/src/UploadFile/SetupUpload.class.php
@@ -8,6 +8,7 @@
  * javascript di gestione del plupload
  *
  * @author Cristiano Magro
+ * 
  */
 class SetupUpload {
 
@@ -107,12 +108,25 @@
         return $this;
     }
 
+    /**
+     * Restituisce il numero massimo di file previsti nella coda
+     * @return integer Max numero file
+     */
     public function getNumMaxFiles() {
         return $this->numMaxFiles;
     }
 
-    public function setNumMaxFiles($x) {
-        $this->numMaxFiles = $x;
+    /**
+     * Viene impostato il numero massimo di file caricabili
+     * @param integer $numero
+     * @return \SetupUpload fluent style
+     */
+    public function setNumMaxFiles($numero) {
+        if(!is_integer($numero) || $numero <= 0){
+            throw new UploadFile_Exc();
+        } 
+        
+        $this->numMaxFiles = $numero;
         return $this;
     }
 
@@ -164,4 +178,24 @@
         return json_encode($dati);
     }
 
+    /**
+     * Converte una stringa nei corrispondenti bytes.
+     * 
+     * 1 Mb = 1024^2
+     * 
+     * @param string $strSize Stringa da convertire
+     * @return integer
+     */
+    public static function str2Bytes($strSize) {
+        $strUnit = strtolower($strSize);
+        $strUnit = preg_replace('/[^a-z]/', '', $strUnit);
+
+        $value = intval(preg_replace('/[^0-9]/', '', $strSize));
+
+        $Units = array('b' => 0, 'kb' => 1, 'mb' => 2, 'gb' => 3, 'tb' => 4);
+        $Exponent = isset($Units[$strUnit]) ? $Units[$strUnit] : 0;
+
+        return ($value * pow(1024, $Exponent));
+    }
+
 }

--
Gitblit v1.8.0