lithium\net\http\Route::_write()
Writes a set of URL options to this route's template string.
Parameters
-
array
$options
The options to write to this route, with defaults pre-merged.
-
array
$defaults
The default template options for this route (contains hard-coded default values).
Returns
stringReturns the route template string with option values inserted.
Source
protected function _write($options, $defaults) {
$template = $this->_template;
$trimmed = true;
$options += array('args' => '');
foreach (array_reverse($this->_keys, true) as $key) {
$value =& $options[$key];
$pattern = isset($this->_subPatterns[$key]) ? ":{$this->_subPatterns[$key]}" : '';
$rpl = "{:{$key}{$pattern}}";
$len = strlen($rpl) * -1;
if ($trimmed && isset($defaults[$key]) && $value == $defaults[$key]) {
if (substr($template, $len) == $rpl) {
$template = rtrim(substr($template, 0, $len), '/');
continue;
}
}
if ($value === null) {
$template = str_replace("/{$rpl}", '', $template);
continue;
}
if ($key !== 'args') {
$trimmed = false;
}
$template = str_replace($rpl, $value, $template);
}
return $template ?: '/';
}