/** * @dataProvider providerTestStringInput */ public function testStringInput($data, $success) { $ob = new Horde_Compress_Fast(array('drivers' => array('Horde_Compress_Fast_Null'))); try { $ob->compress($data); if (!$success) { $this->fail('Expected exception.'); } } catch (Horde_Compress_Fast_Exception $e) { if ($success) { $this->fail('Unexpected exception.'); } } }
/** * Unpack a string. * * @param string $data The packed string. * * @return mixed The unpacked data. * @throws Horde_Pack_Exception */ public function unpack($data) { if (!$data) { return $data; } if (is_string($data)) { $mask = unpack('C*', $data[0]); $mask = reset($mask); $data = substr($data, 1); if ($mask & self::COMPRESS_MASK) { $data = self::$_compress->decompress($data); $mask ^= self::COMPRESS_MASK; } if (isset(self::$_drivers[$mask])) { try { return self::$_drivers[$mask]->unpack($data); } catch (Horde_Pack_Exception $e) { throw $e; } catch (Exception $e) { /* Unknown exceptions are handled with the throw below. */ } } } throw new Horde_Pack_Exception('Could not unpack data'); }
/** * Unpack a string. * * @param string $data The packed string. * * @return mixed The unpacked data. * @throws Horde_Pack_Exception */ public function unpack($data) { if (!$data) { return $data; } if (is_string($data)) { $mask = unpack('C*', $data[0]); $mask = reset($mask); $data = substr($data, 1); if ($mask & self::COMPRESS_MASK) { $data = self::$_compress->decompress($data); $mask ^= self::COMPRESS_MASK; } if (isset(self::$_drivers[$mask])) { return self::$_drivers[$mask]->unpack($data); } } throw new Horde_Pack_Exception('Could not unpack data'); }
/** * Convert data from/to storage format. * * @param mixed|MongoBinData $data The data object. * * @return mixed|MongoBinData The converted data. */ protected function _value($data) { static $compress; if (!isset($compress)) { $compress = new Horde_Compress_Fast(); } return $data instanceof MongoBinData ? @unserialize($compress->decompress($data->bin)) : new MongoBinData($compress->compress(serialize($data)), MongoBinData::BYTE_ARRAY); }
/** * Store an object in the cache. * * @param string $key Object ID used as the caching key. * @param string $data Data to store in the cache. * @param integer $lifetime Object lifetime - i.e. the time before the * data becomes available for garbage * collection, in seconds. If null use the * default Horde GC time. If 0 will not be GC'd. */ public function set($key, $data, $lifetime = null) { if (!empty($this->_params['compress'])) { $compress = new Horde_Compress_Fast(); $data = $compress->compress($data); } $lifetime = is_null($lifetime) ? $this->_params['lifetime'] : $lifetime; $this->_storage->set($key, $data, $lifetime); }
/** */ public function set($mailbox, $data, $uidvalid) { if ($uid = $this->_getUid($mailbox)) { $res = $this->get($mailbox, array_keys($data), array(), $uidvalid); } else { $res = array(); $uid = $this->_createUid($mailbox); } $compress = new Horde_Compress_Fast(); foreach ($data as $key => $val) { if (isset($res[$key])) { try { /* Update */ $this->_db->update(sprintf('UPDATE %s SET data = ? WHERE messageid = ? AND msguid = ?', self::MSG_TABLE), array(new Horde_Db_Value_Binary($compress->compress(serialize(array_merge($res[$key], $val)))), $uid, strval($key))); } catch (Horde_Db_Exception $e) { } } else { /* Insert */ try { $this->_db->insert(sprintf('INSERT INTO %s (data, msguid, messageid) VALUES (?, ?, ?)', self::MSG_TABLE), array(new Horde_Db_Value_Binary($compress->compress(serialize($val))), strval($key), $uid)); } catch (Horde_Db_Exception $e) { } } } /* Update modified time. */ try { $this->_db->update(sprintf('UPDATE %s SET modified = ? WHERE messageid = ?', self::BASE_TABLE), array(time(), $uid)); } catch (Horde_Db_Exception $e) { } /* Update uidvalidity. */ $this->setMetaData($mailbox, array('uidvalid' => $uidvalid)); }