Update RouteCollection::getPath

This version work faster - old code create closure at every calling getPath
This commit is contained in:
Anton 2015-09-02 10:58:44 +03:00
parent bd47653377
commit f3bc7d1c23

View File

@ -80,16 +80,19 @@ class RouteCollection
return $this->dataGenerator->getData(); 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]; $parts = $this->reverse[$name][0];
$path = implode('', array_map(function ($part) use ($parameters) { array_walk($parts, [$this, 'fixPathPart'], $parameters);
if (is_array($part)) { $path = implode('', $parts);
$part = $parameters[$part[0]];
}
return $part;
}, $parts));
$path = '/' . ltrim($path, '/'); $path = '/' . ltrim($path, '/');
return $path; return $path;