Пример #1
0
 /**
  * 初始化项目编码和输入内容编码,如果输入编码和项目编码不一致,自动转换RPG中数据编码
  * @return void
  * @throws InvalidArgumentException 如果不是可支持的编码,抛出异常
  */
 protected function _initEncoding()
 {
     // 验证配置中的项目编码是否合法
     try {
         $encoding = strtoupper(trim(Cfg::getApp('encoding')));
         Ap::setEncoding($encoding);
     } catch (ErrorException $e) {
     }
     if (!in_array(Ap::getEncoding(), $this->_encodings)) {
         throw new InvalidArgumentException('BaseAction is unable to determine the charset of the config.');
     }
     // 从RGP中获取‘ie’的值(input encode),并验证是否合法
     $encoding = Ap::getRequest()->getTrim('ie');
     if ($encoding !== '') {
         $encoding = strtoupper($encoding);
         if (!in_array($encoding, $this->_encodings)) {
             throw new InvalidArgumentException('BaseAction is unable to determine the charset of the request.');
         }
         // 转换输入内容编码
         if (Ap::getEncoding() !== $encoding) {
             $encoder = Encoder::getInstance();
             $_GET = $encoder->convert($_GET, $encoding);
             $_POST = $encoder->convert($_POST, $encoding);
             // $_COOKIE = $encoder->convert($_COOKIE, $encoding);
         }
     }
 }