| @@ 10-97 (lines=88) @@ | ||
| 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 array|null |
|
| 19 | */ |
|
| 20 | private $unserialize_options; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | private $name = ''; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * SerializerIgbinary constructor. |
|
| 29 | */ |
|
| 30 | public function __construct() |
|
| 31 | { |
|
| 32 | if (self::$_exists_igbinary === null) { |
|
| 33 | self::$_exists_igbinary = ( |
|
| 34 | \function_exists('igbinary_serialize') |
|
| 35 | && |
|
| 36 | \function_exists('igbinary_unserialize') |
|
| 37 | ); |
|
| 38 | } |
|
| 39 | ||
| 40 | if (self::$_exists_igbinary) { |
|
| 41 | $this->name = 'igbinary'; |
|
| 42 | } else { |
|
| 43 | $this->name = 'default'; |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @return string |
|
| 49 | */ |
|
| 50 | public function getName(): string |
|
| 51 | { |
|
| 52 | return $this->name; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * {@inheritdoc} |
|
| 57 | */ |
|
| 58 | public function serialize($value) |
|
| 59 | { |
|
| 60 | if (self::$_exists_igbinary === true) { |
|
| 61 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 62 | /** @noinspection PhpComposerExtensionStubsInspection */ |
|
| 63 | return \igbinary_serialize($value); |
|
| 64 | } |
|
| 65 | ||
| 66 | // fallback |
|
| 67 | return \serialize($value); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * {@inheritdoc} |
|
| 72 | */ |
|
| 73 | public function unserialize($value) |
|
| 74 | { |
|
| 75 | if (self::$_exists_igbinary === true) { |
|
| 76 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 77 | /** @noinspection PhpComposerExtensionStubsInspection */ |
|
| 78 | return \igbinary_unserialize($value); |
|
| 79 | } |
|
| 80 | ||
| 81 | // fallback |
|
| 82 | if ($this->unserialize_options !== null) { |
|
| 83 | return \unserialize($value, $this->unserialize_options); |
|
| 84 | } |
|
| 85 | ||
| 86 | /** @noinspection UnserializeExploitsInspection */ |
|
| 87 | return \unserialize($value); |
|
| 88 | } |
|
| 89 | ||
| 90 | /** |
|
| 91 | * @param array $options |
|
| 92 | */ |
|
| 93 | public function setUnserializeOptions(array $options) |
|
| 94 | { |
|
| 95 | $this->unserialize_options = $options; |
|
| 96 | } |
|
| 97 | } |
|
| 98 | ||
| @@ 10-95 (lines=86) @@ | ||
| 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 array|null |
|
| 19 | */ |
|
| 20 | private $unserialize_options; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | private $name = ''; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * SerializerIgbinary constructor. |
|
| 29 | */ |
|
| 30 | public function __construct() |
|
| 31 | { |
|
| 32 | if (self::$_exists_msgpack === null) { |
|
| 33 | self::$_exists_msgpack = ( |
|
| 34 | \function_exists('msgpack_pack') |
|
| 35 | && |
|
| 36 | \function_exists('msgpack_unpack') |
|
| 37 | ); |
|
| 38 | } |
|
| 39 | ||
| 40 | if (self::$_exists_msgpack) { |
|
| 41 | $this->name = 'msgpack'; |
|
| 42 | } else { |
|
| 43 | $this->name = 'default'; |
|
| 44 | } |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * @return string |
|
| 49 | */ |
|
| 50 | public function getName(): string |
|
| 51 | { |
|
| 52 | return $this->name; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * {@inheritdoc} |
|
| 57 | */ |
|
| 58 | public function serialize($value) |
|
| 59 | { |
|
| 60 | if (self::$_exists_msgpack === true) { |
|
| 61 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 62 | return \msgpack_pack($value); |
|
| 63 | } |
|
| 64 | ||
| 65 | // fallback |
|
| 66 | return \serialize($value); |
|
| 67 | } |
|
| 68 | ||
| 69 | /** |
|
| 70 | * {@inheritdoc} |
|
| 71 | */ |
|
| 72 | public function unserialize($value) |
|
| 73 | { |
|
| 74 | if (self::$_exists_msgpack === true) { |
|
| 75 | /** @noinspection PhpUndefinedFunctionInspection */ |
|
| 76 | return \msgpack_unpack($value); |
|
| 77 | } |
|
| 78 | ||
| 79 | // fallback |
|
| 80 | if ($this->unserialize_options !== null) { |
|
| 81 | return \unserialize($value, $this->unserialize_options); |
|
| 82 | } |
|
| 83 | ||
| 84 | /** @noinspection UnserializeExploitsInspection */ |
|
| 85 | return \unserialize($value); |
|
| 86 | } |
|
| 87 | ||
| 88 | /** |
|
| 89 | * @param array $options |
|
| 90 | */ |
|
| 91 | public function setUnserializeOptions(array $options) |
|
| 92 | { |
|
| 93 | $this->unserialize_options = $options; |
|
| 94 | } |
|
| 95 | } |
|
| 96 | ||