Laravel AT Protocol Client (alpha & unstable)
at dev 2.0 kB view raw
1<?php 2 3namespace SocialDept\AtpClient\Enums; 4 5use BackedEnum; 6 7enum Scope: string 8{ 9 // Transition scopes (current) 10 case Atproto = 'atproto'; 11 case TransitionGeneric = 'transition:generic'; 12 case TransitionEmail = 'transition:email'; 13 case TransitionChat = 'transition:chat.bsky'; 14 15 /** 16 * Build a repo scope string for record operations. 17 * 18 * @param string|BackedEnum $collection The collection NSID (e.g., 'app.bsky.feed.post') 19 * @param array|null $actions The action (create, update, delete) 20 * 21 * @return string 22 */ 23 public static function repo(string|BackedEnum $collection, ?array $actions = []): string 24 { 25 $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 26 $scope = "repo:{$collection}"; 27 28 if (!empty($actions)) { 29 $scope .= '?' . implode('&', array_map(fn ($action) => "action={$action}", $actions)); 30 } 31 32 return $scope; 33 } 34 35 /** 36 * Build an RPC scope string for endpoint access. 37 * 38 * @param string $lxm The lexicon method ID (e.g., 'app.bsky.feed.getTimeline') 39 */ 40 public static function rpc(string $lxm): string 41 { 42 return "rpc:{$lxm}"; 43 } 44 45 /** 46 * Build a blob scope string for uploads. 47 * 48 * @param string|null $mimeType The mime type pattern (e.g., 'image/*', '*\/*') 49 */ 50 public static function blob(?string $mimeType = null): string 51 { 52 return 'blob:'.($mimeType ?? '*/*'); 53 } 54 55 /** 56 * Build an account scope string. 57 * 58 * @param string $attr The account attribute (e.g., 'email', 'status') 59 */ 60 public static function account(string $attr): string 61 { 62 return "account:{$attr}"; 63 } 64 65 /** 66 * Build an identity scope string. 67 * 68 * @param string $attr The identity attribute (e.g., 'handle') 69 */ 70 public static function identity(string $attr): string 71 { 72 return "identity:{$attr}"; 73 } 74}