Skip to content

Commit

Permalink
Merge pull request #65 from sroehrl/request-guard
Browse files Browse the repository at this point in the history
CLI generation of request guards
  • Loading branch information
sroehrl authored Feb 11, 2023
2 parents eb6a1be + 5513dc2 commit 4d914c3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/Cli/Create/CreateGuardCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Neoan\Cli\Create;

use Neoan\NeoanApp;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand('create:request', 'Creates file extending RouteGuard')]
class CreateGuardCommand extends Command
{
protected static $defaultName = 'create:request';
protected static $defaultDescription = 'Creates file extending RouteGuard';
private NeoanApp $neoanApp;

public function __construct(NeoanApp $neoanApp, string $name = null)
{
$this->neoanApp = $neoanApp;
parent::__construct($name);
}

protected function configure()
{
$this
->setHelp('Creates class extending RouteGuard via Namespace')
->addArgument(
'name',
InputArgument::REQUIRED,
'fully qualified namespace'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
FileCreator::process('request', $input->getArgument('name'), $this->neoanApp, $output);

return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion src/Cli/Create/FileCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FileCreator
public static NeoanApp $neoanApp;
public static Output $output;

public static function process($type, $name, $neoanApp, $output)
public static function process($type, $name, $neoanApp, $output): void
{
self::$neoanApp = $neoanApp;
self::$output = $output;
Expand Down
10 changes: 10 additions & 0 deletions src/Cli/Stubs/RequestTemplate.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace {{namespace}};

use Neoan\Request\RequestGuard;

class {{name}} extends RequestGuard
{

}

0 comments on commit 4d914c3

Please sign in to comment.