+ /**
+ * Build a representation for an object for logging
+ * @param mixed
+ * @return string
+ */
+ function logrep($object) {
+ if (is_object($object)) {
+ $class = get_class($object);
+ if (isset($object->id)) {
+ return "$class $object->id";
+ }
+ return $class;
+ }
+ if (is_string($object)) {
+ $len = strlen($object);
+ $fragment = mb_substr($object, 0, 32);
+ if (mb_strlen($object) > 32) {
+ $fragment .= '...';
+ }
+ return "string '$fragment' ($len bytes)";
+ }
+ return strval($object);
+ }
+
+ /**
+ * Encode an object or variable for queued storage.
+ * Notice objects are currently stored as an id reference;
+ * other items are serialized.
+ *
+ * @param mixed $item
+ * @return string
+ */
+ protected function encode($item)
+ {
+ if ($item instanceof Notice) {
+ // Backwards compat
+ return $item->id;
+ } else {
+ return serialize($item);
+ }
+ }
+
+ /**
+ * Decode an object from queued storage.
+ * Accepts notice reference entries and serialized items.
+ *
+ * @param string
+ * @return mixed
+ */
+ protected function decode($frame)
+ {
+ if (is_numeric($frame)) {
+ // Back-compat for notices...
+ return Notice::staticGet(intval($frame));
+ } elseif (substr($frame, 0, 1) == '<') {
+ // Back-compat for XML source
+ return $frame;
+ } else {
+ // Deserialize!
+ #$old = error_reporting();
+ #error_reporting($old & ~E_NOTICE);
+ $out = unserialize($frame);
+ #error_reporting($old);
+
+ if ($out === false && $frame !== 'b:0;') {
+ common_log(LOG_ERR, "Couldn't unserialize queued frame: $frame");
+ return false;
+ }
+ return $out;
+ }
+ }
+