From a6cc51f7266094b3b8f5a059cc08816764018ea7 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Sep 2015 10:58:44 +0300 Subject: [PATCH 1/2] Update RouteCollection::getPath This version work faster - old code create closure at every calling getPath --- framework/core/src/Http/RouteCollection.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Http/RouteCollection.php b/framework/core/src/Http/RouteCollection.php index 3400e0f46..500ac8d58 100644 --- a/framework/core/src/Http/RouteCollection.php +++ b/framework/core/src/Http/RouteCollection.php @@ -80,16 +80,19 @@ class RouteCollection return $this->dataGenerator->getData(); } - public function getPath($name, $parameters = []) + protected function fixPathPart(&$part, $key, array $parameters) + { + if (is_array($part) && array_key_exists($part[0], $parameters)) { + $part = $parameters[$part[0]]; + } + } + + public function getPath($name, array $parameters = []) { $parts = $this->reverse[$name][0]; - $path = implode('', array_map(function ($part) use ($parameters) { - if (is_array($part)) { - $part = $parameters[$part[0]]; - } - return $part; - }, $parts)); + array_walk($parts, [$this, 'fixPathPart'], $parameters); + $path = implode('', $parts); $path = '/' . ltrim($path, '/'); return $path; From 0a43250426e644cdfbe5e92bcf13a38f10358e14 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 2 Sep 2015 19:22:40 +0300 Subject: [PATCH 2/2] Update RouteCollection.php --- framework/core/src/Http/RouteCollection.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/core/src/Http/RouteCollection.php b/framework/core/src/Http/RouteCollection.php index 500ac8d58..795f72ef8 100644 --- a/framework/core/src/Http/RouteCollection.php +++ b/framework/core/src/Http/RouteCollection.php @@ -90,11 +90,8 @@ class RouteCollection public function getPath($name, array $parameters = []) { $parts = $this->reverse[$name][0]; - array_walk($parts, [$this, 'fixPathPart'], $parameters); - $path = implode('', $parts); - - $path = '/' . ltrim($path, '/'); + $path = '/' . ltrim(implode('', $parts), '/'); return $path; } }