|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Twitter\Serializer; |
|
4
|
|
|
|
|
5
|
|
|
use Assert\Assertion; |
|
6
|
|
|
use Twitter\Object\Tweet; |
|
7
|
|
|
use Twitter\TwitterEventTarget; |
|
8
|
|
|
use Twitter\TwitterSerializable; |
|
9
|
|
|
use Twitter\TwitterSerializer; |
|
10
|
|
|
|
|
11
|
|
|
class TwitterEventTargetSerializer implements TwitterSerializer |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var TweetSerializer |
|
15
|
|
|
*/ |
|
16
|
|
|
private $tweetSerializer; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param TweetSerializer $tweetSerializer |
|
20
|
|
|
*/ |
|
21
|
24 |
|
public function __construct(TweetSerializer $tweetSerializer) |
|
22
|
|
|
{ |
|
23
|
24 |
|
$this->tweetSerializer = $tweetSerializer; |
|
24
|
24 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param TwitterSerializable $object |
|
28
|
|
|
* @return \stdClass |
|
29
|
|
|
*/ |
|
30
|
9 |
|
public function serialize(TwitterSerializable $object) |
|
31
|
|
|
{ |
|
32
|
9 |
|
Assertion::true($this->canSerialize($object), 'object must be an instance of TwitterEventTarget'); |
|
33
|
|
|
|
|
34
|
6 |
|
if ($object instanceof Tweet) { |
|
35
|
3 |
|
return $this->tweetSerializer->serialize($object); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
3 |
|
throw new \BadMethodCallException('Not Implemented'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param \stdClass $obj |
|
43
|
|
|
* @param array $context |
|
44
|
|
|
* @return TwitterEventTarget |
|
45
|
|
|
*/ |
|
46
|
6 |
|
public function unserialize($obj, array $context = []) |
|
47
|
|
|
{ |
|
48
|
6 |
|
if (!$this->canUnserialize($obj)) { |
|
49
|
3 |
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
3 |
|
return $this->tweetSerializer->unserialize($obj); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param TwitterSerializable $object |
|
57
|
|
|
* @return boolean |
|
58
|
|
|
*/ |
|
59
|
9 |
|
public function canSerialize(TwitterSerializable $object) |
|
60
|
|
|
{ |
|
61
|
9 |
|
return $this->tweetSerializer->canSerialize($object) || $object instanceof TwitterEventTarget; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param \stdClass $object |
|
66
|
|
|
* @return boolean |
|
67
|
|
|
*/ |
|
68
|
6 |
|
public function canUnserialize($object) |
|
69
|
|
|
{ |
|
70
|
6 |
|
return $this->tweetSerializer->canUnserialize($object); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return TwitterEventTargetSerializer |
|
75
|
|
|
*/ |
|
76
|
9 |
|
public static function build() |
|
77
|
|
|
{ |
|
78
|
9 |
|
return new self( |
|
79
|
9 |
|
TweetSerializer::build() |
|
80
|
6 |
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|