| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Enums; |
| 4: | |
| 5: | /** |
| 6: | * Represents the applicability level (scope) of a setting. |
| 7: | * |
| 8: | * Resolution follows a strict precedence chain: |
| 9: | * USER (4) > TEAM (3) > APP (2) > TENANT (1) |
| 10: | * |
| 11: | * Settings with a higher scope value override those with a lower value. |
| 12: | */ |
| 13: | enum SettingScope: int |
| 14: | { |
| 15: | /** |
| 16: | * The base or installation-wide default. |
| 17: | * Defined by the developer via attributes or config files. |
| 18: | * Cannot be changed at runtime. |
| 19: | */ |
| 20: | case Installation = 0; |
| 21: | |
| 22: | /** |
| 23: | * The setting applies to the entire tenant (defaults). |
| 24: | * Commonly provided by the vendor (e.g., Pragmatiqu IT). |
| 25: | */ |
| 26: | case Tenant = 1; |
| 27: | |
| 28: | /** |
| 29: | * The setting applies to a specific project or application configuration. |
| 30: | * Typically set during rollout by a site_admin or tenant_admin. |
| 31: | */ |
| 32: | case App = 2; |
| 33: | |
| 34: | /** |
| 35: | * The setting applies to a team (a group of business partners). |
| 36: | * Useful for group-wide display preferences or reports. |
| 37: | */ |
| 38: | case Team = 3; |
| 39: | |
| 40: | /** |
| 41: | * The setting applies to a single user (personalization). |
| 42: | * This has the highest precedence. |
| 43: | */ |
| 44: | case User = 4; |
| 45: | |
| 46: | /** |
| 47: | * Returns the symbolic label of the scope, e.g., 'USER'. |
| 48: | */ |
| 49: | public function label(): string |
| 50: | { |
| 51: | return match ($this) { |
| 52: | self::Installation => 'INSTALLATION', |
| 53: | self::Tenant => 'TENANT', |
| 54: | self::App => 'APP', |
| 55: | self::Team => 'TEAM', |
| 56: | self::User => 'USER', |
| 57: | }; |
| 58: | } |
| 59: | |
| 60: | /** |
| 61: | * Indicates whether the current scope has higher precedence than another. |
| 62: | * |
| 63: | * @param SettingScope $other |
| 64: | * @return bool |
| 65: | */ |
| 66: | public function overrides(SettingScope $other): bool |
| 67: | { |
| 68: | return $this->value > $other->value; |
| 69: | } |
| 70: | } |
| 71: |