diff --git a/lib/Compose/Attachment.php b/lib/Compose/Attachment.php index dbd013285..25d8e8ca1 100644 --- a/lib/Compose/Attachment.php +++ b/lib/Compose/Attachment.php @@ -187,6 +187,11 @@ public function viewUrl() /** */ public function serialize() + { + return array_shift($this->__serialize()); + } + + public function __serialize(): array { /* Don't store Mime_Part data. Can't use clone here ATM, since there * appears to be a PHP bug. Since this is an object specific to IMP @@ -196,7 +201,9 @@ public function serialize() $this->_part->clearContents(); $this->_isBuilt = false; - return $GLOBALS['injector']->getInstance('Horde_Pack')->pack( + return + [ + $GLOBALS['injector']->getInstance('Horde_Pack')->pack( array( $this->_composeCache, $this->id, @@ -207,13 +214,18 @@ public function serialize() ), array( 'compression' => false, 'phpob' => true - ) - ); + )) + ]; } /** */ public function unserialize($data) + { + $this->__unserialize([$data]); + } + + public function __unserialize(array $data): void { list( $this->_composeCache, @@ -222,7 +234,6 @@ public function unserialize($data) $this->_part, $this->related, $this->_uuid - ) = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack($data); + ) = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack(array_shift($data)); } - } diff --git a/lib/Flag/Base.php b/lib/Flag/Base.php index b49ed4c0d..c88494f3f 100644 --- a/lib/Flag/Base.php +++ b/lib/Flag/Base.php @@ -203,7 +203,12 @@ public function serialize() { return $this->_bgcolor; } - + public function __serialize(): array + { + return [ + $this->_bgcolor + ]; + } /** */ public function unserialize($data) @@ -211,4 +216,8 @@ public function unserialize($data) $this->_bgcolor = $data; } + public function __unserialize(array $data): void + { + $this->_bgcolor = $data[0]; + } } diff --git a/lib/Flag/User.php b/lib/Flag/User.php index b983430ec..0b61665a4 100644 --- a/lib/Flag/User.php +++ b/lib/Flag/User.php @@ -112,22 +112,33 @@ protected function _getLabel() */ public function serialize() { - return json_encode(array( - parent::serialize(), - $this->_label, - $this->_imapflag - )); + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + json_encode(array( + parent::serialize(), + $this->_label, + $this->_imapflag + )) + ]; } /** */ public function unserialize($data) { - $data = json_decode($data, true); + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $data = json_decode($data[0], true); parent::unserialize($data[0]); $this->_label = $data[1]; $this->_imapflag = $data[2]; - } + } } diff --git a/lib/Ftree/Account.php b/lib/Ftree/Account.php index f687c6cf7..399a29cc0 100644 --- a/lib/Ftree/Account.php +++ b/lib/Ftree/Account.php @@ -84,12 +84,21 @@ public function serialize() { return $this->_id; } - + public function __serialize(): array + { + return + [ + $this->_id + ]; + } /** */ public function unserialize($data) { $this->_id = $data; } - + public function __unserialize(array $data): void + { + $this->_id = $data[0]; + } } diff --git a/lib/Ftree/Eltdiff.php b/lib/Ftree/Eltdiff.php index 66f26141b..9340e1a6f 100644 --- a/lib/Ftree/Eltdiff.php +++ b/lib/Ftree/Eltdiff.php @@ -193,26 +193,37 @@ public function clear() */ public function serialize() { - return $GLOBALS['injector']->getInstance('Horde_Pack')->pack( - array( - $this->track, - $this->_changes - ), - array( - 'compression' => false, - 'phpob' => false - ) - ); + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + $GLOBALS['injector']->getInstance('Horde_Pack')->pack( + array( + $this->track, + $this->_changes + ), + array( + 'compression' => false, + 'phpob' => false + ) + ) + ]; } /** */ public function unserialize($data) + { + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void { list( $this->track, $this->_changes - ) = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack($data); + ) = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack(array_shift($data)); } } diff --git a/lib/Imap.php b/lib/Imap.php index 5adca73c2..97594ceb6 100644 --- a/lib/Imap.php +++ b/lib/Imap.php @@ -943,28 +943,40 @@ public static function loadServerConfig($server = null) */ public function serialize() { - return $GLOBALS['injector']->getInstance('Horde_Pack')->pack( - array( - $this->_ob, - $this->_id, - $this->_config - ), - array( - 'compression' => false, - 'phpob' => true + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + $GLOBALS['injector']->getInstance('Horde_Pack')->pack( + array( + $this->_ob, + $this->_id, + $this->_config + ), + array( + 'compression' => false, + 'phpob' => true + ) ) - ); + ]; } - /** + * @throws Horde_Pack_Exception */ public function unserialize($data) + { + $this->__unserialize([$data]); + } + + public function __unserialize(array $data): void { list( $this->_ob, $this->_id, $this->_config - ) = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack($data); + ) = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack(array_shift($data)); + } - } diff --git a/lib/Imap/Cache/Wrapper.php b/lib/Imap/Cache/Wrapper.php index ee00148c3..1879e024c 100644 --- a/lib/Imap/Cache/Wrapper.php +++ b/lib/Imap/Cache/Wrapper.php @@ -125,14 +125,24 @@ public function __call($name, $arguments) */ public function serialize() { - return json_encode($this->_params); + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + json_encode($this->_params) + ]; } /** */ public function unserialize($data) { - $this->_initOb(json_decode($data, true)); + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $this->_initOb(json_decode($data[0], true)); } - } diff --git a/lib/Imap/Config.php b/lib/Imap/Config.php index 88e4938b4..151aa229e 100644 --- a/lib/Imap/Config.php +++ b/lib/Imap/Config.php @@ -297,7 +297,7 @@ public function __get($name) case 'maildomain': /* Sanity checking - this should be null, not empty string. */ - if (!strlen($out)) { + if (!is_null($out) && !strlen($out)) { $out = null; } break; @@ -376,6 +376,10 @@ public function __unset($name) /** */ public function serialize() + { + return array_shift($this->__serialize()); + } + public function __serialize(): array { global $injector, $session; @@ -383,24 +387,31 @@ public function serialize() $session->set('imp', self::PASSWORDS_KEY, $this->_passwords, $session::ENCRYPT); } - return $injector->getInstance('Horde_Pack')->pack( - array_filter($this->_config), - array( - 'compression' => false, - 'phpob' => false + return + [ + $injector->getInstance('Horde_Pack')->pack( + array_filter($this->_config), + array( + 'compression' => false, + 'phpob' => false + ) ) - ); - } + ]; + } /** */ public function unserialize($data) + { + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void { global $injector, $session; - $this->_config = $injector->getInstance('Horde_Pack')->unpack($data); + $this->_config = $injector->getInstance('Horde_Pack')->unpack(array_shift($data)); $this->_passwords = $session->get('imp', self::PASSWORDS_KEY, $session::TYPE_ARRAY); - } + } } diff --git a/lib/Imap/Password.php b/lib/Imap/Password.php index 5d64e9220..75cde4e34 100644 --- a/lib/Imap/Password.php +++ b/lib/Imap/Password.php @@ -64,6 +64,10 @@ public function getPassword() /** */ public function serialize() + { + return array_shift($this->__serialize()); + } + public function __serialize(): array { global $session; @@ -73,15 +77,21 @@ public function serialize() $session->set('imp', self::PASSWORD_KEY . '/' . $this->_id, $this->_password, $session::ENCRYPT); - return $this->_id; + return + [ + $this->_id + ]; } - /** * @throws RuntimeException */ public function unserialize($data) { - $this->_id = $data; + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $this->_id = $data[0]; $password = $GLOBALS['session']->get( 'imp', @@ -94,6 +104,6 @@ public function unserialize($data) ); } $this->_password = $password; - } + } } diff --git a/lib/LoginTasks/SystemTask/Upgrade.php b/lib/LoginTasks/SystemTask/Upgrade.php index 31112f9e3..4eb91a0c9 100644 --- a/lib/LoginTasks/SystemTask/Upgrade.php +++ b/lib/LoginTasks/SystemTask/Upgrade.php @@ -687,12 +687,23 @@ class IMP_Search_Element_Date implements Serializable public function serialize() { - return ''; + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + '' + ]; } public function unserialize($data) { - $this->data = json_decode($data); + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $this->data = json_decode($data[0]); } } diff --git a/lib/Mailbox/SessionCache.php b/lib/Mailbox/SessionCache.php index b38010e61..2045aaa69 100644 --- a/lib/Mailbox/SessionCache.php +++ b/lib/Mailbox/SessionCache.php @@ -397,20 +397,30 @@ public function expire($entries, $mbox = null) */ public function serialize() { - return $GLOBALS['injector']->getInstance('Horde_Pack')->pack( - $this->_cache, - array( - 'compression' => false, - 'phpob' => false + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + $GLOBALS['injector']->getInstance('Horde_Pack')->pack( + $this->_cache, + array( + 'compression' => false, + 'phpob' => false + ) ) - ); + ]; } /** */ public function unserialize($data) { - $this->_cache = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack($data); + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $this->_cache = $GLOBALS['injector']->getInstance('Horde_Pack')->unpack(array_shift($data)); } - } diff --git a/lib/Message/Date.php b/lib/Message/Date.php index 3ac095557..b9a1f58c1 100644 --- a/lib/Message/Date.php +++ b/lib/Message/Date.php @@ -105,7 +105,7 @@ public function format($format = 0) } $this->_buildCache(); - $tz = strftime('%Z'); + $tz = strftime('%Z'); // TODO replace strftime if (($udate < self::$_cache['today_start']) || ($udate > self::$_cache['today_end'])) { @@ -141,7 +141,7 @@ public function format($format = 0) if ($format === self::DATE_FORCE) { return $this->_format('date_format', $udate) . ' [' . - $this->_format('time_format', $udate) . ' ' . strftime('%Z') . + $this->_format('time_format', $udate) . ' ' . strftime('%Z') . // TODO replace strftime ']'; } diff --git a/lib/Remote/Account.php b/lib/Remote/Account.php index 45e38d966..6fc5451ca 100644 --- a/lib/Remote/Account.php +++ b/lib/Remote/Account.php @@ -232,14 +232,24 @@ public function mailbox($id) */ public function serialize() { - return json_encode($this->_config); + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + json_encode($this->_config) + ]; } /** */ public function unserialize($data) { - $this->_config = json_decode($data, true); + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $this->_config = json_decode($data[0], true); } - } diff --git a/lib/Search/Element.php b/lib/Search/Element.php index 73619f579..baa8b339f 100644 --- a/lib/Search/Element.php +++ b/lib/Search/Element.php @@ -77,10 +77,17 @@ public function getCriteria() */ public function serialize() { - return json_encode(array( - self::VERSION, - $this->_data - )); + return array_shift($this->__serialize()); + } + public function __serialize(): array + { + return + [ + json_encode(array( + self::VERSION, + $this->_data + )) + ]; } /** @@ -92,7 +99,11 @@ public function serialize() */ public function unserialize($data) { - $data = json_decode($data); + $this->__unserialize([$data]); + } + public function __unserialize(array $data): void + { + $data = json_decode($data[0]); if (!is_array($data) || !isset($data[0]) || ($data[0] != self::VERSION)) { @@ -101,5 +112,4 @@ public function unserialize($data) $this->_data = $data[1]; } - } diff --git a/lib/Search/Filter/Builtin.php b/lib/Search/Filter/Builtin.php index 98072780f..cb3b13172 100644 --- a/lib/Search/Filter/Builtin.php +++ b/lib/Search/Filter/Builtin.php @@ -54,4 +54,10 @@ public function unserialize($data) $this->_init(); } + public function __unserialize(array $data): void + { + parent::__unserialize($data); + $this->_init(); + } + } diff --git a/lib/Search/Query.php b/lib/Search/Query.php index c0fa62be6..cce9d492c 100644 --- a/lib/Search/Query.php +++ b/lib/Search/Query.php @@ -374,6 +374,23 @@ public function serialize() return serialize($data); } + public function __serialize(): array + { + $data = array_filter(array( + 'c' => $this->_criteria, + 'e' => intval($this->enabled), + 'i' => $this->_id, + 'l' => $this->_label, + 'm' => $this->_mboxes, + 'v' => self::VERSION + )); + + foreach ($this->_nosave as $val) { + unset($data[$val]); + } + + return $data; + } /** * Unserialization. @@ -405,5 +422,25 @@ public function unserialize($data) $this->_mboxes = $data['m']; } } + public function __unserialize(array $data): void + { + if (!isset($data['v']) || + ($data['v'] != self::VERSION)) { + throw new Exception('Cache version change'); + } + if (isset($data['c'])) { + $this->_criteria = $data['c']; + } + $this->enabled = !empty($data['e']); + if (isset($data['i'])) { + $this->_id = $data['i']; + } + if (isset($data['l'])) { + $this->_label = $data['l']; + } + if (isset($data['m'])) { + $this->_mboxes = $data['m']; + } + } } diff --git a/lib/Search/Vfolder/Builtin.php b/lib/Search/Vfolder/Builtin.php index f1729d93b..739159497 100644 --- a/lib/Search/Vfolder/Builtin.php +++ b/lib/Search/Vfolder/Builtin.php @@ -67,5 +67,9 @@ public function unserialize($data) parent::unserialize($data); $this->_init(); } - + public function __unserialize(array $data): void + { + parent::__unserialize($data); + $this->_init(); + } }