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); }
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); }
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); }
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) { } }