1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\roa\hal; |
4
|
|
|
|
5
|
|
|
use roaresearch\yii2\roa\behaviors\{Curies, Slug}; |
6
|
|
|
use yii\{base\Action, di\Instance}; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trait which gives the basic support for HAL contracts. |
10
|
|
|
*/ |
11
|
|
|
trait ContractTrait |
12
|
|
|
{ |
13
|
|
|
use EmbeddableTrait; |
14
|
|
|
|
15
|
14 |
|
public function behaviors() |
16
|
|
|
{ |
17
|
14 |
|
return array_merge(parent::behaviors(), [ |
18
|
14 |
|
$this->getSlugBehaviorId() => Instance::ensure( |
19
|
14 |
|
$this->slugBehaviorConfig(), |
20
|
|
|
Slug::class |
21
|
|
|
), |
22
|
14 |
|
$this->getCuriesBehaviorId() => Instance::ensure( |
23
|
14 |
|
$this->curiesBehaviorConfig(), |
24
|
|
|
Curies::class |
25
|
|
|
), |
26
|
|
|
]); |
27
|
|
|
} |
28
|
|
|
|
29
|
14 |
|
public function checkAccess( |
30
|
|
|
array $params = [], |
31
|
|
|
?Action $action = null |
32
|
|
|
): void { |
33
|
14 |
|
$this->getSlugBehavior()->checkAccess($params, $action); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
abstract protected function slugBehaviorConfig(): array|Slug; |
37
|
|
|
|
38
|
14 |
|
protected function curiesBehaviorConfig(): array |
39
|
|
|
{ |
40
|
14 |
|
return []; |
41
|
|
|
} |
42
|
|
|
|
43
|
14 |
|
protected function getSlugBehaviorId(): string |
44
|
|
|
{ |
45
|
14 |
|
return 'slug'; |
46
|
|
|
} |
47
|
|
|
|
48
|
14 |
|
protected function getCuriesBehaviorId(): string |
49
|
|
|
{ |
50
|
14 |
|
return 'curies'; |
51
|
|
|
} |
52
|
|
|
|
53
|
14 |
|
public function getSlugBehavior(): Slug |
54
|
|
|
{ |
55
|
14 |
|
return $this->getBehavior($this->getSlugBehaviorId()); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
9 |
|
public function getCuriesBehavior(): Curies |
59
|
|
|
{ |
60
|
9 |
|
return $this->getBehavior($this->getCuriesBehaviorId()); |
61
|
|
|
} |
62
|
|
|
|
63
|
12 |
|
public function getSelfLink(): string |
64
|
|
|
{ |
65
|
12 |
|
return $this->getSlugBehavior()->getSelfLink(); |
66
|
|
|
} |
67
|
|
|
|
68
|
9 |
|
public function getLinks() |
69
|
|
|
{ |
70
|
9 |
|
return $this->getSlugBehavior()->getSlugLinks() |
71
|
9 |
|
+ $this->getCuriesBehavior()->getCuriesLinks(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.