-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
SupportsScopes.php
54 lines (51 loc) · 1.6 KB
/
SupportsScopes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace Crell\AttributeUtils;
interface SupportsScopes
{
/**
* The scopes this attribute should be included in.
*
* To include this attribute in the "no scope requested" case,
* include `null` in the returned array.
*
* In the typical case of an attribute only having a single
* scope that is specified by an argument, do this:
*
* class Attr implements SupportsScopes
* {
* public function __construct(private ?string $scope) {}
*
* public function scopes(): array
* {
* return [$this->scope];
* }
* }
*
* If the intent is to allow multiple scopes on the same
* attribute instance, you would do this (assuming you want
* it included it unscoped requests):
*
* class Attr implements SupportsScopes
* {
* public function __construct(private array $scopes = [null]) {}
*
* public function scopes(): array
* {
* return $this->scopes;
* }
* }
*
* Returning an empty array means this attribute will never be
* included, so that is most likely never what you want.
*
* To explicitly exclude an attribute in unscoped or scoped requests, implement
* `Excludable` and mark it excluded in the appropriate scope.
*
* @return array<string|null>
* An array of scope names in which this attribute should
* be included. Include a value of `null` to have it
* present in the "none requested" scope.
*/
public function scopes(): array;
}