OSDN Git Service

Use \Fig\Http\Message\RequestMethodInterface to reference HTTP verbs
authorJefersson Nathan <admin@phpse.net>
Fri, 23 Dec 2016 16:45:25 +0000 (13:45 -0300)
committerJefersson Nathan <admin@phpse.net>
Fri, 23 Dec 2016 16:45:25 +0000 (13:45 -0300)
src/Route.php
src/Router.php

index 96c09f5..e4b0603 100755 (executable)
@@ -17,6 +17,8 @@
  */
 namespace PHPRouter;
 
+use Fig\Http\Message\RequestMethodInterface;
+
 class Route
 {
     /**
@@ -29,7 +31,12 @@ class Route
      * Accepted HTTP methods for this route.
      * @var string[]
      */
-    private $methods = array('GET', 'POST', 'PUT', 'DELETE');
+    private $methods = array(
+        RequestMethodInterface::METHOD_GET,
+        RequestMethodInterface::METHOD_POST,
+        RequestMethodInterface::METHOD_PUT,
+        RequestMethodInterface::METHOD_DELETE,
+    );
 
     /**
      * Target for this route, can be anything.
index 11d44bf..56e56ff 100755 (executable)
@@ -18,7 +18,7 @@
 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.
@@ -76,7 +76,7 @@ class Router
         $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'];
@@ -99,7 +99,7 @@ class Router
      *
      * @return bool|Route
      */
-    public function match($requestUrl, $requestMethod = 'GET')
+    public function match($requestUrl, $requestMethod = RequestMethodInterface::METHOD_GET)
     {
         foreach ($this->routes->all() as $routes) {
             // compare server request method with route's allowed http methods