From 1315436571376897ab09e3e9456d154e65c96842 Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Tue, 16 Jan 2018 18:14:13 +0100
Subject: [PATCH] Wrapper per catturare il file caricato dall'interfaccia
---
src/Vola/UploadFile/Exc/FileNotExist.php | 14 ++++
tests/Vola/UploadFile/FileUpTest.php | 38 ++++++++++++
src/Vola/UploadFile/FileUp.php | 68 ++++++++++++++++++++++
composer.json | 7 +
src/Vola/UploadFile/Autoloader.php | 5 +
src/Vola/UploadFile/Exc/Estension.php | 14 ++++
src/Vola/UploadFile/Exc/ExtensionNotValid.php | 14 ++++
7 files changed, 158 insertions(+), 2 deletions(-)
diff --git a/composer.json b/composer.json
index f95409c..4d270f6 100644
--- a/composer.json
+++ b/composer.json
@@ -6,5 +6,8 @@
"name": "Cristiano Magro",
"email": "cristiano.magro@vola.it"
}
- ]
-}
\ No newline at end of file
+ ],
+ "require-dev": {
+ "phpunit/phpunit": "^4.8"
+ }
+}
diff --git a/src/Vola/UploadFile/Autoloader.php b/src/Vola/UploadFile/Autoloader.php
index a1e5514..647864b 100644
--- a/src/Vola/UploadFile/Autoloader.php
+++ b/src/Vola/UploadFile/Autoloader.php
@@ -26,6 +26,11 @@
'FileUpload' => 'FileUpload.class.php',
'SetupUpload' => 'SetupUpload.class.php',
'Upload_Exc_Error' => 'Exc/Error.php',
+ 'Upload_Exc_Extension' => 'Exc/Extension.php',
+ 'Upload_Exc_ExtensionNotValid' => 'Exc/ExtensionNotValid.php',
+ 'Upload_Exc_FileNotExist' => 'Exc/FileNotExist.php',
+ 'Upload_MgrFile' => 'MgrFile.php',
+ 'Upload_FileUp' => 'FileUp.php',
);
/**
diff --git a/src/Vola/UploadFile/Exc/Estension.php b/src/Vola/UploadFile/Exc/Estension.php
new file mode 100644
index 0000000..21f113d
--- /dev/null
+++ b/src/Vola/UploadFile/Exc/Estension.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Eccezioni
+ * @since 0.3.2
+ */
+
+
+/**
+ * Eccezione nel caso l'estensione del file non si a tra quelle permesse
+ * @since 0.3.2
+ */
+class Upload_Exc_Extension extends Upload_Exc_Error {
+
+}
\ No newline at end of file
diff --git a/src/Vola/UploadFile/Exc/ExtensionNotValid.php b/src/Vola/UploadFile/Exc/ExtensionNotValid.php
new file mode 100644
index 0000000..8741ca6
--- /dev/null
+++ b/src/Vola/UploadFile/Exc/ExtensionNotValid.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Eccezioni
+ * @since 0.3.2
+ */
+
+
+/**
+ * Eccezione nel caso l'estensione del file non si a tra quelle permesse
+ * @since 0.3.2
+ */
+class Upload_Exc_ExtensionNotValid extends Upload_Exc_Error {
+
+}
\ No newline at end of file
diff --git a/src/Vola/UploadFile/Exc/FileNotExist.php b/src/Vola/UploadFile/Exc/FileNotExist.php
new file mode 100644
index 0000000..41c52a7
--- /dev/null
+++ b/src/Vola/UploadFile/Exc/FileNotExist.php
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Eccezioni
+ * @since 0.3.2
+ */
+
+
+/**
+ * Eccezione nel caso l'estensione del file non si a tra quelle permesse
+ * @since 0.3.2
+ */
+class Upload_Exc_FileNotExist extends Upload_Exc_Error {
+
+}
\ No newline at end of file
diff --git a/src/Vola/UploadFile/FileUp.php b/src/Vola/UploadFile/FileUp.php
new file mode 100644
index 0000000..03bd09f
--- /dev/null
+++ b/src/Vola/UploadFile/FileUp.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Cristiano Magro
+ * Date: 16/01/2018
+ * Time: 16:57
+ * @package Plupload
+ * @since v0.3.2
+ */
+
+/**
+ * Class Upload_FileUp manipolazione dettagli file caricato dagestire.
+ *
+ * Si tratta di un wrapper per gestire il file appena caricato.
+ *
+ */
+class Upload_FileUp
+{
+
+ const EMPTY_OBJ = "vuoto";
+
+ private $request;
+ private $beanFile;
+ public static function create()
+ {
+ $instance = new self();
+ $instance->request = new stdClass();
+ $instance->beanFile = new stdClass();
+ return $instance;
+ }
+
+ public function __toString()
+ {
+ return $this->toString();
+ }
+
+ /**
+ * Creo una stringa della struttura interna per la stampa sul logger.
+ *
+ * @return mixed|string struttura interna per il log
+ */
+ public function toString()
+ {
+ $text = "Richiesta: " . $this->convertToString($this->request) . PHP_EOL;
+ $text .= "Bean: " . $this->convertToString($this->beanFile);
+ return $text;
+ }
+
+ /**
+ * Converto la struttura in una stringa per la stamapa.
+ *
+ * Se la struttura e' vuota ritorno "vuota"
+ * @param stdClass $data struttura dati
+ * @return string conversione della struttura
+ */
+ private function convertToString(stdClass $data)
+ {
+ //effettuo il cast ad array per testare se la classe e' vuota
+ $tmp = (array)$data;
+ if (empty($tmp)) {
+ return self::EMPTY_OBJ;
+ } else {
+ return print_r($data, true);
+ }
+ }
+
+
+}
diff --git a/tests/Vola/UploadFile/FileUpTest.php b/tests/Vola/UploadFile/FileUpTest.php
new file mode 100644
index 0000000..4e5de34
--- /dev/null
+++ b/tests/Vola/UploadFile/FileUpTest.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * User: Cristiano Magro
+ * Date: 16/01/2018
+ * Time: 17:13
+ */
+
+
+/**
+ * Implementazione dei test per la classe FileUp
+ *
+ * @author Cristiano Magro
+ * @since 0.3.2
+ */
+class FileUpTest extends PHPUnit_Framework_TestCase
+{
+
+ /** @var $object Upload_FileUp */
+ private $object;
+
+ /**
+ * Inizializzazione oggetto per i test
+ */
+ public function setUp()
+ {
+ $this->object = Upload_FileUp::create();
+ }
+
+ public function testConvertToStringEmpty()
+ {
+ $text = "" . $this->object;
+
+ $atteso = "Richiesta: vuoto" . PHP_EOL . "Bean: vuoto";
+
+ $this->assertEquals($atteso, $this->object->toString());
+ $this->assertEquals($atteso, $text);
+ }
+}
\ No newline at end of file
--
Gitblit v1.8.0