protected function substituteAttributesInRoute($attributes, $route) { foreach ($attributes as $key => $value) { $route = str_replace("{" . $key . "}", $value, $route); $route = str_replace("{" . $key . "?}", $value, $route); } // delete empty optional arguments that are not in the $attributes array $route = preg_replace('/\\/{[^)]+\\?}/', '', $route); return $route; }