Implement output filter into Laravel3

タグ: Laravel3  

Sometime we want to sanitize all output. For instance, you use js editor to permit input HTML tags. (Also Javascript.) It will spend more resource, but you must do it if needed.

Yes, it is also easy to do in Laravel.

For example, try just string replacement. The string 'Laravel' to 'FuelPHP'.

Route::filter('after',
    function($response) {
        if ( in_array($response->status(), array('200'))) {
        $response->content = str_replace('Laravel', 'FuelPHP', $response->content);
        }
    });

It just change content of Response class instance. It is just a string.

Sometime this idea is useful for you.