mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
revert serializable
This commit is contained in:
parent
a74d2e8a97
commit
9f0a6233a0
|
|
@ -34,7 +34,7 @@ abstract class CacheValueType extends Enum
|
|||
|
||||
public const _ARRAY = 2; /* Data is array */
|
||||
|
||||
public const _SERIALIZABLE = 3; /* Data implements __serialize and __unserialize() */
|
||||
public const _SERIALIZABLE = 3; /* Data implements \Serializable */
|
||||
|
||||
public const _FLOAT = 4; /* Data is float */
|
||||
|
||||
|
|
|
|||
|
|
@ -164,6 +164,8 @@ abstract class ConnectionAbstract implements ConnectionInterface
|
|||
return CacheValueType::_ARRAY;
|
||||
} elseif ($value === null) {
|
||||
return CacheValueType::_NULL;
|
||||
} elseif ($value instanceof \Serializable) {
|
||||
return CacheValueType::_SERIALIZABLE;
|
||||
} elseif ($value instanceof \JsonSerializable) {
|
||||
return CacheValueType::_JSONSERIALIZABLE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use phpOMS\System\File\Local\File;
|
|||
* This implementation uses the hard drive as cache by saving data to the disc as text files.
|
||||
* The text files follow a defined strucuture which allows this implementation to parse the cached data.
|
||||
*
|
||||
* Allowed datatypes: null, int, bool, float, string, \DateTime, \JsonSerializable
|
||||
* Allowed datatypes: null, int, bool, float, string, \DateTime, \JsonSerializable, \Serializable
|
||||
* File structure:
|
||||
* data type (1 byte)
|
||||
* delimiter (1 byte)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ final class MemCached extends ConnectionAbstract
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(\is_scalar($value) || $value === null || \is_array($value) || $value instanceof \JsonSerializable) {
|
||||
if (!(\is_scalar($value) || $value === null || \is_array($value) || $value instanceof \JsonSerializable || $value instanceof \Serializable)) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ final class MemCached extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!(\is_scalar($value) || $value === null || \is_array($value) || $value instanceof \JsonSerializable) {
|
||||
if (!(\is_scalar($value) || $value === null || \is_array($value) || $value instanceof \JsonSerializable || $value instanceof \Serializable)) {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1454,6 +1454,8 @@ class Builder extends BuilderAbstract
|
|||
return $column;
|
||||
} elseif ($column instanceof Column) {
|
||||
return $column->getColumn();
|
||||
} elseif ($column instanceof \Serializable) {
|
||||
return $column->serialize();
|
||||
} elseif ($column instanceof self) {
|
||||
return \md5($column->toSql());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -359,6 +359,8 @@ class Grammar extends GrammarAbstract
|
|||
$encoded = \json_encode($value);
|
||||
|
||||
return $encoded ? $encoded : 'NULL';
|
||||
} elseif ($value instanceof \Serializable) {
|
||||
return $value->serialize();
|
||||
} elseif ($value instanceof Parameter) {
|
||||
return $value->__toString();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -736,7 +736,7 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetExists(mixed $offset) : bool
|
||||
public function offsetExists($offset) : bool
|
||||
{
|
||||
$row = (int) ($offset / $this->m);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ use phpOMS\Message\HeaderAbstract;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SocketHeader extends HeaderAbstract
|
||||
class SocketHeader extends HeaderAbstract implements \Serializable
|
||||
{
|
||||
private $sendFrom = null;
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ class SocketHeader extends HeaderAbstract
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
|
@ -225,7 +225,7 @@ class SocketHeader extends HeaderAbstract
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __unserialize($string) : void
|
||||
public function unserialize($string) : void
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Contract\ArrayableInterface;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Dom implements ArrayableInterface
|
||||
final class Dom implements \Serializable, ArrayableInterface
|
||||
{
|
||||
/**
|
||||
* Message type.
|
||||
|
|
@ -129,9 +129,9 @@ final class Dom implements ArrayableInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->toArray());
|
||||
return $this->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -145,7 +145,7 @@ final class Dom implements ArrayableInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize($raw) : void
|
||||
public function unserialize($raw) : void
|
||||
{
|
||||
$unserialized = \json_decode($raw, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Contract\ArrayableInterface;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class FormValidation implements \JsonSerializable, ArrayableInterface
|
||||
final class FormValidation implements \JsonSerializable, \Serializable, ArrayableInterface
|
||||
{
|
||||
/**
|
||||
* Message type.
|
||||
|
|
@ -61,9 +61,9 @@ final class FormValidation implements \JsonSerializable, ArrayableInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->toArray());
|
||||
return $this->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -77,7 +77,7 @@ final class FormValidation implements \JsonSerializable, ArrayableInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize($raw) : void
|
||||
public function unserialize($raw) : void
|
||||
{
|
||||
$unserialized = \json_decode($raw, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Contract\ArrayableInterface;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Notify implements \JsonSerializable, ArrayableInterface
|
||||
final class Notify implements \JsonSerializable, \Serializable, ArrayableInterface
|
||||
{
|
||||
/**
|
||||
* Message type.
|
||||
|
|
@ -165,9 +165,9 @@ final class Notify implements \JsonSerializable, ArrayableInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->toArray());
|
||||
return $this->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,7 +181,7 @@ final class Notify implements \JsonSerializable, ArrayableInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize($raw) : void
|
||||
public function unserialize($raw) : void
|
||||
{
|
||||
$unserialized = \json_decode($raw, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Contract\ArrayableInterface;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Redirect implements \JsonSerializable, ArrayableInterface
|
||||
final class Redirect implements \JsonSerializable, \Serializable, ArrayableInterface
|
||||
{
|
||||
/**
|
||||
* Message type.
|
||||
|
|
@ -107,9 +107,9 @@ final class Redirect implements \JsonSerializable, ArrayableInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->toArray());
|
||||
return $this->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,7 +123,7 @@ final class Redirect implements \JsonSerializable, ArrayableInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize($raw) : void
|
||||
public function unserialize($raw) : void
|
||||
{
|
||||
$unserialized = \json_decode($raw, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Contract\ArrayableInterface;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Reload implements \JsonSerializable, ArrayableInterface
|
||||
final class Reload implements \JsonSerializable, \Serializable, ArrayableInterface
|
||||
{
|
||||
/**
|
||||
* Message type.
|
||||
|
|
@ -75,15 +75,15 @@ final class Reload implements \JsonSerializable, ArrayableInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->toArray());
|
||||
return $this->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize($raw) : void
|
||||
public function unserialize($raw) : void
|
||||
{
|
||||
$unserialized = \json_decode($raw, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Stdlib\Base;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class FloatInt
|
||||
class FloatInt implements \Serializable
|
||||
{
|
||||
/**
|
||||
* Max amount of decimals.
|
||||
|
|
@ -306,7 +306,7 @@ class FloatInt
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return (string) $this->getInt();
|
||||
}
|
||||
|
|
@ -320,7 +320,7 @@ class FloatInt
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __unserialize($value) : void
|
||||
public function unserialize($value) : void
|
||||
{
|
||||
$this->setInt((int) $value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Validation\Finance\IbanEnum;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Iban
|
||||
class Iban implements \Serializable
|
||||
{
|
||||
/**
|
||||
* Iban.
|
||||
|
|
@ -254,7 +254,7 @@ class Iban
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return $this->prettyPrint();
|
||||
}
|
||||
|
|
@ -280,7 +280,7 @@ class Iban
|
|||
* @return void
|
||||
* @since 5.1.0
|
||||
*/
|
||||
public function __unserialize($serialized) : void
|
||||
public function unserialize($serialized) : void
|
||||
{
|
||||
$this->parse($serialized);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Localization\ISO3166TwoEnum;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Location implements \JsonSerializable
|
||||
class Location implements \JsonSerializable, \Serializable
|
||||
{
|
||||
/**
|
||||
* Location id
|
||||
|
|
@ -183,9 +183,9 @@ class Location implements \JsonSerializable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->toArray());
|
||||
return (string) \json_encode($this->jsonSerialize());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -214,7 +214,7 @@ class Location implements \JsonSerializable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize($serialized) : void
|
||||
public function unserialize($serialized) : void
|
||||
{
|
||||
$data = \json_decode($serialized, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PriorityQueue implements \Countable
|
||||
class PriorityQueue implements \Countable, \Serializable
|
||||
{
|
||||
/**
|
||||
* Queue type.
|
||||
|
|
@ -313,9 +313,9 @@ class PriorityQueue implements \Countable
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode($this->queue);
|
||||
return (string) \json_encode($this->queue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -327,7 +327,7 @@ class PriorityQueue implements \Countable
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __unserialize($data) : void
|
||||
public function unserialize($data) : void
|
||||
{
|
||||
$this->queue = \json_decode($data, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -728,7 +728,7 @@ class Directory extends FileAbstract implements DirectoryInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetExists(mixed $offset) : bool
|
||||
public function offsetExists($offset) : bool
|
||||
{
|
||||
$offset = isset($this->nodes[$offset]) ? $offset : $this->path . '/' . $offset;
|
||||
|
||||
|
|
|
|||
|
|
@ -551,7 +551,7 @@ final class Directory extends FileAbstract implements DirectoryInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function offsetExists(mixed $offset) : bool
|
||||
public function offsetExists($offset) : bool
|
||||
{
|
||||
$offset = isset($this->nodes[$offset]) ? $offset : $this->path . '/' . $offset;
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ class ArrayParser
|
|||
return \rtrim(\rtrim(\number_format($value, 5, '.', ''), '0'), '.');
|
||||
} elseif (\is_scalar($value)) {
|
||||
return (string) $value;
|
||||
} elseif ($value instanceof \Serializable) {
|
||||
return self::parseVariable($value->serialize());
|
||||
} elseif ($value instanceof \JsonSerializable) {
|
||||
return self::parseVariable($value->jsonSerialize());
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -200,6 +200,8 @@ final class StringUtils
|
|||
$encoded = \json_encode($element, $option !== null ? $option : 0);
|
||||
|
||||
return $encoded ? $encoded : null;
|
||||
} elseif ($element instanceof \Serializable) {
|
||||
return $element->serialize();
|
||||
} elseif (\is_string($element)) {
|
||||
return $element;
|
||||
} elseif (\is_int($element) || \is_float($element)) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace phpOMS\Utils\TaskSchedule;
|
|||
* @link https://karaka.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Interval
|
||||
class Interval implements \Serializable
|
||||
{
|
||||
/**
|
||||
* Start of the task.
|
||||
|
|
@ -113,7 +113,7 @@ class Interval
|
|||
$this->start = $start ?? new \DateTime('now');
|
||||
|
||||
if ($interval !== null) {
|
||||
$this->__unserialize($interval);
|
||||
$this->unserialize($interval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -524,9 +524,9 @@ class Interval
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __serialize() : string
|
||||
public function serialize() : string
|
||||
{
|
||||
return \json_encode([
|
||||
$serialized = \json_encode([
|
||||
'start' => $this->start->format('Y-m-d H:i:s'),
|
||||
'end' => $this->end === null ? null : $this->end->format('Y-m-d H:i:s'),
|
||||
'maxDuration' => $this->maxDuration,
|
||||
|
|
@ -536,6 +536,8 @@ class Interval
|
|||
'dayOfWeek' => $this->dayOfWeek,
|
||||
'year' => $this->year,
|
||||
]);
|
||||
|
||||
return $serialized === false ? '{}' : $serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -547,7 +549,7 @@ class Interval
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __unserialize($serialized) : void
|
||||
public function unserialize($serialized) : void
|
||||
{
|
||||
$data = \json_decode($serialized, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,16 +14,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace phpOMS\tests\DataStorage\Cache\Connection;
|
||||
|
||||
class FileCacheSerializable
|
||||
class FileCacheSerializable implements \Serializable
|
||||
{
|
||||
public $val = 'asdf';
|
||||
|
||||
public function __serialize()
|
||||
public function serialize()
|
||||
{
|
||||
return ['abc'];
|
||||
return 'abc';
|
||||
}
|
||||
|
||||
public function __unserialize($val) : void
|
||||
public function unserialize($val) : void
|
||||
{
|
||||
$this->val = $val;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,15 +65,15 @@ class BaseModel
|
|||
$this->ownsOneSelf = new OwnsOneModel();
|
||||
$this->belongsToOne = new BelongsToModel();
|
||||
|
||||
$this->serializable = new class() {
|
||||
$this->serializable = new class() implements \Serializable {
|
||||
public $value = '';
|
||||
|
||||
public function __serialize()
|
||||
public function serialize()
|
||||
{
|
||||
return ['123'];
|
||||
return '123';
|
||||
}
|
||||
|
||||
public function __unserialize($data) : void
|
||||
public function unserialize($data) : void
|
||||
{
|
||||
$this->value = $data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ final class ArrayParserTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testParser() : void
|
||||
{
|
||||
$serializable = new class() implements \Serializable {
|
||||
public function serialize() { return 2; }
|
||||
|
||||
public function unserialize($raw) : void {}
|
||||
};
|
||||
|
||||
$jsonSerialize = new class() implements \JsonSerializable {
|
||||
public function jsonSerialize() { return [6, 7]; }
|
||||
};
|
||||
|
|
@ -44,6 +50,7 @@ final class ArrayParserTest extends \PHPUnit\Framework\TestCase
|
|||
0 => 'a',
|
||||
1 => 'b',
|
||||
],
|
||||
5 => $serializable,
|
||||
6 => $jsonSerialize,
|
||||
];
|
||||
|
||||
|
|
@ -57,6 +64,7 @@ final class ArrayParserTest extends \PHPUnit\Framework\TestCase
|
|||
0 => 'a',
|
||||
1 => 'b',
|
||||
],
|
||||
5 => $serializable->serialize(),
|
||||
6 => $jsonSerialize->jsonSerialize(),
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -130,6 +130,17 @@ final class StringUtilsTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
self::assertEquals('["abc"]', StringUtils::stringify(['abc']));
|
||||
|
||||
self::assertEquals('abc', StringUtils::stringify(new class() implements \Serializable {
|
||||
public function serialize()
|
||||
{
|
||||
return 'abc';
|
||||
}
|
||||
|
||||
public function unserialize($val) : void
|
||||
{
|
||||
}
|
||||
}));
|
||||
|
||||
self::assertEquals('abc', StringUtils::stringify('abc'));
|
||||
self::assertEquals('1', StringUtils::stringify(1));
|
||||
self::assertEquals('1.1', StringUtils::stringify(1.1));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user