Laravel AT Protocol Client (alpha & unstable)

Use public paths when --public flag is set

+13 -9
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
+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