klein/klein.php

Passing arguments where registering Lazy services

Opened this issue · 2 comments

Hi,

It's now impossible to do something like

    $app->register('myfunction', function($arg1, $arg2) {
        var_dump($arg1); // return NULL
    })

$args are not passed to function

I suggest to change App.php, at line 95 from:
$instance = $closure();
to
$instance = call_user_func_array($closure,func_get_args());

Giving the possibility to use $app->myfunction("argument1","argument2");

Thks by advance!

ddv88 commented

You should use closure.

$app->register('myfunction', function($result) use ($arg1, $arg2) {
        var_dump($arg1);
    })

$result will be returning value of your function.

Doesn't work...
My goal is to pass $arg1 and $arg2 dynamically when I will call this service:

$klein->respond('GET', '/', function ($request, $response, $service, $app) {
    return $app->myfunction('foo',['foo','bar']);
});

thanks for advises,