diff options
Diffstat (limited to 'src/Http/Request.php')
-rw-r--r-- | src/Http/Request.php | 70 |
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()), '/'); } /** |