Skip to content

Commit

Permalink
docs: write docs
Browse files Browse the repository at this point in the history
  • Loading branch information
regnerisch committed May 25, 2024
1 parent 7d35cec commit bed01fa
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 60 deletions.
5 changes: 4 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
19 changes: 19 additions & 0 deletions docs/commands/make-provider.md
Original file line number Diff line number Diff line change
@@ -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 |
9 changes: 4 additions & 5 deletions docs/commands/make-rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
5 changes: 0 additions & 5 deletions src/Commands/Abstracts/ApplicationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@ public function getNamespaceTemplate(): string
{
return 'Application\\%s\\%s';
}

public function getBaseCommandName(): string
{
return 'App';
}
}
2 changes: 0 additions & 2 deletions src/Commands/Abstracts/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/Commands/Abstracts/DomainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,4 @@ public function getNamespaceTemplate(): string
{
return 'Domain\\%s\\%s';
}

public function getBaseCommandName(): string
{
return 'Domain';
}
}
11 changes: 11 additions & 0 deletions src/Commands/Abstracts/SupportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace AkrilliA\LaravelBeyond\Commands\Abstracts;

abstract class SupportCommand extends BaseCommand
{
public function getNamespaceTemplate(): string
{
return 'Support\\%s';
}
}
5 changes: 3 additions & 2 deletions src/Commands/MakeRuleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace AkrilliA\LaravelBeyond\Commands;

use AkrilliA\LaravelBeyond\Commands\Abstracts\ApplicationCommand;
use AkrilliA\LaravelBeyond\Commands\Abstracts\SupportCommand;
use AkrilliA\LaravelBeyond\Type;

final class MakeRuleCommand extends ApplicationCommand
final class MakeRuleCommand extends SupportCommand
{
protected $signature = 'beyond:make:rule {name?} {--g|global} {--force}';
protected $signature = 'beyond:make:rule {name?} {--force}';

protected $description = 'Make a new rule';

Expand Down
3 changes: 2 additions & 1 deletion src/Commands/MakeServiceProviderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace AkrilliA\LaravelBeyond\Commands;

use AkrilliA\LaravelBeyond\Commands\Abstracts\ApplicationCommand;
use AkrilliA\LaravelBeyond\Commands\Abstracts\SupportCommand;
use AkrilliA\LaravelBeyond\Type;

final class MakeServiceProviderCommand extends ApplicationCommand
final class MakeServiceProviderCommand extends SupportCommand
{
protected $signature = 'beyond:make:provider {name} {--force}';

Expand Down
6 changes: 4 additions & 2 deletions src/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use AkrilliA\LaravelBeyond\Commands\Abstracts\ApplicationCommand;
use AkrilliA\LaravelBeyond\Commands\Abstracts\BaseCommand;
use AkrilliA\LaravelBeyond\Commands\Abstracts\DomainCommand;
use AkrilliA\LaravelBeyond\Commands\Abstracts\SupportCommand;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;

use function Laravel\Prompts\suggest;

final class NameResolver
{
private string $appOrDomain;
private ?string $appOrDomain = null;

private string $namespace;

Expand Down Expand Up @@ -49,7 +50,8 @@ public function getPath(): string

private function isGlobal(): bool
{
return $this->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
Expand Down
36 changes: 4 additions & 32 deletions tests/Commands/MakeRuleCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Commands/MakeServiceProviderCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down

0 comments on commit bed01fa

Please sign in to comment.