Navigation Menu

Skip to content

Commit

Permalink
isLinkCurrent decoupled from link generator (closes #124)
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 28, 2016
1 parent 107fe36 commit df2f934
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Application/UI/PresenterComponent.php
Expand Up @@ -325,7 +325,43 @@ public function isLinkCurrent($destination = NULL, $args = [])
{
if ($destination !== NULL) {
$args = func_num_args() < 3 && is_array($args) ? $args : array_slice(func_get_args(), 1);
$this->getPresenter()->createRequest($this, $destination, $args, 'test');
$presenter = $this->getPresenter();
$parsedLinkDestination = $presenter->parseLinkDestination($this, $destination);
if ($parsedLinkDestination['presenterClass'] !== get_class($presenter)) {
return FALSE;
}

if ($parsedLinkDestination['action'] !== '*' && $parsedLinkDestination['action'] !== $presenter->getAction()) {
return FALSE;
}

if ($parsedLinkDestination['callee'] !== $presenter) {
$prefix = $parsedLinkDestination['callee']->getUniqueId() . self::NAME_SEPARATOR;
foreach ($args as $key => $val) {
unset($args[$key]);
$args[$prefix . $key] = $val;
}
}

$currentParameters = $presenter->getGlobalState($parsedLinkDestination['destination'] === 'this' ? NULL : $parsedLinkDestination['presenterClass']) + $presenter->getParameters();
foreach ($args as $name => $value) {
if (array_key_exists($name, $currentParameters)) {
if ($currentParameters[$name] != $value) {
return FALSE;
}
} else {
return FALSE;
}
}

if ($parsedLinkDestination['signal'] !== NULL) {
list($signalReceiver, $signal) = $presenter->getSignal();

return $parsedLinkDestination['callee']->getUniqueId() === $signalReceiver
&& $parsedLinkDestination['signal'] === $signal;
}

return TRUE;
}
return $this->getPresenter()->getLastCreatedRequestFlag('current');
}
Expand Down
31 changes: 31 additions & 0 deletions tests/UI/PresenterComponent.isLinkCurrent().php7.phpt
@@ -0,0 +1,31 @@
<?php

/**
* Test: Nette\Application\UI\PresenterComponent::isLinkCurrent()
* @phpVersion 7
*/

use Nette\Application;
use Nette\Http;

require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/MockPresenterFactory.php';

class TestPresenter extends Application\UI\Presenter
{

public function actionDefault(int $int, bool $bool)
{
}

public function handleSignal()
{
}

public function handleOtherSignal()
{
}

}

require __DIR__ . '/PresenterComponent.isLinkCurrent().asserts.php';

0 comments on commit df2f934

Please sign in to comment.