Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add scope helper methods to Session class

+51
+51
src/Session/Session.php
··· 5 5 use SocialDept\AtpClient\Data\Credentials; 6 6 use SocialDept\AtpClient\Data\DPoPKey; 7 7 use SocialDept\AtpClient\Enums\AuthType; 8 + use SocialDept\AtpClient\Enums\Scope; 8 9 9 10 class Session 10 11 { ··· 62 63 public function hasScope(string $scope): bool 63 64 { 64 65 return in_array($scope, $this->credentials->scope, true); 66 + } 67 + 68 + /** 69 + * Check if the session has the given scope (alias for hasScope with Scope enum support). 70 + */ 71 + public function can(string|Scope $scope): bool 72 + { 73 + $scopeValue = $scope instanceof Scope ? $scope->value : $scope; 74 + 75 + return $this->hasScope($scopeValue); 76 + } 77 + 78 + /** 79 + * Check if the session has any of the given scopes. 80 + * 81 + * @param array<string|Scope> $scopes 82 + */ 83 + public function canAny(array $scopes): bool 84 + { 85 + foreach ($scopes as $scope) { 86 + if ($this->can($scope)) { 87 + return true; 88 + } 89 + } 90 + 91 + return false; 92 + } 93 + 94 + /** 95 + * Check if the session has all of the given scopes. 96 + * 97 + * @param array<string|Scope> $scopes 98 + */ 99 + public function canAll(array $scopes): bool 100 + { 101 + foreach ($scopes as $scope) { 102 + if (! $this->can($scope)) { 103 + return false; 104 + } 105 + } 106 + 107 + return true; 108 + } 109 + 110 + /** 111 + * Check if the session does NOT have the given scope. 112 + */ 113 + public function cannot(string|Scope $scope): bool 114 + { 115 + return ! $this->can($scope); 65 116 } 66 117 67 118 public function authType(): AuthType