/** * 单次请求的初始化 * * @throws BaseException */ public function init() { /** * 设置默认时区 */ if ($this->timezone) { date_default_timezone_set($this->timezone); } /** * 设置地区信息(地域信息) */ if ($this->locale) { setlocale(LC_ALL, $this->locale); } if ($this->charset && function_exists('mb_internal_encoding')) { mb_internal_encoding($this->charset); } /** * 当输入字符的编码是无效的,或者字符代码不存在于输出的字符编码中时,可以为其指定一个替代字符。 * * @link http://www.php.net/manual/function.mb-substitute-character.php */ mb_substitute_character('none'); // 确保输入的数据安全 $_GET = Security::sanitize($_GET); $_POST = Security::sanitize($_POST); $_COOKIE = Security::sanitize($_COOKIE); self::cleanComponents(); }
/** * 检测过滤是否正确 * * @dataProvider providerSanitize * @param mixed $input * @param mixed $output */ public function testSanitize($input, $output) { $this->assertEquals($output, Security::sanitize($input)); }