Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

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

Simplify generator commands for unified client

+26 -81
+13 -44
src/Console/MakeAtpClientCommand.php
··· 10 10 { 11 11 protected $signature = 'make:atp-client 12 12 {name : The name of the client class} 13 - {--public : Generate a public client extension instead of authenticated} 14 13 {--force : Overwrite existing file}'; 15 14 16 15 protected $description = 'Create a new ATP domain client extension'; ··· 23 22 public function handle(): int 24 23 { 25 24 $name = $this->argument('name'); 26 - $isPublic = $this->option('public'); 27 25 28 26 if (! Str::endsWith($name, 'Client')) { 29 27 $name .= 'Client'; 30 28 } 31 29 32 - $path = $this->getPath($name, $isPublic); 30 + $path = $this->getPath($name); 33 31 34 32 if ($this->files->exists($path) && ! $this->option('force')) { 35 33 $this->components->error("Client [{$name}] already exists!"); ··· 39 37 40 38 $this->makeDirectory($path); 41 39 42 - $stub = $isPublic ? $this->getPublicStub() : $this->getStub(); 43 - $content = $this->populateStub($stub, $name, $isPublic); 40 + $content = $this->populateStub($this->getStub(), $name); 44 41 45 42 $this->files->put($path, $content); 46 43 47 44 $this->components->info("Client [{$path}] created successfully."); 48 45 49 - $this->outputRegistrationHint($name, $isPublic); 46 + $this->outputRegistrationHint($name); 50 47 51 48 return self::SUCCESS; 52 49 } 53 50 54 - protected function getPath(string $name, bool $isPublic = false): string 51 + protected function getPath(string $name): string 55 52 { 56 - $basePath = $isPublic 57 - ? config('client.generators.client_public_path', 'app/Services/Clients/Public') 58 - : config('client.generators.client_path', 'app/Services/Clients'); 53 + $basePath = config('client.generators.client_path', 'app/Services/Clients'); 59 54 60 55 return base_path($basePath.'/'.$name.'.php'); 61 56 } ··· 67 62 } 68 63 } 69 64 70 - protected function getNamespace(bool $isPublic = false): string 65 + protected function getNamespace(): string 71 66 { 72 - $basePath = $isPublic 73 - ? config('client.generators.client_public_path', 'app/Services/Clients/Public') 74 - : config('client.generators.client_path', 'app/Services/Clients'); 67 + $basePath = config('client.generators.client_path', 'app/Services/Clients'); 75 68 76 69 return Str::of($basePath) 77 70 ->replace('/', '\\') ··· 80 73 ->toString(); 81 74 } 82 75 83 - protected function populateStub(string $stub, string $name, bool $isPublic = false): string 76 + protected function populateStub(string $stub, string $name): string 84 77 { 85 78 return str_replace( 86 79 ['{{ namespace }}', '{{ class }}'], 87 - [$this->getNamespace($isPublic), $name], 80 + [$this->getNamespace(), $name], 88 81 $stub 89 82 ); 90 83 } 91 84 92 - protected function outputRegistrationHint(string $name, bool $isPublic): void 85 + protected function outputRegistrationHint(string $name): void 93 86 { 94 87 $this->newLine(); 95 88 $this->components->info('Register the extension in your AppServiceProvider:'); 96 89 $this->newLine(); 97 90 98 - $namespace = $this->getNamespace($isPublic); 91 + $namespace = $this->getNamespace(); 99 92 $extensionName = Str::of($name)->before('Client')->camel()->toString(); 100 - $clientClass = $isPublic ? 'AtpPublicClient' : 'AtpClient'; 101 93 102 94 $this->line("use {$namespace}\\{$name};"); 103 - $this->line("use SocialDept\\AtpClient\\".($isPublic ? 'Client\\Public\\' : '').$clientClass.';'); 95 + $this->line("use SocialDept\\AtpClient\\AtpClient;"); 104 96 $this->newLine(); 105 97 $this->line("// In boot() method:"); 106 - $this->line("{$clientClass}::extend('{$extensionName}', fn({$clientClass} \$atp) => new {$name}(\$atp));"); 98 + $this->line("AtpClient::extend('{$extensionName}', fn(AtpClient \$atp) => new {$name}(\$atp));"); 107 99 } 108 100 109 101 protected function getStub(): string ··· 120 112 protected AtpClient $atp; 121 113 122 114 public function __construct(AtpClient $parent) 123 - { 124 - $this->atp = $parent; 125 - } 126 - 127 - // 128 - } 129 - STUB; 130 - } 131 - 132 - protected function getPublicStub(): string 133 - { 134 - return <<<'STUB' 135 - <?php 136 - 137 - namespace {{ namespace }}; 138 - 139 - use SocialDept\AtpClient\Client\Public\AtpPublicClient; 140 - 141 - class {{ class }} 142 - { 143 - protected AtpPublicClient $atp; 144 - 145 - public function __construct(AtpPublicClient $parent) 146 115 { 147 116 $this->atp = $parent; 148 117 }
+13 -37
src/Console/MakeAtpRequestCommand.php
··· 11 11 protected $signature = 'make:atp-request 12 12 {name : The name of the request client class} 13 13 {--domain=bsky : The domain to extend (bsky, atproto, chat, ozone)} 14 - {--public : Generate a public request client instead of authenticated} 15 14 {--force : Overwrite existing file}'; 16 15 17 16 protected $description = 'Create a new ATP request client extension for an existing domain'; ··· 27 26 { 28 27 $name = $this->argument('name'); 29 28 $domain = $this->option('domain'); 30 - $isPublic = $this->option('public'); 31 29 32 30 if (! in_array($domain, $this->validDomains)) { 33 31 $this->components->error("Invalid domain [{$domain}]. Valid domains: ".implode(', ', $this->validDomains)); ··· 39 37 $name .= 'Client'; 40 38 } 41 39 42 - $path = $this->getPath($name, $isPublic); 40 + $path = $this->getPath($name); 43 41 44 42 if ($this->files->exists($path) && ! $this->option('force')) { 45 43 $this->components->error("Request client [{$name}] already exists!"); ··· 49 47 50 48 $this->makeDirectory($path); 51 49 52 - $stub = $isPublic ? $this->getPublicStub() : $this->getStub(); 53 - $content = $this->populateStub($stub, $name, $isPublic); 50 + $content = $this->populateStub($this->getStub(), $name); 54 51 55 52 $this->files->put($path, $content); 56 53 57 54 $this->components->info("Request client [{$path}] created successfully."); 58 55 59 - $this->outputRegistrationHint($name, $domain, $isPublic); 56 + $this->outputRegistrationHint($name, $domain); 60 57 61 58 return self::SUCCESS; 62 59 } 63 60 64 - protected function getPath(string $name, bool $isPublic = false): string 61 + protected function getPath(string $name): string 65 62 { 66 - $basePath = $isPublic 67 - ? config('client.generators.request_public_path', 'app/Services/Clients/Public/Requests') 68 - : config('client.generators.request_path', 'app/Services/Clients/Requests'); 63 + $basePath = config('client.generators.request_path', 'app/Services/Clients/Requests'); 69 64 70 65 return base_path($basePath.'/'.$name.'.php'); 71 66 } ··· 77 72 } 78 73 } 79 74 80 - protected function getNamespace(bool $isPublic = false): string 75 + protected function getNamespace(): string 81 76 { 82 - $basePath = $isPublic 83 - ? config('client.generators.request_public_path', 'app/Services/Clients/Public/Requests') 84 - : config('client.generators.request_path', 'app/Services/Clients/Requests'); 77 + $basePath = config('client.generators.request_path', 'app/Services/Clients/Requests'); 85 78 86 79 return Str::of($basePath) 87 80 ->replace('/', '\\') ··· 90 83 ->toString(); 91 84 } 92 85 93 - protected function populateStub(string $stub, string $name, bool $isPublic = false): string 86 + protected function populateStub(string $stub, string $name): string 94 87 { 95 88 return str_replace( 96 89 ['{{ namespace }}', '{{ class }}'], 97 - [$this->getNamespace($isPublic), $name], 90 + [$this->getNamespace(), $name], 98 91 $stub 99 92 ); 100 93 } 101 94 102 - protected function outputRegistrationHint(string $name, string $domain, bool $isPublic): void 95 + protected function outputRegistrationHint(string $name, string $domain): void 103 96 { 104 97 $this->newLine(); 105 98 $this->components->info('Register the extension in your AppServiceProvider:'); 106 99 $this->newLine(); 107 100 108 - $namespace = $this->getNamespace($isPublic); 101 + $namespace = $this->getNamespace(); 109 102 $extensionName = Str::of($name)->before('Client')->camel()->toString(); 110 - $clientClass = $isPublic ? 'AtpPublicClient' : 'AtpClient'; 111 103 112 104 $this->line("use {$namespace}\\{$name};"); 113 - $this->line("use SocialDept\\AtpClient\\".($isPublic ? 'Client\\Public\\' : '').$clientClass.';'); 105 + $this->line("use SocialDept\\AtpClient\\AtpClient;"); 114 106 $this->newLine(); 115 107 $this->line("// In boot() method:"); 116 - $this->line("{$clientClass}::extendDomain('{$domain}', '{$extensionName}', fn(\$domain) => new {$name}(\$domain));"); 108 + $this->line("AtpClient::extendDomain('{$domain}', '{$extensionName}', fn(\$domain) => new {$name}(\$domain));"); 117 109 } 118 110 119 111 protected function getStub(): string ··· 126 118 use SocialDept\AtpClient\Client\Requests\Request; 127 119 128 120 class {{ class }} extends Request 129 - { 130 - // 131 - } 132 - STUB; 133 - } 134 - 135 - protected function getPublicStub(): string 136 - { 137 - return <<<'STUB' 138 - <?php 139 - 140 - namespace {{ namespace }}; 141 - 142 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 143 - 144 - class {{ class }} extends PublicRequest 145 121 { 146 122 // 147 123 }