示例#1
0
 protected function saveCache(array $id, array $record, $ttl = null)
 {
     $key = $this->getCacheKey($id);
     $memcached = $this->getCacheService($key);
     $ttl = $ttl ?: $this->getCacheTTL();
     return $memcached->set($key, \Owl\safe_json_encode($record, JSON_UNESCAPED_UNICODE), $ttl);
 }
示例#2
0
文件: Json.php 项目: yeaha/owl-orm
 public function store($value, array $attribute)
 {
     $value = parent::store($value, $attribute);
     if ($this->isNull($value)) {
         return;
     }
     return \Owl\safe_json_encode($value, JSON_UNESCAPED_UNICODE);
 }
示例#3
0
文件: Cookie.php 项目: yeaha/owl-mvc
 protected function encode($data)
 {
     $data = \Owl\safe_json_encode($data);
     // 添加数字签名
     $data = $data . $this->getSign($data);
     if ($this->getConfig('encrypt')) {
         // 加密,加密数据不需要压缩
         $data = $this->encrypt($data);
     } elseif ($this->getConfig('zip')) {
         // 压缩
         // 压缩文本最前面有'_',用于判断是否压缩数据
         // 否则在运行期间切换压缩配置时,错误的数据格式会导致gzcompress()报错
         $data = '_' . gzcompress($data, 9);
     }
     return base64_encode($data);
 }
示例#4
0
 public function testSafeJson()
 {
     try {
         $json = '{a:1';
         \Owl\safe_json_decode($json, true);
         $this->fail('test safe_json_decode() failed');
     } catch (\UnexpectedValueException $ex) {
     }
     try {
         $string = substr('爱', 0, 1);
         \Owl\safe_json_encode($string);
         $this->fail('test safe_json_encode() failed');
     } catch (\UnexpectedValueException $ex) {
     }
 }