|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Twitter\Serializer; |
|
4
|
|
|
|
|
5
|
|
|
use Assert\Assertion; |
|
6
|
|
|
use Twitter\Object\TwitterVariantMedia; |
|
7
|
|
|
use Twitter\TwitterSerializable; |
|
8
|
|
|
use Twitter\TwitterSerializer; |
|
9
|
|
|
|
|
10
|
|
|
class TwitterVariantMediaSerializer implements TwitterSerializer |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param TwitterSerializable $object |
|
14
|
|
|
* @return \stdClass |
|
15
|
|
|
*/ |
|
16
|
6 |
|
public function serialize(TwitterSerializable $object) |
|
17
|
|
|
{ |
|
18
|
|
|
/* @var TwitterVariantMedia $object */ |
|
19
|
6 |
|
Assertion::true($this->canSerialize($object), 'object must be an instance of TwitterVariantMedia'); |
|
20
|
|
|
|
|
21
|
3 |
|
$variantMedia = new \stdClass(); |
|
22
|
3 |
|
$variantMedia->content_type = $object->getContentType(); |
|
23
|
3 |
|
$variantMedia->url = $object->getUrl(); |
|
24
|
3 |
|
$variantMedia->bitrate = $object->getBitrate(); |
|
25
|
|
|
|
|
26
|
3 |
|
return $variantMedia; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param \stdClass $obj |
|
31
|
|
|
* @param array $context |
|
32
|
|
|
* @return TwitterVariantMedia |
|
33
|
|
|
*/ |
|
34
|
6 |
|
public function unserialize($obj, array $context = []) |
|
35
|
|
|
{ |
|
36
|
6 |
|
Assertion::true($this->canUnserialize($obj), 'object is not unserializable'); |
|
37
|
|
|
|
|
38
|
3 |
|
return TwitterVariantMedia::create($obj->content_type, $obj->url, $obj->bitrate?:null); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param TwitterSerializable $object |
|
43
|
|
|
* @return boolean |
|
44
|
|
|
*/ |
|
45
|
6 |
|
public function canSerialize(TwitterSerializable $object) |
|
46
|
|
|
{ |
|
47
|
6 |
|
return $object instanceof TwitterVariantMedia; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param \stdClass $object |
|
52
|
|
|
* @return boolean |
|
53
|
|
|
*/ |
|
54
|
6 |
|
public function canUnserialize($object) |
|
55
|
|
|
{ |
|
56
|
6 |
|
return isset($object->content_type) && isset($object->url) && isset($object->bitrate); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return TwitterVariantMediaSerializer |
|
61
|
|
|
*/ |
|
62
|
24 |
|
public static function build() |
|
63
|
|
|
{ |
|
64
|
24 |
|
return new self(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|