Skip to content

Commit

Permalink
fix: handle new serialization mechanism in backward compatible way (#65)
Browse files Browse the repository at this point in the history
Refs #63
  • Loading branch information
char0n committed Aug 31, 2022
1 parent a65bbba commit d13731f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 57 deletions.
34 changes: 16 additions & 18 deletions src/AnimatedGif.php
Expand Up @@ -11,7 +11,7 @@
*
* Code fragments used from: GIFEncoder Version 2.0 by László Zsidi
*/
class AnimatedGif implements \Serializable
class AnimatedGif
{

/**
Expand Down Expand Up @@ -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,
Expand All @@ -314,6 +312,6 @@ public function unserialize($serialized)
$this->gifData,
$this->frames,
$this->counter
) = unserialize($serialized);
) = $serialized;
}
}
16 changes: 7 additions & 9 deletions src/Frame.php
Expand Up @@ -5,7 +5,7 @@
/**
* Represents one frame from the movie.
*/
class Frame implements \Serializable
class Frame
{

protected static $EX_CODE_NO_VALID_RESOURCE = 334563;
Expand Down Expand Up @@ -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;
}
}
30 changes: 13 additions & 17 deletions src/Movie.php
Expand Up @@ -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+))?/';
Expand Down Expand Up @@ -883,38 +883,34 @@ 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,
$this->movieFile,
$this->output,
$this->frameNumber,
$this->provider
) = unserialize($serialized);
) = $serialized;
}
}
26 changes: 13 additions & 13 deletions src/OutputProviders/AbstractProvider.php
Expand Up @@ -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
*
Expand All @@ -42,7 +42,7 @@ public function __construct($binary, $persistent)
$this->binary = $binary;
$this->persistent = $persistent;
}

/**
* Setting movie file path
*
Expand All @@ -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;
}
}

0 comments on commit d13731f

Please sign in to comment.