Merge pull request #413 from WinterSilence/patch-2

Update RouteCollection::getPath
This commit is contained in:
Franz Liedke 2015-09-04 12:03:51 +02:00
commit 211d2d25cd

View File

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