1 | <?php |
||
29 | class Subject |
||
30 | { |
||
31 | const PRINCIPAL = 'principal'; |
||
32 | const ROLE = 'role'; |
||
33 | |||
34 | /** |
||
35 | * @var string The subject type |
||
36 | */ |
||
37 | private $type; |
||
38 | /** |
||
39 | * @var string The subject identifier |
||
40 | */ |
||
41 | private $id; |
||
42 | |||
43 | /** |
||
44 | * Creates a new BasicSubject. |
||
45 | * |
||
46 | * @param string $type The subject type (e.g. "role", "principal") |
||
47 | * @param string $id The subject identifier |
||
48 | */ |
||
49 | 2 | protected function __construct(string $type, string $id) |
|
50 | { |
||
51 | 2 | $this->type = $type; |
|
52 | 2 | $this->id = $id; |
|
53 | 2 | } |
|
54 | |||
55 | /** |
||
56 | * Gets the identifier of the subject, usually a unique key. |
||
57 | * |
||
58 | * @return string The subject identifier |
||
59 | */ |
||
60 | 2 | public function getId(): string |
|
64 | |||
65 | /** |
||
66 | * Gets the type of the subject. |
||
67 | * |
||
68 | * @return string The subject type |
||
69 | */ |
||
70 | 2 | public function getType(): string |
|
74 | |||
75 | /** |
||
76 | * Gets a string representation of this subject. |
||
77 | * |
||
78 | * @return string The string representation |
||
79 | */ |
||
80 | 2 | public function __toString(): string |
|
84 | |||
85 | /** |
||
86 | * Gets a Subject for a principal (such as a username). |
||
87 | * |
||
88 | * @param string $id The subject identifier |
||
89 | * @return Subject The subject created! |
||
90 | */ |
||
91 | 1 | public static function principal(string $id): Subject |
|
95 | |||
96 | /** |
||
97 | * Gets a Subject for a role. |
||
98 | * |
||
99 | * @param string $id The subject identifier |
||
100 | * @return Subject The subject created |
||
101 | */ |
||
102 | 1 | public static function role(string $id): Subject |
|
106 | } |
||
107 |