Added Uri::method() to get current HTTP method (GET/POST etc)

This commit is contained in:
Matias Griese 2018-08-02 22:41:54 +03:00
parent e4f2808870
commit 76fb11366b
3 changed files with 19 additions and 3 deletions

View File

@ -1,3 +1,9 @@
# v1.5.0-rc.2
## mm/dd/2018
1. [](#new)
* Added `Uri::method()` to get current HTTP method (GET/POST etc)
# v1.5.0-rc.1
## 07/31/2018

View File

@ -15,7 +15,7 @@ if (!is_file($autoload)) {
die("Please run: <i>bin/grav install</i>");
}
if (PHP_SAPI == 'cli-server') {
if (PHP_SAPI === 'cli-server') {
if (!isset($_SERVER['PHP_CLI_ROUTER'])) {
die("PHP webserver requires a router to run Grav, please use: <pre>php -S {$_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']} system/router.php</pre>");
}

View File

@ -371,6 +371,17 @@ class Uri
return $this->extension;
}
public function method()
{
$method = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
if ($method === 'POST' && isset($_SERVER['X-HTTP-METHOD-OVERRIDE'])) {
$method = strtoupper($_SERVER['X-HTTP-METHOD-OVERRIDE']);
}
return $method;
}
/**
* Return the scheme of the URI
*
@ -620,10 +631,9 @@ class Uri
}
return $ip;
}
/**
/**
* Returns current Uri.
*
* @return \Grav\Framework\Uri\Uri