Skip to content

Commit 2a5227b

Browse files
Merge pull request #1 from InitPHP/v3.x
V3.x
2 parents 5403065 + cc192a5 commit 2a5227b

20 files changed

+507
-235
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 InitPHP
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
"nesbot/carbon": "^2.72",
4545
"initphp/cookies": "^1.1",
4646
"initphp/logger": "^1.0",
47-
"initphp/console": "^2.0",
4847
"initphp/upload": "^1.0",
4948
"filp/whoops": "^2.15",
50-
"initphp/performance-meter": "^1.0"
49+
"initphp/performance-meter": "^1.0",
50+
"symfony/console": "^6.4"
5151
},
5252
"require-dev": {
5353
"symfony/var-dumper": "^6.4"

system/Console/Command.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
declare(strict_types=1);
1515
namespace InitPHP\Framework\Console;
1616

17-
abstract class Command extends \InitPHP\Console\Command
17+
abstract class Command extends \Symfony\Component\Console\Command\Command
1818
{
19+
20+
public const SUCCESS = 0;
21+
public const FAILURE = 1;
22+
public const INVALID = 2;
23+
1924
}

system/Console/Commands/KeyGenerateCommand.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,27 @@
1414
declare(strict_types=1);
1515
namespace InitPHP\Framework\Console\Commands;
1616

17+
use InitPHP\Framework\Console\Command;
1718
use InitPHP\Framework\Console\Utils\ChangeDotEnv;
18-
use \InitPHP\Console\{Input, Output};
19+
use Symfony\Component\Console\Input\InputInterface;
20+
use Symfony\Component\Console\Output\OutputInterface;
1921

20-
class KeyGenerateCommand extends \InitPHP\Framework\Console\Command
22+
class KeyGenerateCommand extends Command
2123
{
2224

23-
/** @var string Command */
24-
public $command = 'key:generate';
25+
protected static $defaultName = 'key:generate';
2526

26-
public function execute(Input $input, Output $output)
27+
public function execute(InputInterface $input, OutputInterface $output): int
2728
{
2829
$key = '"' . base64_encode(random_bytes(16)) . '"';
29-
if ((new ChangeDotEnv())->change('APP_KEY', $key)->save()) {
30-
$output->success("Ok");
31-
} else {
32-
$output->error("Failed");
33-
}
34-
}
3530

36-
public function definition(): string
37-
{
38-
return 'Generates and replaces a new APP_KEY.';
31+
return ((new ChangeDotEnv())->change('APP_KEY', $key)->save()) ? Command::SUCCESS : Command::FAILURE;
3932
}
4033

41-
public function arguments(): array
34+
protected function configure(): void
4235
{
43-
return [];
36+
$this->setDescription('Creates a command.')
37+
->setHelp('');
4438
}
4539

46-
}
40+
}

system/Console/Commands/MakeCommandCommand.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,26 @@
1414
declare(strict_types=1);
1515
namespace InitPHP\Framework\Console\Commands;
1616

17-
use \InitPHP\Console\{Input, Output};
1817
use InitPHP\Framework\Console\Command;
1918
use InitPHP\Framework\Console\Utils\MakeFile;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Input\InputOption;
22+
use Symfony\Component\Console\Output\OutputInterface;
2023

2124
class MakeCommandCommand extends Command
2225
{
2326

24-
public $command = 'make:command';
27+
protected static $defaultName = 'make:command';
2528

26-
public function execute(Input $input, Output $output)
29+
public function execute(InputInterface $input, OutputInterface $output): int
2730
{
28-
$name = !$input->hasSegment(0) ? $output->ask("Name ?", false) : $input->getSegment(0);
31+
32+
$name = $input->getArgument('name');
33+
2934
$path = APP_DIR . "Console/Commands/";
3035
$namespace = "App\\Console\\Commands";
31-
if ($input->hasOption('s')) {
36+
if ($input->getOption('system')) {
3237
$path = SYS_DIR . "Console/Commands/";
3338
$namespace = "InitPHP\\Framework\\Console\\Commands";
3439
}
@@ -41,16 +46,14 @@ public function execute(Input $input, Output $output)
4146
$path .= $name . ".php";
4247
$make = new MakeFile(SYS_DIR . "Console/Templates/Command.txt");
4348

44-
if ($make->to($path, ["name" => $name, "namespace" => $namespace])) {
45-
$output->success("Ok");
46-
} else {
47-
$output->error("Error");
48-
}
49+
return $make->to($path, ["name" => $name, "namespace" => $namespace]) ? Command::SUCCESS : Command::FAILURE;
4950
}
5051

51-
public function definition(): string
52+
protected function configure(): void
5253
{
53-
return 'Creates a command.';
54+
$this->setDescription('Creates a command.')
55+
->addArgument('name', InputArgument::REQUIRED, 'The name of the command class.')
56+
->addOption('system', 's', InputOption::VALUE_NONE, 'Creates a system command.');
5457
}
5558

5659
}

system/Console/Commands/MakeControllerCommand.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@
1414
declare(strict_types=1);
1515
namespace InitPHP\Framework\Console\Commands;
1616

17+
use InitPHP\Framework\Console\Command;
1718
use InitPHP\Framework\Console\Utils\MakeFile;
18-
use \InitPHP\Console\{Input, Output};
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Output\OutputInterface;
1922

20-
class MakeControllerCommand extends \InitPHP\Framework\Console\Command
23+
class MakeControllerCommand extends Command
2124
{
2225

23-
/** @var string Command */
24-
public $command = 'make:controller';
26+
protected static $defaultName = 'make:controller';
2527

26-
public function execute(Input $input, Output $output)
28+
public function execute(InputInterface $input, OutputInterface $output): int
2729
{
28-
$name = trim((!$input->hasSegment(0) ? $output->ask("Name ?", false) : $input->getSegment(0)), "/");
30+
$name = $input->getArgument('name');
31+
2932
$path = APP_DIR . "HTTP/Controllers/";
3033
$namespace = "App\\HTTP\\Controllers";
3134

@@ -39,21 +42,13 @@ public function execute(Input $input, Output $output)
3942
$path .= $name . ".php";
4043
$make = new MakeFile(SYS_DIR . "Console/Templates/Controller.txt");
4144

42-
if ($make->to($path, ["name" => $name, "namespace" => $namespace])) {
43-
$output->success("Ok");
44-
} else {
45-
$output->error("Error");
46-
}
47-
}
48-
49-
public function definition(): string
50-
{
51-
return 'Creates a controller.';
45+
return $make->to($path, ["name" => $name, "namespace" => $namespace]) ? Command::SUCCESS : Command::FAILURE;
5246
}
5347

54-
public function arguments(): array
48+
protected function configure(): void
5549
{
56-
return [];
50+
$this->setDescription('Creates a controller.')
51+
->addArgument('name', InputArgument::REQUIRED, 'The name of the controller class.');
5752
}
5853

5954
}

system/Console/Commands/MakeEntityCommand.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,28 @@
1414
declare(strict_types=1);
1515
namespace InitPHP\Framework\Console\Commands;
1616

17+
use InitPHP\Framework\Console\Command;
1718
use InitPHP\Framework\Console\Utils\MakeFile;
18-
use \InitPHP\Console\{Input, Output};
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Output\OutputInterface;
1922

20-
class MakeEntityCommand extends \InitPHP\Framework\Console\Command
23+
class MakeEntityCommand extends Command
2124
{
2225

23-
/** @var string Command */
24-
public $command = 'make:entity';
26+
protected static $defaultName = 'make:entity';
2527

26-
public function execute(Input $input, Output $output)
28+
public function execute(InputInterface $input, OutputInterface $output): int
2729
{
28-
$name = trim((!$input->hasSegment(0) ? $output->ask("Name ?", false) : $input->getSegment(0)), "/");
30+
$name = trim($input->getArgument('name'), "/");
2931

30-
if (!empty(self::makeEntity($name))) {
31-
$output->success("Ok");
32-
} else {
33-
$output->error("Error");
34-
}
35-
}
36-
37-
public function definition(): string
38-
{
39-
return 'Creates a entity.';
32+
return !empty(self::makeEntity($name)) ? Command::SUCCESS : Command::FAILURE;
4033
}
4134

42-
public function arguments(): array
35+
protected function configure(): void
4336
{
44-
return [];
37+
$this->setDescription('Creates a entity.')
38+
->addArgument('name', InputArgument::REQUIRED, 'The name of the entity class.');
4539
}
4640

4741
public static function makeEntity(string $name): ?string

system/Console/Commands/MakeMiddlewareCommand.php

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@
1515
namespace InitPHP\Framework\Console\Commands;
1616

1717
use InitPHP\Framework\Console\Utils\MakeFile;
18-
use \InitPHP\Console\{Input, Output};
18+
use \InitPHP\Framework\Console\Command;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Output\OutputInterface;
1922

20-
class MakeMiddlewareCommand extends \InitPHP\Framework\Console\Command
23+
class MakeMiddlewareCommand extends Command
2124
{
2225

23-
/** @var string Command */
24-
public $command = 'make:middleware';
26+
protected static $defaultName = 'make:middleware';
2527

26-
public function execute(Input $input, Output $output)
28+
protected function configure(): void
2729
{
28-
$name = trim((!$input->hasSegment(0) ? $output->ask("Name ?", false) : $input->getSegment(0)), "/");
30+
$this->setDescription('Creates a middleware.')
31+
->addArgument('name', InputArgument::REQUIRED, 'Middleware Name');
32+
}
33+
34+
protected function execute(InputInterface $input, OutputInterface $output): int
35+
{
36+
$name = trim($input->getArgument('name'), "/");
2937

3038
$path = APP_DIR . "HTTP/Middlewares/";
3139
$namespace = "App\\HTTP\\Middlewares";
@@ -39,21 +47,7 @@ public function execute(Input $input, Output $output)
3947
$path .= $name . ".php";
4048
$make = new MakeFile(SYS_DIR . "Console/Templates/Middleware.txt");
4149

42-
if ($make->to($path, ["name" => $name, "namespace" => $namespace])) {
43-
$output->success("Ok");
44-
} else {
45-
$output->error("Error");
46-
}
47-
}
48-
49-
public function definition(): string
50-
{
51-
return 'Creates a middleware.';
52-
}
53-
54-
public function arguments(): array
55-
{
56-
return [];
50+
return $make->to($path, ["name" => $name, "namespace" => $namespace]) ? Command::SUCCESS : Command::FAILURE;
5751
}
5852

5953
}

system/Console/Commands/MakeModelCommand.php

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,29 @@
1515
namespace InitPHP\Framework\Console\Commands;
1616

1717
use InitPHP\Framework\Console\Utils\MakeFile;
18-
use \InitPHP\Console\{Input, Output};
18+
use \InitPHP\Framework\Console\Command;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Input\InputOption;
22+
use Symfony\Component\Console\Output\OutputInterface;
1923

20-
class MakeModelCommand extends \InitPHP\Framework\Console\Command
24+
class MakeModelCommand extends Command
2125
{
2226

23-
/** @var string Command */
24-
public $command = 'make:model';
27+
protected static $defaultName = 'make:model';
2528

26-
public function execute(Input $input, Output $output)
29+
protected function configure(): void
2730
{
28-
$name = trim((!$input->hasSegment(0) ? $output->ask("Name ?", false) : $input->getSegment(0)), "/");
31+
$this->setDescription('Creates a model.')
32+
->addArgument('name', InputArgument::REQUIRED, 'Model class name')
33+
->addOption('entity', 'e', InputOption::VALUE_NONE, 'Create Entity Class.');
34+
}
2935

36+
protected function execute(InputInterface $input, OutputInterface $output): int
37+
{
38+
$name = trim($input->getArgument('name'), "/");
3039
$entity = null;
31-
if ($input->hasOption('e')) {
40+
if ($input->getOption('entity')) {
3241
$entity = MakeEntityCommand::makeEntity($name);
3342
}
3443
empty($entity) && $entity = "\\InitPHP\\Framework\\Database\\Entity::class";
@@ -45,21 +54,9 @@ public function execute(Input $input, Output $output)
4554
$path .= $name . ".php";
4655
$make = new MakeFile(SYS_DIR . "Console/Templates/Model.txt");
4756

48-
if ($make->to($path, ["name" => $name, "namespace" => $namespace, 'entity' => $entity, 'schema' => camelCase2SnakeCase($name)])) {
49-
$output->success("Ok");
50-
} else {
51-
$output->error("Error");
52-
}
53-
}
54-
55-
public function definition(): string
56-
{
57-
return 'Creates a model.';
58-
}
59-
60-
public function arguments(): array
61-
{
62-
return [];
57+
return $make->to($path, ["name" => $name, "namespace" => $namespace, 'entity' => $entity, 'schema' => camelCase2SnakeCase($name)])
58+
? Command::SUCCESS
59+
: Command::FAILURE;
6360
}
6461

6562
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy