Skip to content

Commit c3e58b5

Browse files
authored
Add support for internachi/modular (#69)
* Refactor to use Laravel's generator commands * Modularize commands * Bring LilWayneLyrics helper back * Fix styling
1 parent 31bbf71 commit c3e58b5

File tree

9 files changed

+102
-123
lines changed

9 files changed

+102
-123
lines changed

src/Commands/MakeVerbEventCommand.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
namespace Thunk\Verbs\Commands;
44

5-
use Illuminate\Console\Command;
6-
use Thunk\Verbs\Helpers\Stub;
5+
use InterNACHI\Modular\Console\Commands\Make\Modularize;
6+
use Symfony\Component\Console\Attribute\AsCommand;
77

8-
class MakeVerbEventCommand extends Command
8+
#[AsCommand(name: 'verbs:event')]
9+
class MakeVerbEventCommand extends VerbGeneratorCommand
910
{
10-
protected $signature = 'verbs:event {name}';
11+
use Modularize {
12+
getDefaultNamespace as getModularizedNamespace;
13+
}
14+
15+
protected $name = 'verbs:event';
16+
17+
protected $description = 'Create a new Verbs event';
1118

12-
protected $description = 'Generate a Verbs event class.';
19+
protected $type = 'Event';
1320

14-
public function handle(): void
21+
protected function getStub()
1522
{
16-
$path = Stub::event($this->argument('name'));
23+
return $this->resolveStubPath('event.stub');
24+
}
1725

18-
$this->info("Event created at: $path");
26+
protected function getDefaultNamespace($rootNamespace)
27+
{
28+
return $this->getModularizedNamespace($rootNamespace).'\\Events';
1929
}
2030
}

src/Commands/MakeVerbStateCommand.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
namespace Thunk\Verbs\Commands;
44

5-
use Illuminate\Console\Command;
6-
use Thunk\Verbs\Helpers\Stub;
5+
use InterNACHI\Modular\Console\Commands\Make\Modularize;
6+
use Symfony\Component\Console\Attribute\AsCommand;
77

8-
class MakeVerbStateCommand extends Command
8+
#[AsCommand(name: 'verbs:state')]
9+
class MakeVerbStateCommand extends VerbGeneratorCommand
910
{
10-
protected $signature = 'verbs:state {name}';
11+
use Modularize {
12+
getDefaultNamespace as getModularizedNamespace;
13+
}
14+
15+
protected $name = 'verbs:state';
16+
17+
protected $description = 'Create a new Verbs state';
1118

12-
protected $description = 'Generate a Verbs state class.';
19+
protected $type = 'State';
1320

14-
public function handle(): void
21+
protected function getStub()
1522
{
16-
$path = Stub::state($this->argument('name'));
23+
return $this->resolveStubPath('state.stub');
24+
}
1725

18-
$this->info("State created at: $path");
26+
protected function getDefaultNamespace($rootNamespace)
27+
{
28+
return $this->getModularizedNamespace($rootNamespace).'\\States';
1929
}
2030
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Thunk\Verbs\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
use Thunk\Verbs\Support\LilWayneLyrics;
7+
8+
abstract class VerbGeneratorCommand extends GeneratorCommand
9+
{
10+
protected function resolveStubPath($stub): string
11+
{
12+
return file_exists($customPath = $this->laravel->basePath('/stubs/verbs/'.$stub))
13+
? $customPath
14+
: dirname(__DIR__, 2).'/stubs/'.$stub;
15+
}
16+
17+
protected function buildClass($name): string
18+
{
19+
return $this->replaceLyrics(parent::buildClass($name));
20+
}
21+
22+
protected function replaceLyrics($stub): string
23+
{
24+
return str_replace(['DummyLyric', '{{ lyric }}', '{{lyric}}'], LilWayneLyrics::random(), $stub);
25+
}
26+
27+
protected function promptForMissingArgumentsUsing(): array
28+
{
29+
return [
30+
'name' => [
31+
'What should the '.strtolower($this->type).' be named?',
32+
match ($this->type) {
33+
'Event' => 'e.g. ApplicationSubmitted',
34+
'State' => 'e.g. ApplicationState',
35+
default => '',
36+
},
37+
],
38+
];
39+
}
40+
}

src/Helpers/Stub.php

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
namespace Thunk\Verbs\Helpers;
3+
namespace Thunk\Verbs\Support;
44

55
use Illuminate\Support\Arr;
66

77
class LilWayneLyrics
88
{
9-
public static $lyrics = [
9+
protected const LYRICS = [
1010
'I need a Wynn-Dixie grocery bag full of money rig ',
1111
"You think you're calling shots, you got the wrong number. I love Benjamin Franklin more than his own mother.",
1212
'I play the hand that was dealt, I got a deck full of aces. I gave birth to your style, I need a check for my labor',
@@ -24,6 +24,6 @@ class LilWayneLyrics
2424

2525
public static function random(): string
2626
{
27-
return Arr::random(self::$lyrics);
27+
return Arr::random(self::LYRICS);
2828
}
2929
}

stubs/Event.stub

Lines changed: 0 additions & 13 deletions
This file was deleted.

stubs/State.stub

Lines changed: 0 additions & 10 deletions
This file was deleted.

stubs/event.stub

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use Thunk\Verbs\Event;
6+
7+
class {{ class }} extends Event
8+
{
9+
public function handle()
10+
{
11+
// {{ lyric }} - Lil Wayne
12+
}
13+
}

stubs/state.stub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
use Thunk\Verbs\State;
6+
7+
class {{ class }} extends State
8+
{
9+
// {{ lyric }} - Lil Wayne
10+
}

0 commit comments

Comments
 (0)