| @@ 10-78 (lines=69) @@ | ||
| 7 | /** |
|
| 8 | * SerializerIgbinary: serialize / unserialize |
|
| 9 | */ |
|
| 10 | class SerializerIgbinary implements iSerializer |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var bool |
|
| 14 | */ |
|
| 15 | public static $_exists_igbinary; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @var null|array |
|
| 19 | */ |
|
| 20 | private $unserialize_options; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * SerializerIgbinary constructor. |
|
| 24 | */ |
|
| 25 | public function __construct() |
|
| 26 | { |
|
| 27 | if (self::$_exists_igbinary === null) { |
|
| 28 | self::$_exists_igbinary = ( |
|
| 29 | \function_exists('igbinary_serialize') |
|
| 30 | && |
|
| 31 | \function_exists('igbinary_unserialize') |
|
| 32 | ); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function serialize($value) |
|
| 40 | { |
|
| 41 | if (self::$_exists_igbinary === true) { |
|
| 42 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 43 | /** @noinspection PhpComposerExtensionStubsInspection */ |
|
| 44 | return \igbinary_serialize($value); |
|
| 45 | } |
|
| 46 | ||
| 47 | // fallback |
|
| 48 | return \serialize($value); |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * {@inheritdoc} |
|
| 53 | */ |
|
| 54 | public function unserialize($value) |
|
| 55 | { |
|
| 56 | if (self::$_exists_igbinary === true) { |
|
| 57 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 58 | /** @noinspection PhpComposerExtensionStubsInspection */ |
|
| 59 | return \igbinary_unserialize($value); |
|
| 60 | } |
|
| 61 | ||
| 62 | // fallback |
|
| 63 | if ($this->unserialize_options !== null) { |
|
| 64 | return \unserialize($value, $this->unserialize_options); |
|
| 65 | } |
|
| 66 | ||
| 67 | /** @noinspection UnserializeExploitsInspection */ |
|
| 68 | return \unserialize($value); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param array $options |
|
| 73 | */ |
|
| 74 | public function setUnserializeOptions(array $options) |
|
| 75 | { |
|
| 76 | $this->unserialize_options = $options; |
|
| 77 | } |
|
| 78 | } |
|
| 79 | ||
| @@ 10-78 (lines=69) @@ | ||
| 7 | /** |
|
| 8 | * SerializerMsgpack: serialize / unserialize |
|
| 9 | */ |
|
| 10 | class SerializerMsgpack implements iSerializer |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * @var bool |
|
| 14 | */ |
|
| 15 | public static $_exists_msgpack; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @var null|array |
|
| 19 | */ |
|
| 20 | private $unserialize_options; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * SerializerIgbinary constructor. |
|
| 24 | */ |
|
| 25 | public function __construct() |
|
| 26 | { |
|
| 27 | if (self::$_exists_msgpack === null) { |
|
| 28 | self::$_exists_msgpack = ( |
|
| 29 | \function_exists('msgpack_pack') |
|
| 30 | && |
|
| 31 | \function_exists('msgpack_unpack') |
|
| 32 | ); |
|
| 33 | } |
|
| 34 | } |
|
| 35 | ||
| 36 | /** |
|
| 37 | * {@inheritdoc} |
|
| 38 | */ |
|
| 39 | public function serialize($value) |
|
| 40 | { |
|
| 41 | if (self::$_exists_msgpack === true) { |
|
| 42 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 43 | /** @noinspection PhpComposerExtensionStubsInspection */ |
|
| 44 | return \msgpack_pack($value); |
|
| 45 | } |
|
| 46 | ||
| 47 | // fallback |
|
| 48 | return \serialize($value); |
|
| 49 | } |
|
| 50 | ||
| 51 | /** |
|
| 52 | * {@inheritdoc} |
|
| 53 | */ |
|
| 54 | public function unserialize($value) |
|
| 55 | { |
|
| 56 | if (self::$_exists_msgpack === true) { |
|
| 57 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 58 | /** @noinspection PhpComposerExtensionStubsInspection */ |
|
| 59 | return \msgpack_unpack($value); |
|
| 60 | } |
|
| 61 | ||
| 62 | // fallback |
|
| 63 | if ($this->unserialize_options !== null) { |
|
| 64 | return \unserialize($value, $this->unserialize_options); |
|
| 65 | } |
|
| 66 | ||
| 67 | /** @noinspection UnserializeExploitsInspection */ |
|
| 68 | return \unserialize($value); |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param array $options |
|
| 73 | */ |
|
| 74 | public function setUnserializeOptions(array $options) |
|
| 75 | { |
|
| 76 | $this->unserialize_options = $options; |
|
| 77 | } |
|
| 78 | } |
|
| 79 | ||