Skip to content

Commit 29c38bf

Browse files
committed
create a action generator
1 parent f3ab891 commit 29c38bf

File tree

4 files changed

+90
-3
lines changed

4 files changed

+90
-3
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"php",
1313
"generator",
1414
"cli",
15-
"artisan"
15+
"artisan",
16+
"action",
17+
"pattern"
1618
],
1719
"license": "MIT",
1820
"authors": [
@@ -35,4 +37,4 @@
3537
]
3638
}
3739
}
38-
}
40+
}

src/Console/MakeAction.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace RajTechnologies\Tools\Console;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class MakeAction extends GeneratorCommand
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'make:action {name}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Create a new action class';
22+
23+
/**
24+
* The type of class being generated.
25+
*
26+
* @var string
27+
*/
28+
protected $type = 'Action';
29+
30+
/**
31+
* Get the stub file for the generator.
32+
*
33+
* @return string
34+
*/
35+
protected function getStub()
36+
{
37+
return __DIR__.'/../../stubs/action.stub';
38+
}
39+
40+
/**
41+
* Get the default namespace for the class.
42+
*
43+
* @param string $rootNamespace
44+
* @return string
45+
*/
46+
protected function getDefaultNamespace($rootNamespace)
47+
{
48+
return $rootNamespace.'\Actions';
49+
}
50+
}

src/ToolServiceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\File;
88
use RajTechnologies\Tools\Console\MakeRepository;
99
use RajTechnologies\Tools\Console\MakeRepositoryInterface;
10+
use RajTechnologies\Tools\Console\MakeAction;
1011

1112
class ToolServiceProvider extends ServiceProvider
1213
{
@@ -28,6 +29,11 @@ public function boot(){
2829
], 'config');
2930
}
3031
// Repository Pattern End
32+
// Action Start
33+
if ($this->app->runningInConsole()) {
34+
$this->commands([MakeAction::class]);
35+
}
36+
// Action End
3137
}
3238

3339
public function register(){
@@ -62,4 +68,4 @@ protected function bindInterfaces()
6268
// Repository Pattern End
6369
}
6470

65-
?>
71+
?>

stubs/action.stub

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
/**
6+
* Class DummyClass.
7+
*/
8+
class DummyClass
9+
{
10+
/**
11+
* Create a new action instance.
12+
*
13+
* @return void
14+
*/
15+
public function __construct()
16+
{
17+
// Prepare the action for execution, leveraging constructor injection.
18+
}
19+
20+
/**
21+
* Execute the action.
22+
*
23+
* @return mixed
24+
*/
25+
public function execute()
26+
{
27+
// business logic
28+
}
29+
}

0 commit comments

Comments
 (0)