Project

General

Profile

Feature #5718 » File.php

Alexandre Martinez, 2009-12-11 14:21

 
<?php
/**
* Base class for file handling
*
* @author Alexandre Martinez <alexandre.martinez76@gmail.com>
*
*/
abstract class Tx_Extbase_Domain_Model_File extends Tx_Extbase_DomainObject_AbstractEntity {
/**
* FileReader class name
* @var string
*/
protected $readerClassName;
/**
* Result object class name
* @var string
*/
protected $resultClassName;
/**
* Validator class
* @var string
*/
protected $validatorClassName;
/**
* Name of the file
* @var string
* @notEmpty
*/
protected $name;
/**
* Mime type of file
* @var string
* @notEmpty
*/
protected $type;
/**
* Temp path for uploaded files
* @var string
*/
protected $tmp_name;
/**
* Path for saved file
* @var string
*/
protected $path;
/**
* Error code
* @var integer
*/
protected $error;
/**
* Size of the file
* @var integer
*/
protected $size;

/**
* Reader for the file, returns objects according to file content
* Depends on the file implementation
* @var Tx_Extabaseextended_Utility_AbstractFileReader
*/
protected $reader;
/**
* Property mapper
* @var Tx_Extbase_Property_Mapper
*/
protected $propertyMapper;
public function __construct($resultClassName='')
{
if ($resultClassName) $this->resultClassName=$resultClassName;
$reader=t3lib_div::makeInstance($this->readerClassName,$this->resultClassName,$this->validatorClassName);
$this->injectReader($reader);
}
/**
* Injector for FileReader
* @param Tx_Extabaseextended_Utility_FileReader $reader
* @return void
*/
public function injectReader($reader) {
$this->reader=$reader;
if ($this->propertyMapper) $this->reader->injectPropertyMapper($this->propertyMapper);
$this->reader->setFile($this);
}
/**
* Injector for propertyMapper
* @param Tx_Extbase_Property_Mapper $mapper
* @return unknown_type
*/
public function injectPropertyMapper(Tx_Extbase_Property_Mapper $mapper)
{
$this->propertyMapper=$mapper;
if ($this->reader) $this->reader->injectPropertyMapper($mapper);
}
/**
* Setter for name
* @param string $name
* @return void
*/
public function setName($name)
{
$this->name=$name;
}
/**
* Getter for name
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Setter for type
* @param string $type
* @return void
*/
public function setType($type)
{
$this->type=$type;
}
/**
* Getter for type
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Setter for tmp_name
* @param string $name
* @return void
*/
public function setTmp_name($name)
{
$this->tmp_name=$name;
}
/**
* Getter for tmp_name
* @return string
*/
public function getTmp_name()
{
return $this->tmp_name;
}
/**
* Setter for error
* @param integer $error
* @return void
*/
public function setError($error)
{
$this->error=$error;
}
/**
* Getter for error
* @return integer
*/
public function getError()
{
return $this->error;
}
/**
* Setter for size
* @param integer $size
* @return void
*/
public function setSize($size)
{
$this->size=$size;
}
/**
* Getter for size
* @return integer
*/
public function getSize()
{
return $this->size;
}
/**
* Getter for path property
* @var boolean $absolute whether the path to return is relative or absolute
* @return string
*/
public function getPath($absolute=false)
{
return ($absolute?PATH_site:"").$this->path;
}
/**
* Setter for path property
* @param string $path
* @return void
*/
public function setPath($path)
{
$this->path=$path;
}
/**
* Copies temp file in given folder
* @param string $folder
* @return void
*/
public function copyToFolder($folder)
{
$path=$folder."/".time()."_".$this->getName();
t3lib_div::upload_copy_move($this->getTmp_name(),$path);
$this->setPath($path);
}
}
(2-2/4)