From baf0c7f2bf0944c7f1927e9c5bb078353a23f217 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 27 Jan 2018 16:24:55 +0100 Subject: [PATCH] remove deprecated create_function --- ipf/router.php | 9 ++++----- t/RouterTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 t/RouterTest.php diff --git a/ipf/router.php b/ipf/router.php index 05de262..bceeb36 100644 --- a/ipf/router.php +++ b/ipf/router.php @@ -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 index 0000000..56b1c65 --- /dev/null +++ b/t/RouterTest.php @@ -0,0 +1,16 @@ +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/"); + } +} -- 2.49.0