Skip to content

Commit 6d12b3c

Browse files
committed
Presenter: isLinkCurrent is compatible with PHP 7 typehints [Closes #126]
1 parent 0c5f21d commit 6d12b3c

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

src/Application/UI/Presenter.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ protected function createRequest($component, $destination, array $args, $mode)
874874
throw new InvalidLinkException("Unknown signal '$signal', missing handler {$reflection->getName()}::$method()");
875875
}
876876
// convert indexed parameters to named
877-
self::argsToParams(get_class($component), $method, $args);
877+
self::argsToParams(get_class($component), $method, $args, [], $mode === 'test');
878878
}
879879

880880
// counterpart of IStatePersistent
@@ -915,12 +915,8 @@ protected function createRequest($component, $destination, array $args, $mode)
915915
if (array_key_exists(0, $args)) {
916916
throw new InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method.");
917917
}
918-
919-
} elseif ($destination === 'this') {
920-
self::argsToParams($presenterClass, $method, $args, $this->params);
921-
922918
} else {
923-
self::argsToParams($presenterClass, $method, $args);
919+
self::argsToParams($presenterClass, $method, $args, $destination === 'this' ? $this->params : [], $mode === 'test');
924920
}
925921

926922
// counterpart of IStatePersistent
@@ -1004,11 +1000,12 @@ protected function createRequest($component, $destination, array $args, $mode)
10041000
* @param string method name
10051001
* @param array arguments
10061002
* @param array supplemental arguments
1003+
* @param bool prevents 'Missing parameter' exception
10071004
* @return void
10081005
* @throws InvalidLinkException
10091006
* @internal
10101007
*/
1011-
public static function argsToParams($class, $method, & $args, $supplemental = [])
1008+
public static function argsToParams($class, $method, & $args, $supplemental = [], $ignoreMissing = FALSE)
10121009
{
10131010
$i = 0;
10141011
$rm = new \ReflectionMethod($class, $method);
@@ -1029,7 +1026,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
10291026
}
10301027

10311028
if (!isset($args[$name])) {
1032-
if ($param->isDefaultValueAvailable() || $type === 'NULL' || $type === 'array') {
1029+
if ($param->isDefaultValueAvailable() || $type === 'NULL' || $type === 'array' || $ignoreMissing) {
10331030
continue;
10341031
}
10351032
throw new InvalidLinkException("Missing parameter \$$name required by $class::{$rm->getName()}()");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Application\UI\PresenterComponent::isLinkCurrent()
5+
* @phpVersion 7
6+
*/
7+
8+
use Nette\Application;
9+
10+
require __DIR__ . '/../bootstrap.php';
11+
require __DIR__ . '/MockPresenterFactory.php';
12+
13+
class TestPresenter extends Application\UI\Presenter
14+
{
15+
16+
public function actionDefault(int $int, bool $bool)
17+
{
18+
}
19+
20+
public function handleSignal()
21+
{
22+
}
23+
24+
public function handleOtherSignal()
25+
{
26+
}
27+
28+
}
29+
30+
class TestControl extends Application\UI\Control
31+
{
32+
33+
public function handleClick(int $x)
34+
{
35+
}
36+
37+
public function handleOtherSignal()
38+
{
39+
}
40+
41+
}
42+
43+
require __DIR__ . '/PresenterComponent.isLinkCurrent().asserts.php';

0 commit comments

Comments
 (0)