Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support Symfony Console 5 | 6 | 7 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"require": {
"php": "^8.0.0",
"rareloop/lumberjack-core": "^5.0.1||^6.0.0",
"symfony/console": "^4.1",
"symfony/console": "^5.0 || ^6.0 || ^7.0",
"icanboogie/inflector": "^2.0",
"statamic/stringy": "^3.1.1"
},
Expand All @@ -26,4 +26,4 @@
"Rareloop\\Hatchet\\Test\\": "tests"
}
}
}
}
4 changes: 0 additions & 4 deletions src/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public function __construct(Application $app)
} else {
parent::__construct($this->name);
}

if (isset($this->description)) {
$this->setDescription($this->description);
}
}

protected function configureFromSignature()
Expand Down
3 changes: 2 additions & 1 deletion src/Commands/ControllerMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ class ControllerMake extends MakeFromStubCommand

protected $description = 'Create a Controller';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name');

$stub = file_get_contents(__DIR__ . '/stubs/Controller.stub');
$stub = str_replace('DummyController', $name, $stub);

$this->createFile('app/Http/Controllers/'.$name.'.php', $stub);
return self::SUCCESS;
}
}
11 changes: 6 additions & 5 deletions src/Commands/ExceptionMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Rareloop\Hatchet\Commands;

use Rareloop\Hatchet\Commands\MakeFromStubCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'make:exception {name : The class name of the Exception}',
description: 'Create a Exception'
)]
class ExceptionMake extends MakeFromStubCommand
{
protected $signature = 'make:exception {name : The class name of the Exception}';

protected $description = 'Create a Exception';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name');

Expand Down
11 changes: 6 additions & 5 deletions src/Commands/PostTypeMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ICanBoogie\Inflector;
use Rareloop\Hatchet\Commands\MakeFromStubCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -12,13 +13,13 @@
use Symfony\Component\Console\Question\Question;
use function Stringy\create as s;

#[AsCommand(
name: 'make:posttype {name : The class name of the PostType (singular)}',
description: 'Create a PostType'
)]
class PostTypeMake extends MakeFromStubCommand
{
protected $signature = 'make:posttype {name : The class name of the PostType (singular)}';

protected $description = 'Create a PostType';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$singular = $input->getArgument('name');
$plural = Inflector::get('en')->pluralize($singular);
Expand Down
10 changes: 6 additions & 4 deletions src/Commands/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

use Rareloop\Hatchet\Commands\Command;
use Rareloop\Router\Router;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'route:list',
description: 'List all registered routes'
)]
class RouteList extends Command
{
protected $signature = 'route:list';

protected $description = 'List all registered routes';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$router = $this->app->get(Router::class);

Expand Down
11 changes: 6 additions & 5 deletions src/Commands/ServiceProviderMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Rareloop\Hatchet\Commands;

use Rareloop\Hatchet\Commands\MakeFromStubCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'make:provider {name : The class name of the ServiceProvider}',
description: 'Create a ServiceProvider',
)]
class ServiceProviderMake extends MakeFromStubCommand
{
protected $signature = 'make:provider {name : The class name of the ServiceProvider}';

protected $description = 'Create a ServiceProvider';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name');

Expand Down
11 changes: 6 additions & 5 deletions src/Commands/ViewModelMake.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
namespace Rareloop\Hatchet\Commands;

use Rareloop\Hatchet\Commands\MakeFromStubCommand;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'make:viewmodel {name : The class name of the View Model}',
description: 'Create a ViewModel',
)]
class ViewModelMake extends MakeFromStubCommand
{
protected $signature = 'make:viewmodel {name : The class name of the View Model}';

protected $description = 'Create a ViewModel';

protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name');

Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class CommandTest extends TestCase
{
use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use MockeryPHPUnitIntegration;

/** @test */
public function can_create_a_command_with_a_name()
Expand Down Expand Up @@ -55,9 +55,10 @@ class CommandWithSignature extends Command
protected $signature = 'test:command {name} {--option}';
}

#[AsCommand(
name: 'test:command',
description: 'testing123'
)]
class CommandWithDescription extends Command
{
protected $name = 'test:command';

protected $description = 'testing123';
}
4 changes: 3 additions & 1 deletion tests/Unit/HatchetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ protected function configure()
$this->setName('test:command');
}

protected function execute(InputInterface $input, OutputInterface $output) {}
protected function execute(InputInterface $input, OutputInterface $output): int {
return false;
}
}
2 changes: 1 addition & 1 deletion tests/Unit/RegisterCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ protected function configure()
$this->setName('test:command');
}

protected function execute(InputInterface $input, OutputInterface $output) {}
protected function execute(InputInterface $input, OutputInterface $output): int {}
}