Commit 4a64df7a by pupi1985

Extract HTTP method to own variable

parent 175a7421
...@@ -29,6 +29,9 @@ class Router ...@@ -29,6 +29,9 @@ class Router
/** @var array */ /** @var array */
private $paramsConverterValues; private $paramsConverterValues;
/** @var string */
private $httpMethod;
public function __construct($routeData = array()) public function __construct($routeData = array())
{ {
$this->routes = $routeData; $this->routes = $routeData;
...@@ -39,6 +42,8 @@ class Router ...@@ -39,6 +42,8 @@ class Router
); );
$this->paramsConverterKeys = array_keys($paramsConverter); $this->paramsConverterKeys = array_keys($paramsConverter);
$this->paramsConverterValues = array_values($paramsConverter); $this->paramsConverterValues = array_values($paramsConverter);
$this->httpMethod = strtoupper($_SERVER['REQUEST_METHOD']);
} }
public function addRoute($id, $httpMethod, $routePath, $class, $func) public function addRoute($id, $httpMethod, $routePath, $class, $func)
...@@ -55,7 +60,7 @@ class Router ...@@ -55,7 +60,7 @@ class Router
list($httpMethod, $routePath, $callClass, $callFunc) = $route; list($httpMethod, $routePath, $callClass, $callFunc) = $route;
if (strtoupper($httpMethod) !== strtoupper($_SERVER['REQUEST_METHOD'])) { if (strtoupper($httpMethod) !== $this->httpMethod) {
continue; continue;
} }
...@@ -82,4 +87,14 @@ class Router ...@@ -82,4 +87,14 @@ class Router
{ {
return '#^' . str_replace($this->paramsConverterKeys, $this->paramsConverterValues, $routePath) . '$#'; return '#^' . str_replace($this->paramsConverterKeys, $this->paramsConverterValues, $routePath) . '$#';
} }
/**
* Return the HTTP method of the current request.
*
* @return string
*/
public function getHttpMethod()
{
return $this->httpMethod;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment