|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Services\Stream\Objects; |
|
4
|
|
|
|
|
5
|
|
|
use Coyote\Services\UrlBuilder; |
|
6
|
|
|
use Coyote\Comment as Model; |
|
7
|
|
|
|
|
8
|
|
|
class Comment extends ObjectAbstract |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @param array ...$args |
|
12
|
|
|
* @return $this |
|
13
|
|
|
* @throws \Exception |
|
14
|
|
|
*/ |
|
15
|
|
|
public function map(...$args) |
|
16
|
|
|
{ |
|
17
|
|
|
$object = $args[0]; |
|
18
|
|
|
|
|
19
|
|
|
$class = class_basename($object); |
|
20
|
|
|
if (!method_exists($this, $class)) { |
|
21
|
|
|
throw new \Exception("There is not method called $class"); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$this->$class(...$args); |
|
25
|
|
|
|
|
26
|
|
|
return $this; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param \Coyote\Microblog $microblog |
|
31
|
|
|
*/ |
|
32
|
|
|
private function microblog($microblog) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->id = $microblog->id; |
|
35
|
|
|
$this->url = UrlBuilder::microblogComment($microblog); |
|
36
|
|
|
$this->displayName = excerpt($microblog->html); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param \Coyote\Post $post |
|
41
|
|
|
* @param \Coyote\Post\Comment $comment |
|
42
|
|
|
* @param \Coyote\Topic $topic |
|
43
|
|
|
*/ |
|
44
|
|
|
private function post($post, $comment, $topic) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->id = $comment->id; |
|
47
|
|
|
$this->displayName = excerpt($comment->html); |
|
48
|
|
|
$this->url = UrlBuilder::topic($topic) . '?p=' . $post->id . '#comment-' . $comment->id; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param \Coyote\Wiki $wiki |
|
53
|
|
|
* @param \Coyote\Wiki\Comment $comment |
|
54
|
|
|
*/ |
|
55
|
|
|
private function wiki($wiki, $comment) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->id = $comment->id; |
|
58
|
|
|
$this->displayName = excerpt($comment->html); |
|
59
|
|
|
$this->url = UrlBuilder::wikiComment($wiki, $comment->id); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function comment(Model $comment) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->id = $comment->id; |
|
65
|
|
|
$this->displayName = excerpt($comment->html); |
|
66
|
|
|
$this->url = UrlBuilder::url($comment->resource) . '#comment-' . $comment->id; |
|
67
|
|
|
|
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|