Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function Variables #258

Open
karimkawambwa opened this issue Nov 8, 2014 · 4 comments
Open

Function Variables #258

karimkawambwa opened this issue Nov 8, 2014 · 4 comments
Assignees

Comments

@karimkawambwa
Copy link

Just for helping coding style, can the function variables be returned in and single object. Eg.

$klein->respond('GET', '/login',
function (Request $request, Response $response, ServiceProvider $service, App $app) ...

is really long, if i only just want to get $app. So can this be made better by perhaps having them all in one object parameter e.g.

$klein->respond('GET', '/login',
function ($object) ... {
$object->app ...
$object->request ... 
$object->response ...
$object->service ...

or

$klein->respond('GET', '/login',
function ( /*Parameters from request passed here*/ ) ... use($object) {
$object->app ...
$object->request ... 
$object->response ...
$object->service ...

or which ever way is better.

@Rican7 Rican7 self-assigned this Nov 9, 2014
@Rican7
Copy link
Member

Rican7 commented Nov 9, 2014

Yea, this is something I have planned for a later version. Unfortunately, it would break backwards compatibility pretty heavily, as all route callbacks would have to have their signatures changed, so its going to have to wait until the next major version.

@nbish11
Copy link

nbish11 commented Nov 25, 2014

@Rican7,

I was just wandering if a simple if/else could be used.

if (true === $this->passKleinToCallback) {
    $returned = call_user_func(
        $route->getCallback(),
        $this,
        $matched,
        $methods_matched
    );
} else {
    // Handle the callback
    $returned = call_user_func(
        $route->getCallback(), // Instead of relying on the slower "invoke" magic
        $this->request,
        $this->response,
        $this->service,
        $this->app,
        $this, // Pass the Klein instance
        $matched,
        $methods_matched
    );
}

It's not pretty, but it works. If you do want do this, let me know and I'll create a pull request.

@Rican7
Copy link
Member

Rican7 commented Nov 27, 2014

I'd rather not introduce more configurable branching for now. Klein already has a lot of branching based on configurations and injectables. I might introduce an interesting way to do this in a refactor that I'm current working on. We'll see.

@nbish11
Copy link

nbish11 commented Nov 27, 2014

@Rican7 Fair enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants