Skip to content

Commit 698fa87

Browse files
authored
Merge pull request #15 from spotlibs/feature/exploration
Feature/exploration
2 parents 8504674 + 5c144ca commit 698fa87

File tree

5 files changed

+195
-5
lines changed

5 files changed

+195
-5
lines changed

src/Commands/ControllerMakeCommand.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function handle()
6060
parent::handle();
6161
$this->createSwagger();
6262
$this->createTest();
63+
$this->createUsecase();
6364
}
6465
/**
6566
* Create a swagger file controller.
@@ -83,11 +84,17 @@ protected function createSwagger()
8384
*/
8485
protected function createTest()
8586
{
86-
$className = class_basename($this->argument('name'));
87+
$dirPath = "Controllers";
88+
$temp = explode("/", $this->argument('name'));
89+
if (count($temp) > 1) {
90+
array_pop($temp);
91+
$dirPath .= "/" . implode("/", $temp);
92+
}
93+
$className = class_basename($this->argument('name')) . 'Controller';
8794
$this->call(
8895
'make:test',
8996
[
90-
'name' => $className
97+
'name' => $dirPath . "/" . $className
9198
]
9299
);
93100
}
@@ -113,10 +120,27 @@ protected function getPath($name)
113120
protected function replaceClass($stub, $name)
114121
{
115122
$stub = parent::replaceClass($stub, $name);
116-
$stub = str_replace('DummyUsecase', Str::ucfirst($this->argument('name')) . 'Usecase', $stub);
117-
$stub = str_replace('dummyUsecase', Str::lower($this->argument('name')) . 'Usecase', $stub);
123+
$temp = explode("/", $this->argument('name'));
124+
$usecaseClass = Str::ucfirst($temp[count($temp) - 1]) . 'Usecase';
125+
$stub = str_replace('DummyUsecase', $usecaseClass, $stub);
126+
$stub = str_replace('dummyUsecase', Str::lower($usecaseClass), $stub);
118127
return $stub;
119128
}
129+
/**
130+
* Create a usecase file.
131+
*
132+
* @return void
133+
*/
134+
protected function createUsecase()
135+
{
136+
$className = class_basename($this->argument('name'));
137+
$this->call(
138+
'make:usecase',
139+
[
140+
'name' => $className
141+
]
142+
);
143+
}
120144
/**
121145
* Get the stub file for the generator.
122146
*

src/Commands/ServiceMakeCommand.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8
5+
*
6+
* @category Library
7+
* @package Commands
8+
* @author Made Mas Adi Winata <m45adiwinata@gmail.com>
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.0.9
11+
* @link https://github.com/spotlibs
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Spotlibs\PhpLib\Commands;
17+
18+
use Illuminate\Console\GeneratorCommand;
19+
use Symfony\Component\Console\Input\InputOption;
20+
21+
/**
22+
* ServiceMakeCommand
23+
*
24+
* Custom command
25+
*
26+
* @category Console
27+
* @package Commands
28+
* @author Made Mas Adi Winata <m45adiwinata@gmail.com>
29+
* @license https://mit-license.org/ MIT License
30+
* @link https://github.com/
31+
*/
32+
class ServiceMakeCommand extends GeneratorCommand
33+
{
34+
/**
35+
* The console command name.
36+
*
37+
* @var string
38+
*/
39+
protected $name = 'make:service';
40+
/**
41+
* The console command description.
42+
*
43+
* @var string
44+
*/
45+
protected $description = 'Create a new service for model class';
46+
/**
47+
* The type of class being generated.
48+
*
49+
* @var string
50+
*/
51+
protected $type = 'Service';
52+
/**
53+
* Get the destination class path.
54+
*
55+
* @param string $name name of the type
56+
*
57+
* @return string
58+
*/
59+
protected function getPath($name)
60+
{
61+
return parent::getPath($name . 'Service');
62+
}
63+
/**
64+
* Get the stub file for the generator.
65+
*
66+
* @return string
67+
*/
68+
protected function getStub()
69+
{
70+
if ($this->option('resource')) {
71+
return __DIR__ . '/stubs/service.stub';
72+
}
73+
return __DIR__ . '/stubs/service.plain.stub';
74+
}
75+
/**
76+
* Get the default namespace for the class.
77+
*
78+
* @param string $rootNamespace root namespace (generally App)
79+
*
80+
* @return string
81+
*/
82+
protected function getDefaultNamespace($rootNamespace)
83+
{
84+
return $rootNamespace . '\Services';
85+
}
86+
/**
87+
* Get the console command options.
88+
*
89+
* @return array
90+
*/
91+
protected function getOptions()
92+
{
93+
return [
94+
['resource', null, InputOption::VALUE_NONE, 'Generate a resource service class.'],
95+
];
96+
}
97+
}

src/Commands/TestMakeCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ class TestMakeCommand extends GeneratorCommand
6060
protected function getPath($name)
6161
{
6262
$name = Str::replaceFirst($this->laravel->getNamespace(), '', $name);
63-
return $this->laravel->basePath() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name . 'Test') . '.php';
63+
$temp = explode("\\", $name);
64+
$name = implode(DIRECTORY_SEPARATOR, $temp);
65+
$testPath = $this->laravel->basePath() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . $name . 'Test.php';
66+
return $testPath;
6467
}
6568
/**
6669
* Get the stub file for the generator.

src/Commands/UsecaseMakeCommand.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ class UsecaseMakeCommand extends GeneratorCommand
4949
* @var string
5050
*/
5151
protected $type = 'Usecase';
52+
/**
53+
* Execute the console command.
54+
*
55+
* @return void
56+
*/
57+
public function handle()
58+
{
59+
parent::handle();
60+
$this->createTest();
61+
}
5262
/**
5363
* Get the destination class path.
5464
*
@@ -60,6 +70,22 @@ protected function getPath($name)
6070
{
6171
return parent::getPath($name . 'Usecase');
6272
}
73+
/**
74+
* Create a unit test file.
75+
*
76+
* @return void
77+
*/
78+
protected function createTest()
79+
{
80+
$dirPath = "Usecases";
81+
$className = class_basename($this->argument('name')) . 'Usecase';
82+
$this->call(
83+
'make:test',
84+
[
85+
'name' => $dirPath . "/" . $className
86+
]
87+
);
88+
}
6389
/**
6490
* Get the stub file for the generator.
6591
*

src/Commands/stubs/service.plain.stub

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* PHP version 8.0.30
5+
*
6+
* @category Application
7+
* @package Services
8+
* @author
9+
* @license https://mit-license.org/ MIT License
10+
* @version GIT: 0.0.1
11+
* @link https://github.com/
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace App\Services;
17+
18+
use App\Library\RestClient;
19+
use Spotlibs\PhpLib\Exceptions\StdException;
20+
use Spotlibs\PhpLib\Exceptions\ThirdPartyServiceException;
21+
22+
/**
23+
* DummyClassService
24+
*
25+
* Call to surrounding microservices
26+
*
27+
* @category Surrounding
28+
* @package App\Services
29+
* @author
30+
* @license https://mit-license.org/ MIT License
31+
* @link https://github.com/
32+
*/
33+
class DummyClassService
34+
{
35+
private RestClient $rest_client;
36+
public function __construct(RestClient $restClient)
37+
{
38+
$this->rest_client = $restClient;
39+
}
40+
}

0 commit comments

Comments
 (0)