From d13731f22742bf95d978fcba69cf5b9eabc74433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Wed, 31 Aug 2022 12:08:53 +0200 Subject: [PATCH] fix: handle new serialization mechanism in backward compatible way (#65) Refs #63 --- src/AnimatedGif.php | 34 +++++++++++------------- src/Frame.php | 16 +++++------ src/Movie.php | 30 +++++++++------------ src/OutputProviders/AbstractProvider.php | 26 +++++++++--------- 4 files changed, 49 insertions(+), 57 deletions(-) diff --git a/src/AnimatedGif.php b/src/AnimatedGif.php index f6f6025..56a37ad 100644 --- a/src/AnimatedGif.php +++ b/src/AnimatedGif.php @@ -11,7 +11,7 @@ * * Code fragments used from: GIFEncoder Version 2.0 by László Zsidi */ -class AnimatedGif implements \Serializable +class AnimatedGif { /** @@ -278,32 +278,30 @@ public function getAnimation() /** * String representation of an AnimatedGif. * - * @return string The string representation of the object or null. + * @return array The string representation of the object or null. */ - public function serialize() + public function __serialize() { - return serialize( - [ - $this->outFilePath, - $this->width, - $this->height, - $this->frameRate, - $this->loopCount, - $this->gifData, - $this->frames, - $this->counter, - ] - ); + return [ + $this->outFilePath, + $this->width, + $this->height, + $this->frameRate, + $this->loopCount, + $this->gifData, + $this->frames, + $this->counter, + ]; } /** * Constructs the AnimatedGif. * - * @param string $serialized The string representation of the object. + * @param array $serialized The string representation of the object. * * @return void */ - public function unserialize($serialized) + public function __unserialize($serialized) { list( $this->outFilePath, @@ -314,6 +312,6 @@ public function unserialize($serialized) $this->gifData, $this->frames, $this->counter - ) = unserialize($serialized); + ) = $serialized; } } diff --git a/src/Frame.php b/src/Frame.php index 8bf0a4e..4e838b4 100644 --- a/src/Frame.php +++ b/src/Frame.php @@ -5,7 +5,7 @@ /** * Represents one frame from the movie. */ -class Frame implements \Serializable +class Frame { protected static $EX_CODE_NO_VALID_RESOURCE = 334563; @@ -198,34 +198,32 @@ public function getHeight() /** * Return string representation of a Frame. * - * @return string The string representation of the object or null. + * @return array The string representation of the object or null. */ - public function serialize() + public function __serialize() { - $data = [ + return [ $this->gdImageData, $this->pts, $this->width, $this->height, ]; - - return serialize($data); } /** * Constructs the Frame from serialized data. * - * @param string $serialized The string representation of Frame instance. + * @param array $serialized The string representation of Frame instance. * * @return void */ - public function unserialize($serialized) + public function __unserialize($serialized) { list( $this->gdImageData, $this->pts, $this->width, $this->height - ) = unserialize($serialized); + ) = $serialized; } } diff --git a/src/Movie.php b/src/Movie.php index 2098a76..091da0d 100644 --- a/src/Movie.php +++ b/src/Movie.php @@ -8,7 +8,7 @@ /** * Represents a movie file. */ -class Movie implements \Serializable +class Movie { protected static $REGEX_DURATION = '/Duration: (\d{2}):(\d{2}):(\d{2})(\.(\d+))?/'; @@ -883,31 +883,27 @@ public function __clone() /** * String representation of a Movie. * - * @return string Rhe string representation of the object or null. + * @return array Rhe string representation of the object or null. */ - public function serialize() + public function __serialize() { - $data = serialize( - [ - $this->ffmpegBinary, - $this->movieFile, - $this->output, - $this->frameNumber, - $this->provider, - ] - ); - - return $data; + return [ + $this->ffmpegBinary, + $this->movieFile, + $this->output, + $this->frameNumber, + $this->provider, + ]; } /** * Constructs the Movie from serialized data. * - * @param string $serialized The string representation of Movie instance. + * @param array $serialized The string representation of Movie instance. * * @return void */ - public function unserialize($serialized) + public function __unserialize($serialized) { list( $this->ffmpegBinary, @@ -915,6 +911,6 @@ public function unserialize($serialized) $this->output, $this->frameNumber, $this->provider - ) = unserialize($serialized); + ) = $serialized; } } diff --git a/src/OutputProviders/AbstractProvider.php b/src/OutputProviders/AbstractProvider.php index 108c184..1d283cc 100644 --- a/src/OutputProviders/AbstractProvider.php +++ b/src/OutputProviders/AbstractProvider.php @@ -4,33 +4,33 @@ /** * AbstractProvider parent of all output providers. */ -abstract class AbstractProvider implements OutputProvider, \Serializable +abstract class AbstractProvider implements OutputProvider { protected static $EX_CODE_FILE_NOT_FOUND = 334561; protected static $persistentBuffer = array(); - + /** * Binary that returns info about movie file * * @var string */ protected $binary; - + /** * Movie File path * * @var string */ protected $movieFile; - + /** * Persistent functionality on/off * * @var boolean */ protected $persistent; - + /** * Base constructor for every provider * @@ -42,7 +42,7 @@ public function __construct($binary, $persistent) $this->binary = $binary; $this->persistent = $persistent; } - + /** * Setting movie file path * @@ -52,22 +52,22 @@ public function setMovieFile($movieFile) { $this->movieFile = $movieFile; } - - public function serialize() + + public function __serialize() { - return serialize(array( + return [ $this->binary, $this->movieFile, $this->persistent - )); + ]; } - - public function unserialize($serialized) + + public function __unserialize($serialized) { list( $this->binary, $this->movieFile, $this->persistent - ) = unserialize($serialized); + ) = $serialized; } }