namespace PHPRouter;
use Exception;
-use PHPRouter\RouteCollection;
+use Fig\Http\Message\RequestMethodInterface;
/**
* Routing class to match request URL's against given routes and map them to a controller action.
$requestMethod = (
isset($_POST['_method'])
&& ($_method = strtoupper($_POST['_method']))
- && in_array($_method, array('PUT', 'DELETE'))
+ && in_array($_method, array(RequestMethodInterface::METHOD_PUT, RequestMethodInterface::METHOD_DELETE), true)
) ? $_method : $_SERVER['REQUEST_METHOD'];
$requestUrl = $_SERVER['REQUEST_URI'];
*
* @return bool|Route
*/
- public function match($requestUrl, $requestMethod = 'GET')
+ public function match($requestUrl, $requestMethod = RequestMethodInterface::METHOD_GET)
{
$currentDir = dirname($_SERVER['SCRIPT_NAME']);
$params = array();
- if (preg_match_all("/:([\w-%]+)/", $routes->getUrl(), $argument_keys)) {
+ if (preg_match_all('/:([\w-%]+)/', $routes->getUrl(), $argument_keys)) {
// grab array with matches
$argument_keys = $argument_keys[1];
$url = $route->getUrl();
// replace route url with given parameters
- if ($params && preg_match_all("/:(\w+)/", $url, $param_keys)) {
+ if ($params && preg_match_all('/:(\w+)/', $url, $param_keys)) {
// grab array with matches
$param_keys = $param_keys[1];
// loop trough parameter names, store matching value in $params array
foreach ($param_keys as $key) {
if (isset($params[$key])) {
- $url = preg_replace("/:(\w+)/", $params[$key], $url, 1);
+ $url = preg_replace('/:(\w+)/', $params[$key], $url, 1);
}
}
}