Skip to content

Commit

Permalink
Add __serialize/__unserialize
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed May 25, 2022
1 parent 2d0b262 commit 0830ac7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
26 changes: 21 additions & 5 deletions lib/Horde/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,22 +599,38 @@ public function close()
/**
*/
public function serialize()
{
return json_encode($this->__serialize());
}

/**
*/
public function unserialize($data)
{

$this->__unserialize(json_decode($data, true));
}

/**
* @return array
*/
public function __serialize()
{
$this->_params['_pos'] = $this->pos();

return json_encode(array(
return array(
strval($this),
$this->_params
));
);
}

/**
* @param array $data
* @return void
*/
public function unserialize($data)
public function __unserialize($data)
{
$this->_init();

$data = json_decode($data, true);
$this->add($data[0]);
$this->seek($data[1]['_pos'], false);
unset($data[1]['_pos']);
Expand Down
28 changes: 21 additions & 7 deletions lib/Horde/Stream/TempString.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,43 @@ public function eof()
/**
*/
public function serialize()
{
return serialize($this->__serialize());
}

/**
*/
public function unserialize($data)
{
$this->__unserialize(unserialize($data));
}

/**
* @return array
*/
public function __serialize()
{
if ($this->_string) {
$data = array(
return array(
$this->_string,
$this->_params
);
} else {
$data = parent::serialize();
return parent::__serialize();
}

return serialize($data);
}

/**
* @param array $data
* @return void
*/
public function unserialize($data)
public function __unserialize($data)
{
$data = unserialize($data);
if ($data[0] instanceof Horde_Stream_String) {
$this->_string = $data[0];
$this->_params = $data[1];
} else {
parent::unserialize($data);
parent::__unserialize($data);
}
}

Expand Down

0 comments on commit 0830ac7

Please sign in to comment.