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

Hooks for filtering request()->query and request()->data #17

Closed
warmwaffles opened this issue Nov 28, 2012 · 4 comments
Closed

Hooks for filtering request()->query and request()->data #17

warmwaffles opened this issue Nov 28, 2012 · 4 comments

Comments

@warmwaffles
Copy link

Often I am finding myself having to encapsulate the request()->query in a cleaning function of my own. I would love to have the ability to attach filters to it so I don't have to keep doing something like this:

$clean = Security::clean(Flight::request()->data['someval']);
@mikecao
Copy link
Collaborator

mikecao commented Nov 29, 2012

You can create a filter before the start event like this:

Flight::before('start', function(){
    $query =& Flight::request()->query;
    foreach ($query as $k => $v) {
        $query[$k] = Security::clean($v);
    }
});

@warmwaffles
Copy link
Author

Yea the same would have to go for the data field as well.

EDIT:
To be honest, I would much rather lazy load the clean than to run it on every value at every run.

@mikecao
Copy link
Collaborator

mikecao commented Nov 29, 2012

You can map your own function to do that:

Flight::map('getClean', function($var){
    return Security::clean(Flight::request()->data[$var]);
}

$clean = Flight::getClean('someval');

@warmwaffles
Copy link
Author

I like that solution a lot more.

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

2 participants