<?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;
|
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
|
* @param string $cfgClassName nome della classe con i parametri di configurazione da utilizzare
|
* @return \Upload_FileUp
|
* @throws Upload_Exc_Error
|
*/
|
public function setUploadPath(array $cfgPathKey)
|
{
|
|
$key = $this->request->dirDestinazione;
|
if (isset($cfgPathKey[$key])) {
|
$path = $cfgPathKey[$key];
|
$this->request->pathForUpload = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') . '/../' . $path;
|
} else {
|
throw new Upload_Exc_Error('Decodifica chiave percorso non definita');
|
}
|
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
|
* @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()
|
{
|
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);
|
}
|
}
|
|
|
}
|