|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spinen\ClickUp\Support\Relations; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Traits\ForwardsCalls; |
|
6
|
|
|
use Illuminate\Support\Traits\Macroable; |
|
7
|
|
|
use Spinen\ClickUp\Exceptions\InvalidRelationshipException; |
|
8
|
|
|
use Spinen\ClickUp\Support\Builder; |
|
9
|
|
|
use Spinen\ClickUp\Support\Model; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Relation |
|
13
|
|
|
* |
|
14
|
|
|
* @package Spinen\ClickUp\Support\Relations |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class Relation |
|
17
|
|
|
{ |
|
18
|
|
|
use ForwardsCalls, Macroable { |
|
|
|
|
|
|
19
|
|
|
__call as macroCall; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The Eloquent builder builder instance. |
|
24
|
|
|
* |
|
25
|
|
|
* @var Builder |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $builder; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The parent model instance. |
|
31
|
|
|
* |
|
32
|
|
|
* @var Model |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $parent; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The related model instance. |
|
38
|
|
|
* |
|
39
|
|
|
* @var Model |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $related; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Create a new relation instance. |
|
45
|
|
|
* |
|
46
|
|
|
* @param Builder $builder |
|
47
|
|
|
* @param Model $parent |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
* @throws InvalidRelationshipException |
|
51
|
|
|
*/ |
|
52
|
77 |
|
public function __construct(Builder $builder, Model $parent) |
|
53
|
|
|
{ |
|
54
|
77 |
|
$this->builder = $builder; |
|
55
|
77 |
|
$this->parent = $parent; |
|
56
|
77 |
|
$this->related = $builder->getModel(); |
|
57
|
77 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Handle dynamic method calls to the relationship. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $method |
|
63
|
|
|
* @param array $parameters |
|
64
|
|
|
* |
|
65
|
|
|
* @return mixed |
|
66
|
|
|
*/ |
|
67
|
3 |
|
public function __call($method, $parameters) |
|
68
|
|
|
{ |
|
69
|
3 |
|
if (static::hasMacro($method)) { |
|
70
|
1 |
|
return $this->macroCall($method, $parameters); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
2 |
|
$result = $this->forwardCallTo($this->getBuilder(), $method, $parameters); |
|
74
|
|
|
|
|
75
|
2 |
|
if ($result === $this->getBuilder()) { |
|
76
|
1 |
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
return $result; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get the Builder instance |
|
84
|
|
|
* |
|
85
|
|
|
* @return Builder |
|
86
|
|
|
*/ |
|
87
|
11 |
|
public function getBuilder(): Builder |
|
88
|
|
|
{ |
|
89
|
11 |
|
return $this->builder; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get the parent Model instance |
|
94
|
|
|
* |
|
95
|
|
|
* @return Model |
|
96
|
|
|
*/ |
|
97
|
4 |
|
public function getParent(): Model |
|
98
|
|
|
{ |
|
99
|
4 |
|
return $this->parent; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get the related Model instance |
|
104
|
|
|
* |
|
105
|
|
|
* @return Model |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function getRelated(): Model |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->related; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get the results of the relationship. |
|
114
|
|
|
* |
|
115
|
|
|
* @return mixed |
|
116
|
|
|
*/ |
|
117
|
|
|
abstract public function getResults(); |
|
118
|
|
|
} |
|
119
|
|
|
|