Skip to content

Commit d13731f

Browse files
authored
fix: handle new serialization mechanism in backward compatible way (#65)
Refs #63
1 parent a65bbba commit d13731f

4 files changed

Lines changed: 49 additions & 57 deletions

File tree

src/AnimatedGif.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Code fragments used from: GIFEncoder Version 2.0 by László Zsidi
1313
*/
14-
class AnimatedGif implements \Serializable
14+
class AnimatedGif
1515
{
1616

1717
/**
@@ -278,32 +278,30 @@ public function getAnimation()
278278
/**
279279
* String representation of an AnimatedGif.
280280
*
281-
* @return string The string representation of the object or null.
281+
* @return array The string representation of the object or null.
282282
*/
283-
public function serialize()
283+
public function __serialize()
284284
{
285-
return serialize(
286-
[
287-
$this->outFilePath,
288-
$this->width,
289-
$this->height,
290-
$this->frameRate,
291-
$this->loopCount,
292-
$this->gifData,
293-
$this->frames,
294-
$this->counter,
295-
]
296-
);
285+
return [
286+
$this->outFilePath,
287+
$this->width,
288+
$this->height,
289+
$this->frameRate,
290+
$this->loopCount,
291+
$this->gifData,
292+
$this->frames,
293+
$this->counter,
294+
];
297295
}
298296

299297
/**
300298
* Constructs the AnimatedGif.
301299
*
302-
* @param string $serialized The string representation of the object.
300+
* @param array $serialized The string representation of the object.
303301
*
304302
* @return void
305303
*/
306-
public function unserialize($serialized)
304+
public function __unserialize($serialized)
307305
{
308306
list(
309307
$this->outFilePath,
@@ -314,6 +312,6 @@ public function unserialize($serialized)
314312
$this->gifData,
315313
$this->frames,
316314
$this->counter
317-
) = unserialize($serialized);
315+
) = $serialized;
318316
}
319317
}

src/Frame.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Represents one frame from the movie.
77
*/
8-
class Frame implements \Serializable
8+
class Frame
99
{
1010

1111
protected static $EX_CODE_NO_VALID_RESOURCE = 334563;
@@ -198,34 +198,32 @@ public function getHeight()
198198
/**
199199
* Return string representation of a Frame.
200200
*
201-
* @return string The string representation of the object or null.
201+
* @return array The string representation of the object or null.
202202
*/
203-
public function serialize()
203+
public function __serialize()
204204
{
205-
$data = [
205+
return [
206206
$this->gdImageData,
207207
$this->pts,
208208
$this->width,
209209
$this->height,
210210
];
211-
212-
return serialize($data);
213211
}
214212

215213
/**
216214
* Constructs the Frame from serialized data.
217215
*
218-
* @param string $serialized The string representation of Frame instance.
216+
* @param array $serialized The string representation of Frame instance.
219217
*
220218
* @return void
221219
*/
222-
public function unserialize($serialized)
220+
public function __unserialize($serialized)
223221
{
224222
list(
225223
$this->gdImageData,
226224
$this->pts,
227225
$this->width,
228226
$this->height
229-
) = unserialize($serialized);
227+
) = $serialized;
230228
}
231229
}

src/Movie.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Represents a movie file.
1010
*/
11-
class Movie implements \Serializable
11+
class Movie
1212
{
1313

1414
protected static $REGEX_DURATION = '/Duration: (\d{2}):(\d{2}):(\d{2})(\.(\d+))?/';
@@ -883,38 +883,34 @@ public function __clone()
883883
/**
884884
* String representation of a Movie.
885885
*
886-
* @return string Rhe string representation of the object or null.
886+
* @return array Rhe string representation of the object or null.
887887
*/
888-
public function serialize()
888+
public function __serialize()
889889
{
890-
$data = serialize(
891-
[
892-
$this->ffmpegBinary,
893-
$this->movieFile,
894-
$this->output,
895-
$this->frameNumber,
896-
$this->provider,
897-
]
898-
);
899-
900-
return $data;
890+
return [
891+
$this->ffmpegBinary,
892+
$this->movieFile,
893+
$this->output,
894+
$this->frameNumber,
895+
$this->provider,
896+
];
901897
}
902898

903899
/**
904900
* Constructs the Movie from serialized data.
905901
*
906-
* @param string $serialized The string representation of Movie instance.
902+
* @param array $serialized The string representation of Movie instance.
907903
*
908904
* @return void
909905
*/
910-
public function unserialize($serialized)
906+
public function __unserialize($serialized)
911907
{
912908
list(
913909
$this->ffmpegBinary,
914910
$this->movieFile,
915911
$this->output,
916912
$this->frameNumber,
917913
$this->provider
918-
) = unserialize($serialized);
914+
) = $serialized;
919915
}
920916
}

src/OutputProviders/AbstractProvider.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44
/**
55
* AbstractProvider parent of all output providers.
66
*/
7-
abstract class AbstractProvider implements OutputProvider, \Serializable
7+
abstract class AbstractProvider implements OutputProvider
88
{
99

1010
protected static $EX_CODE_FILE_NOT_FOUND = 334561;
1111
protected static $persistentBuffer = array();
12-
12+
1313
/**
1414
* Binary that returns info about movie file
1515
*
1616
* @var string
1717
*/
1818
protected $binary;
19-
19+
2020
/**
2121
* Movie File path
2222
*
2323
* @var string
2424
*/
2525
protected $movieFile;
26-
26+
2727
/**
2828
* Persistent functionality on/off
2929
*
3030
* @var boolean
3131
*/
3232
protected $persistent;
33-
33+
3434
/**
3535
* Base constructor for every provider
3636
*
@@ -42,7 +42,7 @@ public function __construct($binary, $persistent)
4242
$this->binary = $binary;
4343
$this->persistent = $persistent;
4444
}
45-
45+
4646
/**
4747
* Setting movie file path
4848
*
@@ -52,22 +52,22 @@ public function setMovieFile($movieFile)
5252
{
5353
$this->movieFile = $movieFile;
5454
}
55-
56-
public function serialize()
55+
56+
public function __serialize()
5757
{
58-
return serialize(array(
58+
return [
5959
$this->binary,
6060
$this->movieFile,
6161
$this->persistent
62-
));
62+
];
6363
}
64-
65-
public function unserialize($serialized)
64+
65+
public function __unserialize($serialized)
6666
{
6767
list(
6868
$this->binary,
6969
$this->movieFile,
7070
$this->persistent
71-
) = unserialize($serialized);
71+
) = $serialized;
7272
}
7373
}

0 commit comments

Comments
 (0)