pack() public method

Pack a string.
public pack ( mixed $data, array $opts = [] ) : string
$data mixed The data to pack.
$opts array Additional options:
  - compress: (mixed) If false, don't use compression. If true, uses
              default compress length (DEFAULT). If 0, always compress.
              All other integer values: compress only if data is
              greater than this string length.
  - drivers: (array) Only use these drivers to pack. By default, driver
             to use is auto-determined.
  - phpob: (boolean) If true, the data contains PHP serializable
           objects (i.e. objects that have a PHP-specific serialized
           representation). If false, the data does not contain any of
           these objects. If not present, will auto-determine
           existence of these objects.
return string The packed string.
Esempio n. 1
0
 /**
  * Updates the cache.
  */
 public function save()
 {
     foreach ($this->_update as $mbox => $val) {
         try {
             if (!empty($val['u'])) {
                 $ptr =& $this->_data[$mbox];
                 foreach ($this->_getMsgCids($mbox, array_keys($val['u'])) as $k2 => $v2) {
                     try {
                         $this->_hash->set($v2, $this->_pack->pack($ptr[$k2]), array('expire' => $this->_params['lifetime']));
                     } catch (Horde_Pack_Exception $e) {
                         $this->deleteMsgs($mbox, array($v2));
                         $val['d'][] = $v2;
                     }
                 }
             }
             if (!empty($val['d'])) {
                 $this->_hash->delete(array_values($this->_getMsgCids($mbox, $val['d'])));
             }
             if (!empty($val['m'])) {
                 try {
                     $this->_hash->set($this->_getCid($mbox), $this->_pack->pack($this->_mbox[$mbox]), array('expire' => $this->_params['lifetime']));
                 } catch (Horde_Pack_Exception $e) {
                 }
             }
         } catch (Horde_Exception $e) {
         }
     }
     $this->_update = array();
 }
Esempio n. 2
0
 /**
  * @dataProvider buggyDriverBackendsProvider
  */
 public function testBuggyDriverBackends($data)
 {
     $pack = new Horde_Pack();
     $p = $pack->pack($data, array('drivers' => array('Horde_Pack_Driver_Json', 'Horde_Pack_Driver_Serialize')));
     $this->assertEquals($data, $pack->unpack($p));
 }