From 8f33cc1a39b166026bffe569842af0e4ff32fee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Sat, 19 Nov 2016 04:41:29 +0100 Subject: [PATCH] Development --- src/Pecee/Http/Input/InputCollection.php | 12 +++---- src/Pecee/Http/Input/InputFile.php | 31 +++++++++++++++++-- src/Pecee/Http/Input/InputItem.php | 4 +-- .../Http/Middleware/BaseCsrfVerifier.php | 2 +- src/Pecee/Http/Request.php | 1 - src/Pecee/SimpleRouter/RouterEntry.php | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Pecee/Http/Input/InputCollection.php b/src/Pecee/Http/Input/InputCollection.php index b1d00c1..a495b45 100644 --- a/src/Pecee/Http/Input/InputCollection.php +++ b/src/Pecee/Http/Input/InputCollection.php @@ -41,17 +41,17 @@ class InputCollection implements \IteratorAggregate { $input = $this->findFirst($index); - if($input !== null) { - if(trim($input->getValue()) === '') { - return $default; - } - - return $input; + if($input !== null && trim($input->getValue()) !== '') { + return $input->getValue(); } return $default; } + public function getValue($index, $default = null) { + + } + /** * @param string $index * @throws \InvalidArgumentException diff --git a/src/Pecee/Http/Input/InputFile.php b/src/Pecee/Http/Input/InputFile.php index 71c2484..a7668c5 100644 --- a/src/Pecee/Http/Input/InputFile.php +++ b/src/Pecee/Http/Input/InputFile.php @@ -60,24 +60,48 @@ class InputFile extends InputItem return file_get_contents($this->tmpName); } + /** + * 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 = $error; + return $this; } /** @@ -101,9 +125,12 @@ class InputFile extends InputItem return $input; } - public function __toString() + /** + * @return string + */ + public function getValue() { - return (string)$this->tmpName; + return $this->tmpName; } } \ No newline at end of file diff --git a/src/Pecee/Http/Input/InputItem.php b/src/Pecee/Http/Input/InputItem.php index ff66845..71d0253 100644 --- a/src/Pecee/Http/Input/InputItem.php +++ b/src/Pecee/Http/Input/InputItem.php @@ -17,7 +17,7 @@ class InputItem } /** - * @return array + * @return string */ public function getName() { @@ -25,7 +25,7 @@ class InputItem } /** - * @return array + * @return string */ public function getValue() { diff --git a/src/Pecee/Http/Middleware/BaseCsrfVerifier.php b/src/Pecee/Http/Middleware/BaseCsrfVerifier.php index 68a9419..d09723a 100644 --- a/src/Pecee/Http/Middleware/BaseCsrfVerifier.php +++ b/src/Pecee/Http/Middleware/BaseCsrfVerifier.php @@ -56,7 +56,7 @@ class BaseCsrfVerifier implements IMiddleware if ($request->getMethod() !== 'get' && !$this->skip($request)) { - $token = $request->getInput()->post->getValue(static::POST_KEY); + $token = $request->getInput()->post->get(static::POST_KEY); // If the token is not posted, check headers for valid x-csrf-token if ($token === null) { diff --git a/src/Pecee/Http/Request.php b/src/Pecee/Http/Request.php index 11ac53e..a0b4603 100644 --- a/src/Pecee/Http/Request.php +++ b/src/Pecee/Http/Request.php @@ -16,7 +16,6 @@ class Request { $this->parseHeaders(); $this->input = new Input($this); - $this->host = $this->getHeader('http-host');; $this->uri = $this->getHeader('request-uri'); $this->method = strtolower($this->input->post->findFirst('_method', $this->getHeader('request-method'))); diff --git a/src/Pecee/SimpleRouter/RouterEntry.php b/src/Pecee/SimpleRouter/RouterEntry.php index 5b5ad89..285d05d 100644 --- a/src/Pecee/SimpleRouter/RouterEntry.php +++ b/src/Pecee/SimpleRouter/RouterEntry.php @@ -377,7 +377,7 @@ abstract class RouterEntry } if (count($this->where) > 0) { - $output['where'] = $this->where; + //$output['where'] = $this->where; } if (count($this->requestMethods) > 0) {