* @package tao */ abstract class tao_helpers_form_data_FileDescription { // --- ASSOCIATIONS --- // --- ATTRIBUTES --- /** * The name of the file e.g. thumbnail.png. * * @access private * @var string */ private $name = null; /** * The size of the file in bytes. * * @access private * @var int */ private $size = null; /** * Reference to the stored file * @var string */ private $fileSerial = null; /** * The filed stored in persistent memory (if already stored). * * @access private * @var File */ private $file = null; // --- OPERATIONS --- /** * Creates a new instance of FileDescription. * * @access public * @author Jerome Bogaerts * @param string name The name of the file such as thumbnail.svg * @param int size The size of the file in bytes. * @return mixed */ public function __construct($name, $size) { $this->name = $name; $this->size = $size; } /** * Returns the name of the file e.g. test.xml. * * @access public * @author Jerome Bogaerts * @return string */ public function getName() { if (is_null($this->name)) { $this->name = is_null($this->getFile()) ? '' : $this->getFile()->getBasename(); } return $this->name; } /** * Returns the size of the file in bytes. * * @access public * @author Jerome Bogaerts * @return int */ public function getSize() { if (is_null($this->size)) { $this->size = is_null($this->getFile()) ? 0 : $this->getFile()->getSize(); } return $this->size; } /** * Gets the file bound to the FileDescription (returns null if not file * in persistent memory). * * @access public * @author Jerome Bogaerts, * @return File */ public function getFile() { if (is_null($this->file)) { $referencer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID); $this->file = $referencer->unserialize($this->getFileSerial()); } return $this->file; } public function getFileSerial() { return $this->fileSerial; } /** * Set the File corresponding to the FileDescription in persistent memory. * * @access public * @author Jerome Bogaerts, * @param File file * @return void */ public function setFile($serial) { $this->fileSerial = $serial; } public function getServiceLocator() { return ServiceManager::getServiceManager(); } }