/** * Get destination file path for the given route / parameters * * @param Route $route * @param array $parameters * * @return string */ protected function getFilePath(Route $route, array $parameters = []) { $filepath = trim($route->getFilePath(), '/'); foreach ($route->getDefaults() as $key => $value) { if (isset($parameters[$key]) && $parameters[$key] == $value) { $filepath = rtrim(preg_replace(sprintf('#{%s}/?#', $key), null, $filepath), '/'); } } foreach ($parameters as $key => $value) { $filepath = str_replace(sprintf('{%s}', $key), (string) $value, $filepath); } return $filepath; }