1 | <?php |
||
25 | class Permission |
||
26 | { |
||
27 | /** |
||
28 | * The workflow name. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $workflowName; |
||
33 | |||
34 | /** |
||
35 | * The permission id. |
||
36 | * |
||
37 | * @var string |
||
38 | */ |
||
39 | private $permissionId; |
||
40 | |||
41 | /** |
||
42 | * Construct. |
||
43 | * |
||
44 | * @param string $workflowName The workflow name. |
||
45 | * @param string $permissionId The permission id. |
||
46 | */ |
||
47 | protected function __construct(string $workflowName, string $permissionId) |
||
52 | |||
53 | /** |
||
54 | * Create a permission for a workflow. |
||
55 | * |
||
56 | * @param Workflow $workflow Workflow to which the permission belongs to. |
||
57 | * @param string $permissionId The permission id. |
||
58 | * |
||
59 | * @return static |
||
60 | */ |
||
61 | public static function forWorkflow(Workflow $workflow, string $permissionId): self |
||
65 | |||
66 | /** |
||
67 | * Reconstruct permission from a string representation. |
||
68 | * |
||
69 | * @param string $workflowName Workflow name. |
||
70 | * @param string $permissionId Permission id. |
||
71 | * |
||
72 | * @return static |
||
73 | */ |
||
74 | public static function forWorkflowName(string $workflowName, string $permissionId): self |
||
83 | |||
84 | /** |
||
85 | * Reconstruct permission from a string representation. |
||
86 | * |
||
87 | * @param string $permission Permission string representation. |
||
88 | * |
||
89 | * @return static |
||
90 | */ |
||
91 | public static function fromString(string $permission): self |
||
104 | |||
105 | /** |
||
106 | * Get the permission id. |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getPermissionId(): string |
||
114 | |||
115 | /** |
||
116 | * Get the workflow name. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getWorkflowName(): string |
||
124 | |||
125 | /** |
||
126 | * Cast permission to a string representation. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function __toString(): string |
||
134 | |||
135 | /** |
||
136 | * Consider if permission equals with another one. |
||
137 | * |
||
138 | * @param Permission $permission Permission to check against. |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function equals(Permission $permission): bool |
||
146 | |||
147 | /** |
||
148 | * Guard that permission values are valid. |
||
149 | * |
||
150 | * @param string $workflowName The workflow name. |
||
151 | * @param string $permissionId The permission id. |
||
152 | * @param string|null $message Optional error message. |
||
153 | * |
||
154 | * @return void |
||
155 | */ |
||
156 | protected static function guardValidPermission( |
||
164 | } |
||
165 |