public function generate($type, array $values = array())
{
if (!isset($this->map[$type])) {
throw new Exceptions\InvalidArgumentException("No URL for type '{$type}' available.");
}
$url = $this->map[$type];
preg_match_all('(' . self::STANDARD_VARIABLE_REGEX . '|' . self::SLASHES_VARIABLE_REGEX . ')', $url, $matches, PREG_SET_ORDER);
foreach ($matches as $matchSet) {
$variableName = empty($matchSet[1]) ? $matchSet[2] : $matchSet[1];
if (!isset($values[$variableName])) {
throw new Exceptions\InvalidArgumentException("No value provided for '{$variableName}'.");
}
$url = str_replace($matchSet[0], $values[$variableName], $url);
unset($values[$variableName]);
}
if (count($values)) {
throw new Exceptions\InvalidArgumentException("Unused values in values array: '" . implode("', '", array_keys($values)) . "'.");
}
return $url;
}