Skip to content

Commit

Permalink
Merge pull request #15 from spotlibs/feature/exploration
Browse files Browse the repository at this point in the history
Feature/exploration
  • Loading branch information
m45adiwinata authored Sep 12, 2024
2 parents 8504674 + 5c144ca commit 698fa87
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 5 deletions.
32 changes: 28 additions & 4 deletions src/Commands/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function handle()
parent::handle();
$this->createSwagger();
$this->createTest();
$this->createUsecase();
}
/**
* Create a swagger file controller.
Expand All @@ -83,11 +84,17 @@ protected function createSwagger()
*/
protected function createTest()
{
$className = class_basename($this->argument('name'));
$dirPath = "Controllers";
$temp = explode("/", $this->argument('name'));
if (count($temp) > 1) {
array_pop($temp);
$dirPath .= "/" . implode("/", $temp);
}
$className = class_basename($this->argument('name')) . 'Controller';
$this->call(
'make:test',
[
'name' => $className
'name' => $dirPath . "/" . $className
]
);
}
Expand All @@ -113,10 +120,27 @@ protected function getPath($name)
protected function replaceClass($stub, $name)
{
$stub = parent::replaceClass($stub, $name);
$stub = str_replace('DummyUsecase', Str::ucfirst($this->argument('name')) . 'Usecase', $stub);
$stub = str_replace('dummyUsecase', Str::lower($this->argument('name')) . 'Usecase', $stub);
$temp = explode("/", $this->argument('name'));
$usecaseClass = Str::ucfirst($temp[count($temp) - 1]) . 'Usecase';
$stub = str_replace('DummyUsecase', $usecaseClass, $stub);
$stub = str_replace('dummyUsecase', Str::lower($usecaseClass), $stub);
return $stub;
}
/**
* Create a usecase file.
*
* @return void
*/
protected function createUsecase()
{
$className = class_basename($this->argument('name'));
$this->call(
'make:usecase',
[
'name' => $className
]
);
}
/**
* Get the stub file for the generator.
*
Expand Down
97 changes: 97 additions & 0 deletions src/Commands/ServiceMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* PHP version 8
*
* @category Library
* @package Commands
* @author Made Mas Adi Winata <m45adiwinata@gmail.com>
* @license https://mit-license.org/ MIT License
* @version GIT: 0.0.9
* @link https://github.com/spotlibs
*/

declare(strict_types=1);

namespace Spotlibs\PhpLib\Commands;

use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;

/**
* ServiceMakeCommand
*
* Custom command
*
* @category Console
* @package Commands
* @author Made Mas Adi Winata <m45adiwinata@gmail.com>
* @license https://mit-license.org/ MIT License
* @link https://github.com/
*/
class ServiceMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:service';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new service for model class';
/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Service';
/**
* Get the destination class path.
*
* @param string $name name of the type
*
* @return string
*/
protected function getPath($name)
{
return parent::getPath($name . 'Service');
}
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
if ($this->option('resource')) {
return __DIR__ . '/stubs/service.stub';
}
return __DIR__ . '/stubs/service.plain.stub';
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace root namespace (generally App)
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\Services';
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['resource', null, InputOption::VALUE_NONE, 'Generate a resource service class.'],
];
}
}
5 changes: 4 additions & 1 deletion src/Commands/TestMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class TestMakeCommand extends GeneratorCommand
protected function getPath($name)
{
$name = Str::replaceFirst($this->laravel->getNamespace(), '', $name);
return $this->laravel->basePath() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name . 'Test') . '.php';
$temp = explode("\\", $name);
$name = implode(DIRECTORY_SEPARATOR, $temp);
$testPath = $this->laravel->basePath() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . $name . 'Test.php';
return $testPath;
}
/**
* Get the stub file for the generator.
Expand Down
26 changes: 26 additions & 0 deletions src/Commands/UsecaseMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class UsecaseMakeCommand extends GeneratorCommand
* @var string
*/
protected $type = 'Usecase';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
parent::handle();
$this->createTest();
}
/**
* Get the destination class path.
*
Expand All @@ -60,6 +70,22 @@ protected function getPath($name)
{
return parent::getPath($name . 'Usecase');
}
/**
* Create a unit test file.
*
* @return void
*/
protected function createTest()
{
$dirPath = "Usecases";
$className = class_basename($this->argument('name')) . 'Usecase';
$this->call(
'make:test',
[
'name' => $dirPath . "/" . $className
]
);
}
/**
* Get the stub file for the generator.
*
Expand Down
40 changes: 40 additions & 0 deletions src/Commands/stubs/service.plain.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* PHP version 8.0.30
*
* @category Application
* @package Services
* @author
* @license https://mit-license.org/ MIT License
* @version GIT: 0.0.1
* @link https://github.com/
*/

declare(strict_types=1);

namespace App\Services;

use App\Library\RestClient;
use Spotlibs\PhpLib\Exceptions\StdException;
use Spotlibs\PhpLib\Exceptions\ThirdPartyServiceException;

/**
* DummyClassService
*
* Call to surrounding microservices
*
* @category Surrounding
* @package App\Services
* @author
* @license https://mit-license.org/ MIT License
* @link https://github.com/
*/
class DummyClassService
{
private RestClient $rest_client;
public function __construct(RestClient $restClient)
{
$this->rest_client = $restClient;
}
}

0 comments on commit 698fa87

Please sign in to comment.