1 | <?php |
||
19 | class Slug extends \yii\base\Behavior |
||
20 | { |
||
21 | /** |
||
22 | * @var callable a PHP callable which will determine if the logged |
||
23 | * user has permission to access a resource record or any of its |
||
24 | * chidren resources. |
||
25 | * |
||
26 | * It must have signature |
||
27 | * ```php |
||
28 | * function (array $queryParams): void |
||
29 | * throws \yii\web\HTTPException |
||
30 | * { |
||
31 | * } |
||
32 | * ``` |
||
33 | */ |
||
34 | public $checkAccess; |
||
35 | |||
36 | /** |
||
37 | * @var string name of the parent relation of the `$owner` |
||
38 | */ |
||
39 | public $parentSlugRelation; |
||
40 | |||
41 | /** |
||
42 | * @var string name of the resource |
||
43 | */ |
||
44 | public $resourceName; |
||
45 | |||
46 | /** |
||
47 | * @var string|array name of the identifier attribute |
||
48 | */ |
||
49 | public $idAttribute = 'id'; |
||
50 | |||
51 | /** |
||
52 | * @var string separator to create the route for resources with multiple id |
||
53 | * attributes. |
||
54 | */ |
||
55 | public $idAttributeSeparator = '/'; |
||
56 | |||
57 | /** |
||
58 | * @var string parentNotFoundMessage for not found exception when the parent |
||
59 | * slug was not found |
||
60 | */ |
||
61 | public $parentNotFoundMessage = '"{resourceName}" not found'; |
||
62 | |||
63 | /** |
||
64 | * @var ?BaseActiveRecord parent record. |
||
65 | */ |
||
66 | protected $parentSlug; |
||
67 | |||
68 | /** |
||
69 | * @var string url to resource |
||
70 | */ |
||
71 | protected $resourceLink; |
||
72 | |||
73 | /** |
||
74 | * @inheritdoc |
||
75 | */ |
||
76 | public function init() |
||
86 | |||
87 | /** |
||
88 | * Ensures the parent record is attached to the behavior. |
||
89 | * |
||
90 | * @param BaseActiveRecord $owner |
||
|
|||
91 | * @param bool $force whether to force finding the slug parent record |
||
92 | * when `$parentSlugRelation` is defined |
||
93 | */ |
||
94 | private function ensureSlug(BaseActiveRecord $owner, bool $force = false) |
||
104 | |||
105 | /** |
||
106 | * This populates the slug to the parentSlug |
||
107 | * @param BaseActiveRecord $owner |
||
108 | */ |
||
109 | private function populateSlugParent(BaseActiveRecord $owner) |
||
128 | |||
129 | /** |
||
130 | * @return string value of the owner's identifier |
||
131 | */ |
||
132 | public function getResourceRecordId(): string |
||
141 | |||
142 | /** |
||
143 | * @return string HTTP Url to the resource list |
||
144 | */ |
||
145 | public function getResourceLink(): string |
||
151 | |||
152 | /** |
||
153 | * @return string HTTP Url to self resource |
||
154 | */ |
||
155 | public function getSelfLink(): string |
||
164 | |||
165 | /** |
||
166 | * @return array link to self resource and all the acumulated parent's links |
||
167 | */ |
||
168 | public function getSlugLinks(): array |
||
186 | |||
187 | /** |
||
188 | * Determines if the logged user has permission to access a resource |
||
189 | * record or any of its chidren resources. |
||
190 | * @param Array $params |
||
191 | */ |
||
192 | public function checkAccess(array $params) |
||
203 | } |
||
204 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.