我想将GUMP https://github.com/Wixel/GUMP合并到我的Slim rest框架中。
我希望在继续处理之前拦截GET或POST请求,然后再使用GUMP验证它。任何人都可以提供一个简短的代码片段如何做到这一点,因为我无法弄清楚使用中间件(服务器是在PHP 5.2)。
感谢
答案 0 :(得分:4)
为什么不使用这样的东西:
$rules = array(
'username' => 'required|alpha_numeric|max_len,100|min_len,6',
'password' => 'required|max_len,100|min_len,6',
'email' => 'required|valid_email',
'gender' => 'required|exact_len,1',
'credit_card' => 'trim|valid_cc',
);
$filters = array(
'username' => 'trim|sanitize_string',
'password' => 'trim|base64',
'email' => 'trim|sanitize_email',
'gender' => 'trim',
'bio' => 'noise_words'
);
//now get $post data and validate
$post = $app->request()->post(); // $app - Slim main app instance
$validated = $gump->validate( $gump->filter($post, $filters), $rules );