Skip to content

Commit

Permalink
Merge branch 'fix/magic-serialize-unserialize-horde' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/ChristophWurst/Imap_Client into ChristophWurst-fix/magic-serialize-unserialize-horde
  • Loading branch information
mrubinsk committed Oct 22, 2022
2 parents e1efeab + 603bb15 commit ba52d0a
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Horde/Imap/Client/Base.php
Expand Up @@ -388,6 +388,30 @@ public function unserialize($data)
$this->_initOb();
}

/**
* @return array
*/
public function __serialize()
{
return array(
'i' => $this->_init,
'p' => $this->_params,
'v' => self::VERSION
);
}

public function __unserialize(array $data)
{
if (empty($data['v']) || $data['v'] != self::VERSION) {
throw new Exception('Cache version change');
}

$this->_init = $data['i'];
$this->_params = $data['p'];

$this->_initOb();
}

/**
*/
public function __get($name)
Expand Down
13 changes: 13 additions & 0 deletions lib/Horde/Imap/Client/Cache/Backend.php
Expand Up @@ -162,4 +162,17 @@ public function unserialize($data)
$this->_initOb();
}

/**
* @return array
*/
public function __serialize()
{
return $this->_params;
}

public function __unserialize(array $data)
{
$this->_params = $data;
}

}
9 changes: 9 additions & 0 deletions lib/Horde/Imap/Client/Cache/Backend/Cache.php
Expand Up @@ -503,4 +503,13 @@ public function serialize()
return parent::serialize();
}

/**
* @return array
*/
public function __serialize()
{
$this->save();
return parent::__serialize();
}

}
15 changes: 15 additions & 0 deletions lib/Horde/Imap/Client/Data/Acl.php
Expand Up @@ -166,4 +166,19 @@ public function unserialize($data)
$this->_rights = json_decode($data);
}

/**
* @return array
*/
public function __serialize()
{
return array(
'rights' => $this->_rights
);
}

public function __unserialize(array $data)
{
$this->_rights = $data['rights'];
}

}
17 changes: 17 additions & 0 deletions lib/Horde/Imap/Client/Data/AclRights.php
Expand Up @@ -214,4 +214,21 @@ public function unserialize($data)
list($this->_required, $this->_optional) = json_decode($data);
}

/**
* @return array
*/
public function __serialize()
{
return array(
'required' => $this->_required,
'optional' => $this->_optional,
);
}

public function __unserialize(array $data)
{
$this->_required = $data['required'];
$this->_optional = $data['optional'];
}

}
13 changes: 13 additions & 0 deletions lib/Horde/Imap/Client/Data/Capability.php
Expand Up @@ -214,4 +214,17 @@ public function unserialize($data)
$this->_data = json_decode($data, true);
}

/**
* @return array
*/
public function __serialize()
{
return $this->_data;
}

public function __unserialize(array $data)
{
$this->_data = $data;
}

}
20 changes: 20 additions & 0 deletions lib/Horde/Imap/Client/Data/Envelope.php
Expand Up @@ -223,4 +223,24 @@ public function unserialize($data)
$this->_data = $data['d'];
}

/**
* @return array
*/
public function __serialize()
{
return array(
'd' => $this->_data,
'v' => self::VERSION,
);
}

public function __unserialize(array $data)
{
if (empty($data['v']) || $data['v'] != self::VERSION) {
throw new Exception('Cache version change');
}

$this->_data = $data['d'];
}

}
13 changes: 13 additions & 0 deletions lib/Horde/Imap/Client/Data/Namespace.php
Expand Up @@ -140,4 +140,17 @@ public function unserialize($data)
$this->_data = json_decode($data, true);
}

/**
* @return array
*/
public function __serialize()
{
return $this->_data;
}

public function __unserialize(array $data)
{
$this->_data = $data;
}

}
13 changes: 13 additions & 0 deletions lib/Horde/Imap/Client/Data/SearchCharset.php
Expand Up @@ -178,4 +178,17 @@ public function unserialize($data)
$this->_charsets = json_decode($data, true);
}

/**
* @return array
*/
public function __serialize()
{
return $this->_charsets;
}

public function __unserialize(array $data)
{
$this->_charsets = $data;
}

}
12 changes: 12 additions & 0 deletions lib/Horde/Imap/Client/Data/SearchCharset/Utf8.php
Expand Up @@ -63,4 +63,16 @@ public function unserialize($data)
{
}

/**
* @return array
*/
public function __serialize()
{
return array();
}

public function __unserialize(array $data)
{
}

}
17 changes: 17 additions & 0 deletions lib/Horde/Imap/Client/Data/Thread.php
Expand Up @@ -196,6 +196,23 @@ public function unserialize($data)
list($this->_thread, $this->_type) = json_decode($data, true);
}

/**
* @return array
*/
public function __serialize()
{
return array(
'thread' => $this->_thread,
'type' => $this->_type,
);
}

public function __unserialize(array $data)
{
$this->_thread = $data['thread'];
$this->_type = $data['type'];
}

/* Protected methods. */

/**
Expand Down
21 changes: 21 additions & 0 deletions lib/Horde/Imap/Client/Ids.php
Expand Up @@ -497,4 +497,25 @@ public function unserialize($data)
}
}

/**
* @return array
*/
public function __serialize()
{
return array(
'd' => $this->duplicates,
's' => $this->_sequence,
'is' => $this->_sorted,
'ids' => $this->_ids,
);
}

public function __unserialize(array $data)
{
$this->duplicates = $data['d'];
$this->_sequence = $data['s'];
$this->_sorted = $data['is'];
$this->_ids = $data['ids'];
}

}
24 changes: 24 additions & 0 deletions lib/Horde/Imap/Client/Ids/Map.php
Expand Up @@ -241,4 +241,28 @@ public function unserialize($data)
$this->_sorted = true;
}

/**
* @return array
*/
public function __serialize()
{
/* Sort before storing; provides more compressible representation. */
$this->sort();

return array(
'keys' => (string)new Horde_Imap_Client_Ids(array_keys($this->_ids)),
'values' => (string)new Horde_Imap_Client_Ids(array_values($this->_ids)),
);
}

public function __unserialize(array $data)
{
$keys = new Horde_Imap_Client_Ids($data['keys']);
$vals = new Horde_Imap_Client_Ids($data['values']);
$this->_ids = array_combine($keys->ids, $vals->ids);

/* Guaranteed to be sorted if unserializing. */
$this->_sorted = true;
}

}
17 changes: 17 additions & 0 deletions lib/Horde/Imap/Client/Mailbox.php
Expand Up @@ -144,4 +144,21 @@ public function unserialize($data)
list($this->_utf7imap, $this->_utf8) = json_decode($data, true);
}

/**
* @return array
*/
public function __serialize()
{
return array(
'utf7imap' => $this->_utf7imap,
'utf8' => $this->_utf8,
);
}

public function __unserialize(array $data)
{
$this->_utf7imap = $data['utf7imap'];
$this->_utf8 = $data['utf8'];
}

}
22 changes: 22 additions & 0 deletions lib/Horde/Imap/Client/Search/Query.php
Expand Up @@ -901,4 +901,26 @@ public function unserialize($data)
}
}

/**
* @return array
*/
public function __serialize()
{
return array(
'version' => self::VERSION,
'search' => $this->_search,
'charset' => $this->_charset,
);
}

public function __unserialize(array $data)
{
if (empty($data['version']) || $data['version'] != self::VERSION) {
throw new Exception('Cache version change');
}

$this->_search = $data['search'];
$this->_charset = $data['charset'];
}

}
15 changes: 15 additions & 0 deletions lib/Horde/Imap/Client/Url.php
Expand Up @@ -299,4 +299,19 @@ public function unserialize($data)
$this->_parse($data);
}

/**
* @return array
*/
public function __serialize()
{
return array(
'value' => (string)$this,
);
}

public function __unserialize(array $data)
{
$this->_parse($data['value']);
}

}
15 changes: 15 additions & 0 deletions lib/Horde/Imap/Client/Url/Base.php
Expand Up @@ -170,4 +170,19 @@ public function unserialize($data)
$this->_parse($data);
}

/**
* @return array
*/
public function __serialize()
{
return array(
'value' => (string)$this,
);
}

public function __unserialize(array $data)
{
$this->_parse($data['value']);
}

}

0 comments on commit ba52d0a

Please sign in to comment.