Development

- It's now possible to adjust the load-order for parameters on routes.
- Replaced PHP 7.1 deprecated `mcrypt_create_iv` function with `random_bytes` if it is available (requires > PHP7)
- Added `setIndex`, `setName` and `setValue` methods to `IInputItem` to allow for extendability.
- Cleanup and bug fixes.
This commit is contained in:
Simon Sessingø
2016-11-25 18:26:50 +01:00
parent 1c515119b4
commit 68fc6b76c0
6 changed files with 175 additions and 149 deletions
+148 -133
View File
@@ -4,6 +4,7 @@ namespace Pecee\Http\Input;
class InputFile implements IInputItem
{
public $index;
public $value;
public $name;
public $size;
public $type;
@@ -18,139 +19,6 @@ class InputFile implements IInputItem
$this->name = ucfirst(str_replace('_', ' ', $this->index));
}
/**
* @return string
*/
public function getIndex()
{
return $this->index;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return string
*/
public function getSize()
{
return $this->size;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return string
*/
public function getError()
{
return $this->error;
}
public function getMime()
{
return $this->getType();
}
/**
* @return string
*/
public function getTmpName()
{
return $this->tmpName;
}
public function getExtension()
{
return pathinfo($this->getName(), PATHINFO_EXTENSION);
}
public function move($destination)
{
return move_uploaded_file($this->tmpName, $destination);
}
public function getContents()
{
return file_get_contents($this->tmpName);
}
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Set file temp. name
* @param string $name
* @return static $this
*/
public function setTmpName($name)
{
$this->tmpName = $name;
return $this;
}
/**
* Set file size
* @param int $size
* @return static $this
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
/**
* Set type
* @param string $type
* @return static $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Set error
* @param int $error
* @return static $this
*/
public function setError($error)
{
$this->error = (int)$error;
return $this;
}
public function getValue()
{
return $this->getTmpName();
}
public function hasError()
{
return ($this->getError() !== 0);
}
/**
* Create from array
* @param array $values
@@ -172,6 +40,128 @@ class InputFile implements IInputItem
return $input;
}
/**
* @return string
*/
public function getIndex()
{
return $this->index;
}
public function setIndex($index)
{
$this->index = $index;
return $this;
}
/**
* @return string
*/
public function getSize()
{
return $this->size;
}
/**
* Set file size
* @param int $size
* @return static $this
*/
public function setSize($size)
{
$this->size = $size;
return $this;
}
public function getMime()
{
return $this->getType();
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* Set type
* @param string $type
* @return static $this
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
public function getExtension()
{
return pathinfo($this->getName(), PATHINFO_EXTENSION);
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
public function move($destination)
{
return move_uploaded_file($this->tmpName, $destination);
}
public function getContents()
{
return file_get_contents($this->tmpName);
}
public function setValue($value)
{
$this->value = $value;
return $this;
}
public function hasError()
{
return ($this->getError() !== 0);
}
/**
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* Set error
* @param int $error
* @return static $this
*/
public function setError($error)
{
$this->error = (int)$error;
return $this;
}
public function toArray()
{
return [
@@ -187,4 +177,29 @@ class InputFile implements IInputItem
{
return $this->getValue();
}
public function getValue()
{
return $this->getTmpName();
}
/**
* @return string
*/
public function getTmpName()
{
return $this->tmpName;
}
/**
* Set file temp. name
* @param string $name
* @return static $this
*/
public function setTmpName($name)
{
$this->tmpName = $name;
return $this;
}
}