Skip to content

Commit 0b95642

Browse files
committed
fix: console generator
1 parent 9407f77 commit 0b95642

File tree

14 files changed

+46
-83
lines changed

14 files changed

+46
-83
lines changed

src/Application/Exception/BaseErrorHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Bow\Http\Exception\HttpException;
88
use Bow\Validation\Exception\ValidationException;
99
use Bow\View\View;
10-
use JetBrains\PhpStorm\NoReturn;
1110
use PDOException;
1211
use Policier\Exception\TokenExpiredException;
1312
use Policier\Exception\TokenInvalidException;

src/Console/Command.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
use Bow\Console\Command\SeederCommand;
1111
use Bow\Console\Command\ServerCommand;
1212
use Bow\Console\Command\WorkerCommand;
13-
use Bow\Console\Command\AppEventCommand;
1413
use Bow\Console\Command\MigrationCommand;
15-
use Bow\Console\Command\ValidationCommand;
1614
use Bow\Console\Command\Generator\GenerateKeyCommand;
1715
use Bow\Console\Command\Generator\GenerateCacheCommand;
1816
use Bow\Console\Command\Generator\GenerateModelCommand;
@@ -21,11 +19,14 @@
2119
use Bow\Console\Command\Generator\GenerateConsoleCommand;
2220
use Bow\Console\Command\Generator\GenerateServiceCommand;
2321
use Bow\Console\Command\Generator\GenerateSessionCommand;
22+
use Bow\Console\Command\Generator\GenerateAppEventCommand;
2423
use Bow\Console\Command\Generator\GenerateProducerCommand;
2524
use Bow\Console\Command\Generator\GenerateExceptionCommand;
2625
use Bow\Console\Command\Generator\GenerateMessagingCommand;
26+
use Bow\Console\Command\Generator\GenerateMigrationCommand;
2727
use Bow\Console\Command\Generator\GenerateControllerCommand;
2828
use Bow\Console\Command\Generator\GenerateMiddlewareCommand;
29+
use Bow\Console\Command\Generator\GenerateValidationCommand;
2930
use Bow\Console\Command\Generator\GenerateNotificationCommand;
3031
use Bow\Console\Command\Generator\GenerateConfigurationCommand;
3132
use Bow\Console\Command\Generator\GenerateEventListenerCommand;
@@ -39,24 +40,22 @@ class Command extends AbstractCommand
3940
* @var array
4041
*/
4142
private array $commands = [
42-
"seed" => SeederCommand::class,
43-
"seed:table" => GenerateSeederCommand::class,
44-
"serve" => ServerCommand::class,
4543
"clear" => ClearCommand::class,
46-
"migrate" => MigrationCommand::class,
44+
"seed:table" => SeederCommand::class,
45+
"seed:all" => SeederCommand::class,
4746
"migration:migrate" => MigrationCommand::class,
4847
"migration:rollback" => MigrationCommand::class,
4948
"migration:reset" => MigrationCommand::class,
5049
"add:controller" => GenerateControllerCommand::class,
5150
"add:configuration" => GenerateConfigurationCommand::class,
5251
"add:exception" => GenerateExceptionCommand::class,
5352
"add:middleware" => GenerateMiddlewareCommand::class,
54-
"add:migration" => MigrationCommand::class,
53+
"add:migration" => GenerateMigrationCommand::class,
5554
"add:model" => GenerateModelCommand::class,
56-
"add:seeder" => SeederCommand::class,
55+
"add:seeder" => GenerateSeederCommand::class,
5756
"add:service" => GenerateServiceCommand::class,
58-
"add:validation" => ValidationCommand::class,
59-
"add:event" => AppEventCommand::class,
57+
"add:validation" => GenerateValidationCommand::class,
58+
"add:event" => GenerateAppEventCommand::class,
6059
"add:listener" => GenerateEventListenerCommand::class,
6160
"add:producer" => GenerateProducerCommand::class,
6261
"add:command" => GenerateConsoleCommand::class,

src/Console/Command/ClearCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ class ClearCommand extends AbstractCommand
1515
* @param string $action
1616
* @return void
1717
*/
18-
public function run(string $action): void
18+
public function run(): void
1919
{
20+
$action = $this->arg->getAction();
21+
2022
if (!in_array($action, ['view', 'cache', 'session', 'log', 'all'])) {
2123
$this->throwFailsCommand('Clear target not valid', 'clear help');
2224
}

src/Console/Command/AppEventCommand.php renamed to src/Console/Command/Generator/GenerateAppEventCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace Bow\Console\Command;
5+
namespace Bow\Console\Command\Generator;
66

77
use Bow\Console\AbstractCommand;
88
use Bow\Console\Generator;
9-
use JetBrains\PhpStorm\NoReturn;
109

11-
class AppEventCommand extends AbstractCommand
10+
class GenerateAppEventCommand extends AbstractCommand
1211
{
1312
/**
1413
* Add event

src/Console/Command/ValidationCommand.php renamed to src/Console/Command/Generator/GenerateValidationCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Bow\Console\Command;
5+
namespace Bow\Console\Command\Generator;
66

77
use Bow\Console\AbstractCommand;
88
use Bow\Console\Color;
99
use Bow\Console\Generator;
10-
use JetBrains\PhpStorm\NoReturn;
1110

12-
class ValidationCommand extends AbstractCommand
11+
class GenerateValidationCommand extends AbstractCommand
1312
{
1413
/**
1514
* Add validation

src/Console/Command/MigrationCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Bow\Console\AbstractCommand;
88
use Bow\Console\Color;
9-
use Bow\Console\Generator;
109
use Bow\Database\Database;
1110
use Bow\Database\Exception\ConnectionException;
1211
use Bow\Database\Exception\QueryBuilderException;

src/Console/Command/SeederCommand.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,11 @@
1212
use Bow\Database\Database;
1313
use Bow\Support\Str;
1414
use Exception;
15-
use JetBrains\PhpStorm\NoReturn;
1615

1716
class SeederCommand extends AbstractCommand
1817
{
1918
use ConsoleTrait;
2019

21-
/**
22-
* Create a seeder
23-
*
24-
* @param string $seeder
25-
*/
26-
public function run(string $seeder): void
27-
{
28-
$seeder = Str::plural($seeder);
29-
30-
$generator = new Generator(
31-
$this->setting->getSeederDirectory(),
32-
$seeder
33-
);
34-
35-
if ($generator->fileExists()) {
36-
echo "\033[0;31mThe seeder already exists.\033[00m";
37-
38-
exit(1);
39-
}
40-
41-
$generator->write('seeder', ['name' => $seeder]);
42-
43-
echo "\033[0;32mThe seeder has been created.\033[00m\n";
44-
45-
exit(0);
46-
}
47-
4820
/**
4921
* Launch all seeding
5022
*

src/Console/Command/ServerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ServerCommand extends AbstractCommand
1515
*/
1616
public function run(): void
1717
{
18-
$port = (int)$this->arg->getParameter('--port', 5000);
18+
$port = (int)$this->arg->getParameter('--port', 8080);
1919
$hostname = $this->arg->getParameter('--host', 'localhost');
2020
$settings = $this->arg->getParameter('--php-settings', false);
2121

src/Console/Console.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function call(?string $command): mixed
233233
// The built-in commands have priority
234234
$commands = $this->command->getCommands();
235235

236-
if (in_array($this->arg->getRawCommand(), array_keys($commands))) {
236+
if (!in_array($command, array_keys($commands))) {
237237
// Try to execute the custom command
238238
if (array_key_exists($this->arg->getRawCommand(), static::$registers) || array_key_exists($command, static::$registers)) {
239239
return $this->executeCustomCommand($command);
@@ -322,9 +322,7 @@ private function migration(): void
322322
$this->throwFailsCommand('This action is not exists!', 'help migration');
323323
}
324324

325-
$target = $this->arg->getTarget();
326-
327-
$this->command->call("migration:{$action}", $action, $target);
325+
$this->command->call("migration:{$action}", $action, $action);
328326
}
329327

330328
/**
@@ -480,6 +478,20 @@ private function flush(): void
480478
$this->command->call('flush:worker', $action);
481479
}
482480

481+
/**
482+
* Show bow framework version and current php version in console
483+
*
484+
* @return void
485+
*/
486+
private function getVersion(): void
487+
{
488+
$version = <<<USAGE
489+
\033[0;33mConsole running for \033[00mBow Framework: \033[0;32m%s\033[00m - PHP Version: \033[0;32m%s\033[0;33m
490+
491+
USAGE;
492+
echo sprintf($version, Console::VERSION, PHP_VERSION);
493+
}
494+
483495
/**
484496
* Display global help or helper command.
485497
*
@@ -501,7 +513,7 @@ private function help(?string $command = null): int
501513
\033[0;33mhelp\033[00m display command helper
502514
503515
\033[0;32mGENERATE\033[00m create a new app key and resources
504-
\033[0;33mgenerate:resource\033[00m Create new REST controller
516+
\033[0;33mgenerate:resource\033[00m Create new REST controller
505517
\033[0;33mgenerate:session-table\033[00m For generate the preset table for session
506518
\033[0;33mgenerate:cache-table\033[00m For generate the preset table for cache
507519
\033[0;33mgenerate:queue-table\033[00m For generate the preset table for queue
@@ -587,7 +599,6 @@ private function help(?string $command = null): int
587599
break;
588600
case 'generate':
589601
case 'gen':
590-
case 'generator':
591602
echo <<<U
592603
\n\033[0;32mgenerate\033[00m create a resource and app key
593604
[option]
@@ -600,6 +611,7 @@ private function help(?string $command = null): int
600611
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:notification-table For generate the table for notification
601612
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate:key For generate a new APP KEY
602613
\033[0;33m$\033[00m php \033[0;34mbow\033[00m generate help For display this
614+
\033[0;33mgen\033[00m Alias of \033[0;33mgenerate\033[00m
603615
604616
U;
605617
break;
@@ -620,7 +632,7 @@ private function help(?string $command = null): int
620632
echo <<<U
621633
\n\033[0;32mrun\033[00m for launch repl and local server\n
622634
[option]
623-
run:server [--port=5000] [--host=localhost] [--php-settings="display_errors=on"]
635+
run:server [--port=8080] [--host=localhost] [--php-settings="display_errors=on"]
624636
run:console [--include=filename.php] [--prompt=prompt_name]
625637
run:worker [--queue=default] [--connexion=beanstalkd,sqs,redis,database] [--tries=duration] [--sleep=duration] [--timeout=duration]
626638
@@ -670,18 +682,4 @@ private function help(?string $command = null): int
670682

671683
exit(0);
672684
}
673-
674-
/**
675-
* Show bow framework version and current php version in console
676-
*
677-
* @return void
678-
*/
679-
private function getVersion(): void
680-
{
681-
$version = <<<USAGE
682-
\033[0;33mConsole running for \033[00mBow Framework: \033[0;32m%s\033[00m - PHP Version: \033[0;32m%s\033[0;33m
683-
684-
USAGE;
685-
echo sprintf($version, Console::VERSION, PHP_VERSION);
686-
}
687685
}

src/Console/Traits/ConsoleTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Bow\Console\Traits;
66

77
use Bow\Console\Color;
8-
use JetBrains\PhpStorm\NoReturn;
98

109
trait ConsoleTrait
1110
{

0 commit comments

Comments
 (0)