Total Complexity | 6 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
9 | class Links |
||
10 | { |
||
11 | /** @var \Illuminate\Support\Collection */ |
||
12 | private $linkTypes; |
||
13 | |||
14 | public function __construct() |
||
15 | { |
||
16 | $this->linkTypes = new Collection(); |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * @param string $controller |
||
21 | * |
||
22 | * @return \Spatie\ResourceLinks\LinkTypes\ControllerLinkType|\Spatie\ResourceLinks\LinkTypes\ActionLinkType |
||
23 | */ |
||
24 | public function controller(string $controller) |
||
25 | { |
||
26 | $linkType = method_exists($controller, '__invoke') |
||
27 | ? ActionLinkType::make([$controller]) |
||
28 | : ControllerLinkType::make($controller); |
||
29 | |||
30 | $this->linkTypes[] = $linkType; |
||
31 | |||
32 | return $linkType; |
||
33 | } |
||
34 | |||
35 | public function action(array $action): ActionLinkType |
||
36 | { |
||
37 | $actionLinkType = ActionLinkType::make($action); |
||
38 | |||
39 | $this->linkTypes[] = $actionLinkType; |
||
40 | |||
41 | return $actionLinkType; |
||
42 | } |
||
43 | |||
44 | public function links(Links $links) |
||
45 | { |
||
46 | $this->linkTypes = $this->linkTypes->merge( |
||
47 | $links->getLinkTypes() |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | public function getLinkTypes(): Collection |
||
54 | } |
||
55 | } |
||
56 |