]> git.andy128k.dev Git - ipf.git/commitdiff
remove deprecated create_function
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jan 2018 15:24:55 +0000 (16:24 +0100)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jan 2018 15:24:55 +0000 (16:24 +0100)
ipf/router.php
t/RouterTest.php [new file with mode: 0644]

index 05de26248502a339f8609dcf36877f2e1c4f8dd1..bceeb36391d175be8076d0b215ccb9d15bcc5f75 100644 (file)
@@ -108,11 +108,10 @@ class IPF_Router_RegexMatch
                 }
                 next($params);
             }
-            $func = create_function('$matches', 
-                                    'static $p = '.var_export($params, true).'; '.
-                                    '$a = current($p); '.
-                                    'next($p); '.
-                                    'return $a;');
+            $params_index = 0;
+            $func = function($matches) use($params, &$params_index) {
+                return $params[$params_index++];
+            };
             $url = preg_replace_callback($groups, $func, $url_regex);
         }
         $url = substr(substr($url, 2), 0, -2);
diff --git a/t/RouterTest.php b/t/RouterTest.php
new file mode 100644 (file)
index 0000000..56b1c65
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+class Router_Test extends PHPUnit_Framework_TestCase
+{
+    public function testReverseWithoutParams()
+    {
+        $route = new IPF_Router_RegexMatch('#^/admin/login/$#i');
+        $this->assertEquals($route->reverse([]), "/admin/login/");
+    }
+
+    public function testReverseWithParams()
+    {
+        $route = new IPF_Router_RegexMatch('#^/admin/([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/delete/$#i');
+        $this->assertEquals($route->reverse(['auth', 'user', 123]), "/admin/auth/user/123/delete/");
+    }
+}