diff --git a/docs/README.md b/docs/README.md index acc2ea7..a176cc9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,6 @@ - [`beyond:make:query`](commands/make-query.md) - [`beyond:make:request`](commands/make-request.md) - [`beyond:make:resource`](commands/make-resource.md) -- [`beyond:make:rule`](commands/make-rule.md) ### Domain - [`beyond:make:action`](commands/make-action.md) @@ -22,3 +21,7 @@ - `beyond:make:listener` - `beyond:make:model` - `beyond:make:observer` + +### Support +- [`beyond:make:provider`](commands/make-provider.md) +- [`beyond:make:rule`](commands/make-rule.md) diff --git a/docs/commands/make-provider.md b/docs/commands/make-provider.md new file mode 100644 index 0000000..48d424e --- /dev/null +++ b/docs/commands/make-provider.md @@ -0,0 +1,19 @@ +# `beyond:make:provider` +Creates a new service provider. + +> [!NOTE] +> Within the register method, you should **only bind things into the service container**. +> Because of this, service containers are **not** created under `Application/{App}/Providers` +> We want to avoid the feeling of registering things per application. You always register things +> for your entire Laravel project. + +## Signature +`beyond:make:provider {name} {--force}` + +| Parameters | Description | +|------------|---------------------------| +| name | The name of your provider | + +| Flags | Description | +|----------|-------------------------| +| --force | Overwrite existing file | diff --git a/docs/commands/make-rule.md b/docs/commands/make-rule.md index 65d7917..903a598 100644 --- a/docs/commands/make-rule.md +++ b/docs/commands/make-rule.md @@ -2,13 +2,12 @@ Creates a new rule. ## Signature -`beyond:make:rule {name} {--g|global} {--force}` +`beyond:make:rule {name} {--force}` | Parameters | Description | |------------|-----------------------| | name | The name of your rule | -| Flags | Description | -|----------|----------------------------------------------| -| --global | Creates a global rule inside `Support\Rules` | -| --force | Overwrite existing file | +| Flags | Description | +|----------|-------------------------| +| --force | Overwrite existing file | diff --git a/src/Commands/Abstracts/ApplicationCommand.php b/src/Commands/Abstracts/ApplicationCommand.php index e925ae6..8feddee 100644 --- a/src/Commands/Abstracts/ApplicationCommand.php +++ b/src/Commands/Abstracts/ApplicationCommand.php @@ -8,9 +8,4 @@ public function getNamespaceTemplate(): string { return 'Application\\%s\\%s'; } - - public function getBaseCommandName(): string - { - return 'App'; - } } diff --git a/src/Commands/Abstracts/BaseCommand.php b/src/Commands/Abstracts/BaseCommand.php index f6371da..fbd7b51 100644 --- a/src/Commands/Abstracts/BaseCommand.php +++ b/src/Commands/Abstracts/BaseCommand.php @@ -25,8 +25,6 @@ abstract protected function getStub(): string; abstract public function getNamespaceTemplate(): string; - abstract public function getBaseCommandName(): string; - abstract public function getType(): Type; public function getFileNameTemplate(): string diff --git a/src/Commands/Abstracts/DomainCommand.php b/src/Commands/Abstracts/DomainCommand.php index 4ac3ba1..64c79fd 100644 --- a/src/Commands/Abstracts/DomainCommand.php +++ b/src/Commands/Abstracts/DomainCommand.php @@ -8,9 +8,4 @@ public function getNamespaceTemplate(): string { return 'Domain\\%s\\%s'; } - - public function getBaseCommandName(): string - { - return 'Domain'; - } } diff --git a/src/Commands/Abstracts/SupportCommand.php b/src/Commands/Abstracts/SupportCommand.php new file mode 100644 index 0000000..f211363 --- /dev/null +++ b/src/Commands/Abstracts/SupportCommand.php @@ -0,0 +1,11 @@ +command->hasOption('global') && $this->command->option('global'); + return $this->command instanceof SupportCommand + || ($this->command->hasOption('global') && $this->command->option('global')); } private function setAppOrDomain(Stringable $name): void diff --git a/tests/Commands/MakeRuleCommandTest.php b/tests/Commands/MakeRuleCommandTest.php index 2411d01..d17f2ec 100644 --- a/tests/Commands/MakeRuleCommandTest.php +++ b/tests/Commands/MakeRuleCommandTest.php @@ -10,34 +10,6 @@ public function testCanMakeRule(): void { $this->artisan('beyond:make:rule User.UniqueUser'); - $file = beyond_app_path('User/Rules/UniqueUser.php'); - $contents = file_get_contents($file); - - $this->assertFileExists($file); - $this->assertStringNotContainsString('{{ namespace }}', $contents); - $this->assertStringNotContainsString('{{ className }}', $contents); - } - - public function testCanMakeRuleUsingForce(): void - { - $this->artisan('beyond:make:rule User.UniqueUser'); - - $file = beyond_app_path('User/Rules/UniqueUser.php'); - $contents = file_get_contents($file); - - $this->assertFileExists($file); - $this->assertStringNotContainsString('{{ namespace }}', $contents); - $this->assertStringNotContainsString('{{ className }}', $contents); - - $code = $this->artisan('beyond:make:rule User.UniqueUser --force'); - - $code->assertOk(); - } - - public function testCanMakeGlobalRule(): void - { - $this->artisan('beyond:make:rule User.UniqueUser --global'); - $file = beyond_support_path('Rules/UniqueUser.php'); $contents = file_get_contents($file); @@ -46,18 +18,18 @@ public function testCanMakeGlobalRule(): void $this->assertStringNotContainsString('{{ className }}', $contents); } - public function testCanMakeGlobalRuleUsingForce(): void + public function testCanMakeRuleUsingForce(): void { - $this->artisan('beyond:make:rule User.UniqueUser --global'); + $this->artisan('beyond:make:rule User.User/UniqueUser'); - $file = beyond_support_path('Rules/UniqueUser.php'); + $file = beyond_support_path('Rules/User/UniqueUser.php'); $contents = file_get_contents($file); $this->assertFileExists($file); $this->assertStringNotContainsString('{{ namespace }}', $contents); $this->assertStringNotContainsString('{{ className }}', $contents); - $code = $this->artisan('beyond:make:rule User.UniqueUser --global --force'); + $code = $this->artisan('beyond:make:rule User/UniqueUser --force'); $code->assertOk(); } diff --git a/tests/Commands/MakeServiceProviderCommandTest.php b/tests/Commands/MakeServiceProviderCommandTest.php index 76ff3d4..a4b2294 100644 --- a/tests/Commands/MakeServiceProviderCommandTest.php +++ b/tests/Commands/MakeServiceProviderCommandTest.php @@ -8,9 +8,9 @@ class MakeServiceProviderCommandTest extends TestCase { public function testCanMakeProvider(): void { - $this->artisan('beyond:make:provider User.UserServiceProvider'); + $this->artisan('beyond:make:provider UserServiceProvider'); - $file = beyond_app_path('User/Providers/UserServiceProvider.php'); + $file = beyond_support_path('Providers/UserServiceProvider.php'); $contents = file_get_contents($file); $this->assertFileExists($file); @@ -19,15 +19,15 @@ public function testCanMakeProvider(): void public function testCanMakeProviderUsingForce(): void { - $this->artisan('beyond:make:provider User.UserServiceProvider'); + $this->artisan('beyond:make:provider UserServiceProvider'); - $file = beyond_app_path('User/Providers/UserServiceProvider.php'); + $file = beyond_support_path('Providers/UserServiceProvider.php'); $contents = file_get_contents($file); $this->assertFileExists($file); $this->assertStringNotContainsString('{{ module }}', $contents); - $code = $this->artisan('beyond:make:provider User.UserServiceProvider --force'); + $code = $this->artisan('beyond:make:provider UserServiceProvider --force'); $code->assertOk(); }