Skip to content

Commit

Permalink
Presenter: isLinkCurrent is compatible with PHP 7 typehints [Closes #126
Browse files Browse the repository at this point in the history
]
  • Loading branch information
dg committed Apr 6, 2016
1 parent a6daabb commit c292b85
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ protected function createRequest($component, $destination, array $args, $mode)
throw new InvalidLinkException("Unknown signal '$signal', missing handler {$reflection->getName()}::$method()");
}
// convert indexed parameters to named
self::argsToParams(get_class($component), $method, $args);
self::argsToParams(get_class($component), $method, $args, array(), $mode === 'test');
}

// counterpart of IStatePersistent
Expand Down Expand Up @@ -914,12 +914,8 @@ protected function createRequest($component, $destination, array $args, $mode)
if (array_key_exists(0, $args)) {
throw new InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method.");
}

} elseif ($destination === 'this') {
self::argsToParams($presenterClass, $method, $args, $this->params);

} else {
self::argsToParams($presenterClass, $method, $args);
self::argsToParams($presenterClass, $method, $args, $destination === 'this' ? $this->params : array(), $mode === 'test');
}

// counterpart of IStatePersistent
Expand Down Expand Up @@ -1003,11 +999,12 @@ protected function createRequest($component, $destination, array $args, $mode)
* @param string method name
* @param array arguments
* @param array supplemental arguments
* @param bool prevents 'Missing parameter' exception
* @return void
* @throws InvalidLinkException
* @internal
*/
public static function argsToParams($class, $method, & $args, $supplemental = array())
public static function argsToParams($class, $method, & $args, $supplemental = array(), $ignoreMissing = FALSE)
{
$i = 0;
$rm = new \ReflectionMethod($class, $method);
Expand All @@ -1028,7 +1025,7 @@ public static function argsToParams($class, $method, & $args, $supplemental = ar
}

if (!isset($args[$name])) {
if ($param->isDefaultValueAvailable() || $type === 'NULL' || $type === 'array' || $isClass) {
if ($param->isDefaultValueAvailable() || $type === 'NULL' || $type === 'array' || $isClass || $ignoreMissing) {
continue;
}
throw new InvalidLinkException("Missing parameter \$$name required by $class::{$rm->getName()}()");
Expand Down
43 changes: 43 additions & 0 deletions tests/UI/PresenterComponent.isLinkCurrent().php7.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

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

use Nette\Application;

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()
{
}

}

class TestControl extends Application\UI\Control
{

public function handleClick(int $x)
{
}

public function handleOtherSignal()
{
}

}

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

0 comments on commit c292b85

Please sign in to comment.