Laravel AT Protocol Client (alpha & unstable)

Merge branch 'refs/heads/main' into dev

+2
config/client.php
··· 188 188 */ 189 189 'generators' => [ 190 190 'client_path' => 'app/Services/Clients', 191 + 'client_public_path' => 'app/Services/Clients/Public', 191 192 'request_path' => 'app/Services/Clients/Requests', 193 + 'request_public_path' => 'app/Services/Clients/Public/Requests', 192 194 ], 193 195 ];
+3 -1
docs/extensions.md
··· 41 41 php artisan make:atp-request TrendingClient --domain=bsky --public 42 42 ``` 43 43 44 - The generated files are placed in `app/Services/Clients/` (domain clients) and `app/Services/Clients/Requests/` (request clients). You can customize these paths in `config/client.php`: 44 + The generated files are placed in configurable directories. You can customize these paths in `config/client.php`: 45 45 46 46 ```php 47 47 'generators' => [ 48 48 'client_path' => 'app/Services/Clients', 49 + 'client_public_path' => 'app/Services/Clients/Public', 49 50 'request_path' => 'app/Services/Clients/Requests', 51 + 'request_public_path' => 'app/Services/Clients/Public/Requests', 50 52 ], 51 53 ``` 52 54
+14 -10
src/Console/MakeAtpClientCommand.php
··· 29 29 $name .= 'Client'; 30 30 } 31 31 32 - $path = $this->getPath($name); 32 + $path = $this->getPath($name, $isPublic); 33 33 34 34 if ($this->files->exists($path) && ! $this->option('force')) { 35 35 $this->components->error("Client [{$name}] already exists!"); ··· 40 40 $this->makeDirectory($path); 41 41 42 42 $stub = $isPublic ? $this->getPublicStub() : $this->getStub(); 43 - $content = $this->populateStub($stub, $name); 43 + $content = $this->populateStub($stub, $name, $isPublic); 44 44 45 45 $this->files->put($path, $content); 46 46 ··· 51 51 return self::SUCCESS; 52 52 } 53 53 54 - protected function getPath(string $name): string 54 + protected function getPath(string $name, bool $isPublic = false): string 55 55 { 56 - $basePath = config('client.generators.client_path', 'app/Services/Clients'); 56 + $basePath = $isPublic 57 + ? config('client.generators.client_public_path', 'app/Services/Clients/Public') 58 + : config('client.generators.client_path', 'app/Services/Clients'); 57 59 58 60 return base_path($basePath.'/'.$name.'.php'); 59 61 } ··· 65 67 } 66 68 } 67 69 68 - protected function getNamespace(): string 70 + protected function getNamespace(bool $isPublic = false): string 69 71 { 70 - $basePath = config('client.generators.client_path', 'app/Services/Clients'); 72 + $basePath = $isPublic 73 + ? config('client.generators.client_public_path', 'app/Services/Clients/Public') 74 + : config('client.generators.client_path', 'app/Services/Clients'); 71 75 72 76 return Str::of($basePath) 73 77 ->replace('/', '\\') ··· 76 80 ->toString(); 77 81 } 78 82 79 - protected function populateStub(string $stub, string $name): string 83 + protected function populateStub(string $stub, string $name, bool $isPublic = false): string 80 84 { 81 85 return str_replace( 82 86 ['{{ namespace }}', '{{ class }}'], 83 - [$this->getNamespace(), $name], 87 + [$this->getNamespace($isPublic), $name], 84 88 $stub 85 89 ); 86 90 } ··· 91 95 $this->components->info('Register the extension in your AppServiceProvider:'); 92 96 $this->newLine(); 93 97 94 - $namespace = $this->getNamespace(); 98 + $namespace = $this->getNamespace($isPublic); 95 99 $extensionName = Str::of($name)->before('Client')->camel()->toString(); 96 100 $clientClass = $isPublic ? 'AtpPublicClient' : 'AtpClient'; 97 101 ··· 99 103 $this->line("use SocialDept\\AtpClient\\".($isPublic ? 'Client\\Public\\' : '').$clientClass.';'); 100 104 $this->newLine(); 101 105 $this->line("// In boot() method:"); 102 - $this->line("{$clientClass}::extend('{$extensionName}', fn(\${$clientClass} \$atp) => new {$name}(\$atp));"); 106 + $this->line("{$clientClass}::extend('{$extensionName}', fn({$clientClass} \$atp) => new {$name}(\$atp));"); 103 107 } 104 108 105 109 protected function getStub(): string
+13 -9
src/Console/MakeAtpRequestCommand.php
··· 39 39 $name .= 'Client'; 40 40 } 41 41 42 - $path = $this->getPath($name); 42 + $path = $this->getPath($name, $isPublic); 43 43 44 44 if ($this->files->exists($path) && ! $this->option('force')) { 45 45 $this->components->error("Request client [{$name}] already exists!"); ··· 50 50 $this->makeDirectory($path); 51 51 52 52 $stub = $isPublic ? $this->getPublicStub() : $this->getStub(); 53 - $content = $this->populateStub($stub, $name); 53 + $content = $this->populateStub($stub, $name, $isPublic); 54 54 55 55 $this->files->put($path, $content); 56 56 ··· 61 61 return self::SUCCESS; 62 62 } 63 63 64 - protected function getPath(string $name): string 64 + protected function getPath(string $name, bool $isPublic = false): string 65 65 { 66 - $basePath = config('client.generators.request_path', 'app/Services/Clients/Requests'); 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'); 67 69 68 70 return base_path($basePath.'/'.$name.'.php'); 69 71 } ··· 75 77 } 76 78 } 77 79 78 - protected function getNamespace(): string 80 + protected function getNamespace(bool $isPublic = false): string 79 81 { 80 - $basePath = config('client.generators.request_path', 'app/Services/Clients/Requests'); 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'); 81 85 82 86 return Str::of($basePath) 83 87 ->replace('/', '\\') ··· 86 90 ->toString(); 87 91 } 88 92 89 - protected function populateStub(string $stub, string $name): string 93 + protected function populateStub(string $stub, string $name, bool $isPublic = false): string 90 94 { 91 95 return str_replace( 92 96 ['{{ namespace }}', '{{ class }}'], 93 - [$this->getNamespace(), $name], 97 + [$this->getNamespace($isPublic), $name], 94 98 $stub 95 99 ); 96 100 } ··· 101 105 $this->components->info('Register the extension in your AppServiceProvider:'); 102 106 $this->newLine(); 103 107 104 - $namespace = $this->getNamespace(); 108 + $namespace = $this->getNamespace($isPublic); 105 109 $extensionName = Str::of($name)->before('Client')->camel()->toString(); 106 110 $clientClass = $isPublic ? 'AtpPublicClient' : 'AtpClient'; 107 111