Classi per la configurazione upload
Cristiano Magro
2018-01-16 1315436571376897ab09e3e9456d154e65c96842
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);
        }
    }
 
 
}