-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap existing Services in Laravel Commands
- Loading branch information
Showing
4 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Membrane\Laravel\Command; | ||
|
||
use Illuminate\Console\Command; | ||
use Symfony\Component\Console\Logger\ConsoleLogger; | ||
|
||
final class CacheOpenAPIProcessors extends Command | ||
{ | ||
protected $signature = 'membrane:cache-openapi-routes' . | ||
'{openapi : Absolute filepath of OpenAPI}' . | ||
'{--destination= : Cache directory}' . | ||
'{--namespace=Membrane\Cache}' . | ||
'{--skip-requests}' . | ||
'{--skip-responses}'; | ||
|
||
protected $description = <<<TEXT | ||
Cache routes specified in OpenAPI file. | ||
You may specify the cache --destination | ||
Defaults to "<CWD>/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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Membrane\Laravel\Command; | ||
|
||
use Illuminate\Console\Command; | ||
use Membrane\OpenAPIRouter; | ||
use Symfony\Component\Console\Logger\ConsoleLogger; | ||
|
||
final class CacheOpenAPIRoutes extends Command | ||
{ | ||
protected $signature = 'membrane:cache-openapi-routes' . | ||
'{openapi : Absolute filepath of OpenAPI}' . | ||
'{--destination= : Cache directory}'; | ||
|
||
protected $description = <<<TEXT | ||
Cache routes specified in OpenAPI file. | ||
You may specify a --destination | ||
Defaults to "<CWD>/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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters