Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Allow multiple arguments in dynamic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola committed Oct 8, 2016
1 parent f333845 commit ff6ff04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/MagicMethods.php
Expand Up @@ -25,9 +25,9 @@ public function __call($method, $arguments)
$inner_method = "get" . ucfirst($method);
if (method_exists($this, $inner_method)) {
$value = call_user_func([$this, $inner_method]);
/* If value is callable run it. */
/* If value is anonymous function run it. */
if ($value instanceof \Closure) {
return call_user_func($value, $arguments[0]);
return call_user_func_array($value, $arguments);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/MagicMethodsTest.php
Expand Up @@ -76,4 +76,18 @@ public function testShouldGetAndSetDynamicFunction()
};
$this->assertEquals($unicorn->dynamic("beer"), "No beer!");
}

public function testShouldGetAndSetDynamicFunctionWithManyParameters()
{
$unicorn = new Unicorn();
$unicorn->dynamic(function ($foo, $bar) {
return "Got {$foo} and {$bar}!";
});
$this->assertEquals($unicorn->dynamic("milk", "honey"), "Got milk and honey!");

$unicorn->dynamic = function ($foo, $bar) {
return "No {$foo} or {$bar}!";
};
$this->assertEquals($unicorn->dynamic("beer", "vodka"), "No beer or vodka!");
}
}

0 comments on commit ff6ff04

Please sign in to comment.