Classi per la configurazione upload
Cristiano Magro
2018-01-16 1315436571376897ab09e3e9456d154e65c96842
Wrapper per catturare il file caricato dall'interfaccia
5 files added
2 files modified
158 ■■■■■ changed files
composer.json 5 ●●●● patch | view | raw | blame | history
src/Vola/UploadFile/Autoloader.php 5 ●●●●● patch | view | raw | blame | history
src/Vola/UploadFile/Exc/Estension.php 14 ●●●●● patch | view | raw | blame | history
src/Vola/UploadFile/Exc/ExtensionNotValid.php 14 ●●●●● patch | view | raw | blame | history
src/Vola/UploadFile/Exc/FileNotExist.php 14 ●●●●● patch | view | raw | blame | history
src/Vola/UploadFile/FileUp.php 68 ●●●●● patch | view | raw | blame | history
tests/Vola/UploadFile/FileUpTest.php 38 ●●●●● patch | view | raw | blame | history
composer.json
@@ -6,5 +6,8 @@
            "name": "Cristiano Magro",
            "email": "cristiano.magro@vola.it"
        }
    ]
    ],
    "require-dev": {
        "phpunit/phpunit": "^4.8"
    }
}
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',
    );
    /**
src/Vola/UploadFile/Exc/Estension.php
New file
@@ -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 {
}
src/Vola/UploadFile/Exc/ExtensionNotValid.php
New file
@@ -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 {
}
src/Vola/UploadFile/Exc/FileNotExist.php
New file
@@ -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 {
}
src/Vola/UploadFile/FileUp.php
New file
@@ -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);
        }
    }
}
tests/Vola/UploadFile/FileUpTest.php
New file
@@ -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);
    }
}