public function link($destination, $args = array())
{
if (!is_array($args)) {
$args = func_get_args();
array_shift($args);
}
$link = parent::link($destination, $args);
$lastRequest = $this->getPresenter()->getLastCreatedRequest();
// bad link
if ($lastRequest === NULL) {
return $link;
}
// not a signal
if (substr($destination, -1) !== '!') {
return $link;
}
// signal must lead to this presenter
if ($this->getPresenter()->getName() !== $lastRequest->getPresenterName()) {
return $link;
}
$destination = str_replace(':', '-', $destination);
if (strpos($destination, '-') !== FALSE) {
$pos = strrpos($destination, '-');
$signal = substr($destination, $pos + 1, -1);
$component = substr($destination, 0, $pos);
$component = $this->getComponent($component);
} else {
$signal = substr($destination, 0, -1);
$component = $this;
}
// only components
if (!$component instanceof PresenterComponent) {
return $link;
}
$method = $component->formatSignalMethod($signal);
$reflection = Method::from($component, $method);
// does not have annotation
if (!$reflection->hasAnnotation('secured')) {
return $link;
}
$origParams = $lastRequest->getParameters();
$protectedParams = array();
foreach ($reflection->getParameters() as $param) {
if ($param->isOptional()) {
continue;
}
$protectedParams[$param->name] = $origParams[$component->getParameterId($param->name)];
}
$uniqueId = $this->getUniqueId();
if (empty($uniqueId)) {
$paramName = $component->getParameterId('__sec');
} else {
$paramName = substr($component->getParameterId('__sec'), strlen($uniqueId) + 1);
}
$args[$paramName] = $this->createSecureHash($protectedParams);
return parent::link($destination, $args);
}