Skip to content

Commit 9b43d02

Browse files
committed
Symfony console application after bug fix
1 parent b0c3c55 commit 9b43d02

13 files changed

+310
-38
lines changed

system/Console/Commands/MakeCommandCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
5252
protected function configure(): void
5353
{
5454
$this->setDescription('Creates a command.')
55-
->setHelp('--name=CommandName')
5655
->addArgument('name', InputArgument::REQUIRED, 'The name of the command class.')
57-
->addOption('system', 's', InputOption::VALUE_OPTIONAL, 'Creates a system command.');
56+
->addOption('system', 's', InputOption::VALUE_NONE, 'Creates a system command.');
5857
}
5958

6059
}

system/Console/Commands/MakeControllerCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
4848
protected function configure(): void
4949
{
5050
$this->setDescription('Creates a controller.')
51-
->setHelp('--name=ControllerName')
5251
->addArgument('name', InputArgument::REQUIRED, 'The name of the controller class.');
5352
}
5453

system/Console/Commands/MakeEntityCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
3535
protected function configure(): void
3636
{
3737
$this->setDescription('Creates a entity.')
38-
->setHelp('--name=EntityName')
3938
->addArgument('name', InputArgument::REQUIRED, 'The name of the entity class.');
4039
}
4140

system/Console/Commands/MakeModelCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ protected function configure(): void
3030
{
3131
$this->setDescription('Creates a model.')
3232
->addArgument('name', InputArgument::REQUIRED, 'Model class name')
33-
->addOption('entity', 'e', InputOption::VALUE_OPTIONAL, 'Create Entity Class.');
33+
->addOption('entity', 'e', InputOption::VALUE_NONE, 'Create Entity Class.');
3434
}
3535

3636
protected function execute(InputInterface $input, OutputInterface $output): int
3737
{
3838
$name = trim($input->getArgument('name'), "/");
39-
4039
$entity = null;
41-
if ($input->hasOption('entity')) {
40+
if ($input->getOption('entity')) {
4241
$entity = MakeEntityCommand::makeEntity($name);
4342
}
4443
empty($entity) && $entity = "\\InitPHP\\Framework\\Database\\Entity::class";

system/Console/Commands/MakeProviderCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ protected function configure(): void
3030
{
3131
$this->setDescription('Creates a service provider.')
3232
->addArgument('name', InputArgument::REQUIRED, 'Provider Name')
33-
->addOption('system', 's', InputOption::VALUE_OPTIONAL, 'System Provider');
33+
->addOption('system', 's', InputOption::VALUE_NONE, 'System Provider');
3434
}
3535

3636
protected function execute(InputInterface $input, OutputInterface $output): int
3737
{
3838
$name = $input->getArgument('name');
3939
$path = APP_DIR . "Providers/";
4040
$namespace = "App\\Providers";
41-
if ($input->hasOption('system')) {
41+
if ($input->getOption('system')) {
4242
$path = SYS_DIR . "Providers/";
4343
$namespace = "InitPHP\\Framework\\Providers";
4444
}
@@ -49,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4949
$path .= implode("/", $split) . "/";
5050
}
5151
$path .= $name . ".php";
52-
$make = new MakeFile(SYS_DIR . "Console/Templates/Providers.txt");
52+
$make = new MakeFile(SYS_DIR . "Console/Templates/Provider.txt");
5353

5454
return $make->to($path, ["name" => $name, "namespace" => $namespace]) ? Command::SUCCESS : Command::FAILURE;
5555
}

system/Console/Commands/MakeRequestCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class MakeRequestCommand extends Command
2828
protected function configure(): void
2929
{
3030
$this->setDescription('Creates a request.')
31-
->addArgument('name', InputArgument::REQUIRED, 'Request class name')
32-
->setHelp('--name=RequestName');
31+
->addArgument('name', InputArgument::REQUIRED, 'Request class name');
3332
}
3433

3534
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -46,9 +45,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4645
$path .= implode("/", $split) . "/";
4746
}
4847
$path .= $name . ".php";
49-
$make = new MakeFile(SYS_DIR . "Console/Templates/Requests.txt");
5048

51-
return $make->to($path, ["name" => $name, "namespace" => $namespace]) ? Command::SUCCESS : Command::FAILURE;
49+
$write = (new MakeFile(SYS_DIR . 'Console/Templates/Request.txt'))
50+
->to($path, ['name' => $name, 'namespace' => $namespace]);
51+
52+
return $write ? Command::SUCCESS : Command::FAILURE;
5253
}
5354

5455
}

system/Console/Commands/RouteListCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use InitPHP\Framework\Base;
1818
use \InitPHP\Framework\Console\Command;
19+
use InitPHP\Framework\Console\Utils\Table;
1920
use Symfony\Component\Console\Input\InputArgument;
2021
use Symfony\Component\Console\Input\InputInterface;
2122
use Symfony\Component\Console\Output\OutputInterface;
@@ -35,7 +36,7 @@ protected function configure(): void
3536

3637
protected function execute(InputInterface $input, OutputInterface $output): int
3738
{
38-
if ($input->hasArgument('method')) {
39+
if (!empty($input->getArgument('method'))) {
3940
$routes = [
4041
strtoupper($input->getArgument('method')) => Base::getProperty('router')->getRoutes($input->getArgument('method'))
4142
];
@@ -44,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4445
}
4546

4647
$i = 0;
47-
$table = new \InitPHP\Console\Utils\Table();
48+
$table = new Table();
4849
foreach ($routes as $method => $route) {
4950
foreach ($route as $path => $row) {
5051
$execute = $row['execute'];
@@ -63,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6364
}
6465
}
6566

66-
$output->write(PHP_EOL . $table->getContent() . PHP_EOL);
67+
$output->writeln(PHP_EOL . $table->getContent() . PHP_EOL);
6768

6869
return Command::SUCCESS;
6970
}

system/Console/Commands/ServeCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,30 @@
1717
use \InitPHP\Framework\Console\Command;
1818
use Symfony\Component\Console\Input\InputArgument;
1919
use Symfony\Component\Console\Input\InputInterface;
20+
use Symfony\Component\Console\Input\InputOption;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122

2223
class ServeCommand extends Command
2324
{
2425

2526
protected static $defaultName = 'serve';
2627

27-
protected function execute(InputInterface $input, OutputInterface $output): int
28+
protected function execute(InputInterface $input, OutputInterface $output)
2829
{
29-
$host = $input->hasArgument("host") ? $input->getArgument("host") : "127.0.0.1";
30-
$port = $input->hasArgument("port") ? $input->getArgument("port") : 8000;
31-
!is_int($port) && $port = 8000;
30+
$host = $input->getOption("host");
31+
$port = intval($input->getOption("port"));
3232

3333
$shell = "php -S " . $host . ":" . $port . " -t \"" . PUBLIC_DIR . "\"";
3434
exec($shell);
3535

3636
return Command::SUCCESS;
3737
}
3838

39-
protected function configure(): void
39+
protected function configure()
4040
{
4141
$this->setDescription('It runs a PHP Web server.')
42-
->addArgument('host', InputArgument::OPTIONAL, 'The host name or IP', '127.0.0.1')
43-
->addArgument('port', InputArgument::OPTIONAL, 'The port', '8000');
42+
->addOption('host', 'host', InputOption::VALUE_OPTIONAL, 'The host name or IP', '127.0.0.1')
43+
->addOption('port', 'p', InputOption::VALUE_OPTIONAL, 'The port', '8000');
4444
}
4545

4646
}

system/Console/Commands/StorageLinkCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
3030

3131
protected function configure(): void
3232
{
33-
$this->setDescription('Creates a shortcut to the storage/public directory in public_html.')
34-
->setHelp('');
33+
$this->setDescription('Creates a shortcut to the storage/public directory in public_html.');
3534
}
3635

3736
}

system/Console/Commands/ViewCacheClearCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
3939

4040
protected function configure(): void
4141
{
42-
$this->setDescription('View cache clear')
43-
->setHelp('');
42+
$this->setDescription('View cache clear');
4443
}
4544

4645
}

0 commit comments

Comments
 (0)