|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Coyote\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Coyote\Forum; |
|
6
|
|
|
use Coyote\Job; |
|
7
|
|
|
use Coyote\Microblog; |
|
8
|
|
|
use Coyote\Guide; |
|
9
|
|
|
use Coyote\Post; |
|
10
|
|
|
use Coyote\Topic; |
|
11
|
|
|
use Coyote\Wiki; |
|
12
|
|
|
|
|
13
|
|
|
class UrlBuilder |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param Topic $topic |
|
17
|
|
|
* @return string |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function topic(Topic $topic) |
|
20
|
|
|
{ |
|
21
|
|
|
return route('forum.topic', ['forum' => $topic->forum->slug, 'topic' => $topic->id, 'slug' => $topic->slug], false); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param Forum $forum |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function forum(Forum $forum) |
|
29
|
|
|
{ |
|
30
|
|
|
return route('forum.category', [$forum->slug], false); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param Post $post |
|
35
|
|
|
* @param bool $absolute |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function post(Post $post, bool $absolute = false) |
|
39
|
|
|
{ |
|
40
|
|
|
return route('forum.topic', ['forum' => $post->forum->slug, 'topic' => $post->topic->id, 'slug' => $post->topic->slug], $absolute) . '?p=' . $post->id . '#id' . $post->id; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param Post\Comment $comment |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function postComment(Post\Comment $comment): string |
|
48
|
|
|
{ |
|
49
|
|
|
return route('forum.topic', [$comment->post->forum->slug, $comment->post->topic->id, $comment->post->topic->slug], false) |
|
50
|
|
|
. '?p=' . $comment->post->id . '#comment-' . $comment->id; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param Wiki $wiki |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function wiki(Wiki $wiki) |
|
58
|
|
|
{ |
|
59
|
|
|
return route('wiki.show', [$wiki->path], false); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param Job $job |
|
64
|
|
|
* @param bool $absolute |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public static function job(Job $job, $absolute = false) |
|
68
|
|
|
{ |
|
69
|
|
|
return route('job.offer', [$job->id, $job->slug], $absolute); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param Job $job |
|
74
|
|
|
* @param int $commentId |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function jobComment(Job $job, int $commentId): string |
|
78
|
|
|
{ |
|
79
|
|
|
return route('job.offer', [$job->id, $job->slug]) . '#comment-' . $commentId; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param Wiki $wiki |
|
84
|
|
|
* @param int $commentId |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
public static function wikiComment(Wiki $wiki, int $commentId) |
|
88
|
|
|
{ |
|
89
|
|
|
return route('wiki.show', [$wiki->path], false) . '#comment-' . $commentId; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param Microblog $microblog |
|
94
|
|
|
* @param bool $absolute |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public static function microblog(Microblog $microblog, bool $absolute = false) |
|
98
|
|
|
{ |
|
99
|
|
|
return route('microblog.view', [$microblog->id], $absolute); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param Microblog $comment |
|
104
|
|
|
* @param bool $absolute |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
public static function microblogComment(Microblog $comment, bool $absolute = false) |
|
108
|
|
|
{ |
|
109
|
|
|
return route('microblog.view', [$comment->parent_id], $absolute) . '#comment-' . $comment->id; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param Guide $guide |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public static function guide(Guide $guide): string |
|
117
|
|
|
{ |
|
118
|
|
|
return route('guide.show', [$guide->id, $guide->slug], false); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public static function url($model): string |
|
122
|
|
|
{ |
|
123
|
|
|
return match ($model::class) { |
|
124
|
|
|
Guide::class => self::guide($model), |
|
125
|
|
|
Job::class => self::job($model), |
|
126
|
|
|
Topic::class => self::topic($model), |
|
127
|
|
|
Post::class => self::post($model), |
|
128
|
|
|
Forum::class => self::forum($model), |
|
129
|
|
|
Post\Comment::class => self::postComment($model), |
|
130
|
|
|
Wiki::class => self::wiki($model), |
|
131
|
|
|
Microblog::class => self::microblog($model) |
|
132
|
|
|
}; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|