public function url($handler, array $data = [], array $query_params = [], $is_absolute = false)
{
if ($this->named_routes === null) {
$this->buildNameIndex();
}
if (!isset($this->named_routes[$handler])) {
throw new \RuntimeException('Named route does not exist for name: ' . $handler);
}
$route = $this->named_routes[$handler];
$url = preg_replace_callback('/{([^}]+)}/', function ($match) use($data) {
$segment_name = explode(':', $match[1])[0];
if (!isset($data[$segment_name])) {
throw new \InvalidArgumentException('Missing data for URL segment: ' . $segment_name);
}
return $data[$segment_name];
}, $route);
if ($query_params) {
$url .= '?' . http_build_query($query_params);
}
if ($is_absolute) {
$url = $this->container['app']->getUrl() . $url;
}
return $url;
}