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
+2 -2
View File
@@ -14,8 +14,8 @@ class CsrfToken
*/ */
public static function generateToken() public static function generateToken()
{ {
if (function_exists('mcrypt_create_iv')) { if (function_exists('random_bytes')) {
return bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)); return bin2hex(random_bytes(32));
} }
return bin2hex(openssl_random_pseudo_bytes(32)); return bin2hex(openssl_random_pseudo_bytes(32));
+6
View File
@@ -6,10 +6,16 @@ interface IInputItem
public function getIndex(); public function getIndex();
public function setIndex($index);
public function getName(); public function getName();
public function setName($name);
public function getValue(); public function getValue();
public function setValue($value);
public function __toString(); public function __toString();
} }
-4
View File
@@ -188,10 +188,6 @@ class Input
*/ */
public function all(array $filter = null) public function all(array $filter = null)
{ {
if ($this->invalidContentType === true) {
return [];
}
$output = $_POST; $output = $_POST;
if ($this->request->getMethod() === 'post') { if ($this->request->getMethod() === 'post') {
+148 -133
View File
@@ -4,6 +4,7 @@ namespace Pecee\Http\Input;
class InputFile implements IInputItem class InputFile implements IInputItem
{ {
public $index; public $index;
public $value;
public $name; public $name;
public $size; public $size;
public $type; public $type;
@@ -18,139 +19,6 @@ class InputFile implements IInputItem
$this->name = ucfirst(str_replace('_', ' ', $this->index)); $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 * Create from array
* @param array $values * @param array $values
@@ -172,6 +40,128 @@ class InputFile implements IInputItem
return $input; 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() public function toArray()
{ {
return [ return [
@@ -187,4 +177,29 @@ class InputFile implements IInputItem
{ {
return $this->getValue(); 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;
}
} }
+15 -9
View File
@@ -24,6 +24,13 @@ class InputItem implements IInputItem
return $this->index; return $this->index;
} }
public function setIndex($index)
{
$this->index = $index;
return $this;
}
/** /**
* @return string * @return string
*/ */
@@ -32,14 +39,6 @@ class InputItem implements IInputItem
return $this->name; return $this->name;
} }
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/** /**
* Set input name * Set input name
* @param string $name * @param string $name
@@ -52,6 +51,14 @@ class InputItem implements IInputItem
return $this; return $this;
} }
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/** /**
* Set input value * Set input value
* @param string $value * @param string $value
@@ -68,5 +75,4 @@ class InputItem implements IInputItem
{ {
return (string)$this->value; return (string)$this->value;
} }
} }
+4 -1
View File
@@ -384,7 +384,10 @@ abstract class Route implements IRoute
} }
if (count($this->parameters) > 0) { if (count($this->parameters) > 0) {
$values['parameters'] = $this->parameters; /* Ensure the right order + values */
$parameters = ($values['parameters'] + $this->parameters);
$parameters = array_merge($parameters, $this->parameters);
$this->setParameters($parameters);
} }
if (count($this->middlewares) > 0) { if (count($this->middlewares) > 0) {