diff --git a/composer.json b/composer.json index 76ff92f..fd70bfb 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "require": { "php": "^8.1.0", "crell/api-problem": "^3.6.1", + "illuminate/console": "^9.0 || ^10.0", "illuminate/http": "^9.0 || ^10.0", "illuminate/support": "^9.0 || ^10.0", "nyholm/psr7": "^1.8", diff --git a/src/Command/CacheOpenAPIProcessors.php b/src/Command/CacheOpenAPIProcessors.php new file mode 100644 index 0000000..ddcd511 --- /dev/null +++ b/src/Command/CacheOpenAPIProcessors.php @@ -0,0 +1,74 @@ +/cache/" + + You may specify the cache --namespace + Defaults to "Membrane\Cache" + + You may avoid caching requests with --skip-requests + You may avoid caching responses with --skip-responses + TEXT; + + public function handle(): int + { + $openapi = $this->argument('openapi'); + + if (!is_string($openapi)) { + $this->error('openapi filepath MUST be a string'); + return Command::FAILURE; + } + + $destination = $this->option('destination') ?? + getcwd() . '/cache'; + + if (!is_string($destination)) { + $this->error('destination MUST be a string'); + return Command::FAILURE; + } + + $namespace = $this->option('namespace'); + if (!is_string($namespace)) { + $this->error('namespace MUST be a string'); + return Command::FAILURE; + } + + $buildRequests = !$this->option('skip-requests'); + assert(is_bool($buildRequests)); + $buildResponses = !$this->option('skip-responses'); + assert(is_bool($buildResponses)); + + $service = new \Membrane\Console\Service\CacheOpenAPIProcessors( + new ConsoleLogger($this->output) + ); + + return $service->cache( + $openapi, + $destination, + $namespace, + $buildRequests, + $buildResponses, + ) ? + Command::SUCCESS : + Command::FAILURE; + } +} diff --git a/src/Command/CacheOpenAPIRoutes.php b/src/Command/CacheOpenAPIRoutes.php new file mode 100644 index 0000000..c950a33 --- /dev/null +++ b/src/Command/CacheOpenAPIRoutes.php @@ -0,0 +1,52 @@ +/cache/" + TEXT; + + public function handle(): int + { + $openapi = $this->argument('openapi'); + + if (!is_string($openapi)) { + $this->error('openapi filepath MUST be a string'); + return Command::FAILURE; + } + + $destination = $this->option('destination') ?? + getcwd() . '/cache'; + + if (!is_string($destination)) { + $this->error('destination MUST be a string'); + return Command::FAILURE; + } + + $service = new OpenAPIRouter\Console\Service\CacheOpenAPIRoutes( + new ConsoleLogger($this->output) + ); + + return $service->cache( + $openapi, + rtrim($destination, '/') . '/routes.php', + ) ? + Command::SUCCESS : + Command::FAILURE; + } +} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index ad6e24e..35f3034 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -5,10 +5,8 @@ namespace Membrane\Laravel; use Membrane\Builder\Builder; -use Membrane\Console\Command\CacheOpenAPIProcessors; use Membrane\Laravel\Middleware\RequestValidation; use Membrane\Membrane; -use Membrane\OpenAPIRouter\Console\Commands\CacheOpenAPIRoutes; use Membrane\OpenAPIRouter\Router\Router; use Membrane\OpenAPIRouter\Router\ValueObject\RouteCollection; @@ -27,8 +25,8 @@ public function boot(): void if ($this->app->runningInConsole()) { $this->commands([ - CacheOpenAPIRoutes::class, - CacheOpenAPIProcessors::class + Command\CacheOpenAPIRoutes::class, + Command\CacheOpenAPIProcessors::class, ]); } }