summaryrefslogtreecommitdiff
path: root/src/Http
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2017-09-11 17:52:55 +0200
committerGitHub <noreply@github.com>2017-09-11 17:52:55 +0200
commit359160613027a480620e22deef19ff883eaaeb21 (patch)
tree310600aaa23404f0cd7d3e198bacdbc93645da32 /src/Http
parent581b81f1b25dc6b6f0a3b34810c293738fd40217 (diff)
parent0a20883aa862779b48fd2a297456c2db04cffb95 (diff)
Merge pull request #344 from MyIgel/master
Prepared routing, added symfony http Closes #336 and closes #337
Diffstat (limited to 'src/Http')
-rw-r--r--src/Http/Request.php70
1 files changed, 26 insertions, 44 deletions
diff --git a/src/Http/Request.php b/src/Http/Request.php
index fcfc2600..f0235d45 100644
--- a/src/Http/Request.php
+++ b/src/Http/Request.php
@@ -3,88 +3,70 @@
namespace Engelsystem\Http;
use ErrorException;
+use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
-class Request
+class Request extends SymfonyRequest
{
/** @var self */
protected static $instance;
- /** @var array of POST data */
- protected $request;
-
- /** @var array of GET data */
- protected $query;
-
/**
- * Initialize request
+ * Get POST input
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
*/
- public function create()
+ public function postData($key, $default = null)
{
- $this->request = $_POST;
- $this->query = $_GET;
+ return $this->request->get($key, $default);
}
/**
- * Get GET input
+ * Get input data
*
* @param string $key
* @param mixed $default
* @return mixed
*/
- public function get($key, $default = null)
+ public function input($key, $default = null)
{
- if (!empty($this->query[$key])) {
- return $this->query[$key];
- }
-
- return $default;
+ return $this->get($key, $default);
}
/**
- * Get POST input
+ * Checks if the input exists
*
* @param string $key
- * @param mixed $default
- * @return mixed
+ * @return bool
*/
- public function post($key, $default = null)
+ public function has($key)
{
- if (!empty($this->request[$key])) {
- return $this->request[$key];
- }
+ $value = $this->input($key);
- return $default;
+ return !empty($value);
}
/**
- * Get input data
+ * Get the requested path
*
- * @param string $key
- * @param mixed $default
- * @return mixed
+ * @return string
*/
- public function input($key, $default = null)
+ public function path()
{
- $data = $this->request + $this->query;
+ $pattern = trim($this->getPathInfo(), '/');
- if (isset($data[$key])) {
- return $data[$key];
- }
-
- return $default;
+ return $pattern == '' ? '/' : $pattern;
}
/**
- * Checks if the input exists
+ * Return the current URL
*
- * @param string $key
- * @return bool
+ * @return string
*/
- public function has($key)
+ public function url()
{
- $data = $this->request + $this->query;
-
- return isset($data[$key]);
+ return rtrim(preg_replace('/\?.*/', '', $this->getUri()), '/');
}
/**