Skip to content

Commit

Permalink
MicroPresenter: fixed passing params to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik authored and dg committed Mar 10, 2015
1 parent 6e3ac0c commit 4d40d7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/Application/MicroPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ public function run(Application\Request $request)
$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);

foreach ($reflection->getParameters() as $param) {
if ($param->getClassName()) {
unset($params[$param->getPosition()]);
if ($this->context) {
foreach ($reflection->getParameters() as $param) {
if ($param->getClassName()) {
unset($params[$param->getPosition()]);
}
}
}

if ($this->context) {
$params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context);
$params['presenter'] = $this;
}

$response = call_user_func_array($callback, $params);
Expand Down
7 changes: 4 additions & 3 deletions tests/Application/MicroPresenter.invoke.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ require __DIR__ . '/../bootstrap.php';

class Invokable extends Nette\Object
{
public function __invoke($page, $id)
public function __invoke($page, $id, NetteModule\MicroPresenter $presenter)
{
Notes::add('Callback id ' . $id . ' page ' . $page);
}
}


test(function() {
$presenter = new NetteModule\MicroPresenter;
$presenter = $p = new NetteModule\MicroPresenter;

$presenter->run(new Request('Nette:Micro', 'GET', array(
'callback' => function($id, $page) {
'callback' => function($id, $page, $presenter) use ($p) {
Assert::same($p, $presenter);
Notes::add('Callback id ' . $id . ' page ' . $page);
},
'id' => 1,
Expand Down

0 comments on commit 4d40d7e

Please sign in to comment.