-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from hungthai1401/develop
Develop
- Loading branch information
Showing
15 changed files
with
263 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace HT\Modules\Console; | ||
|
||
/** | ||
* Command: MakeScope | ||
* @package HT\Modules\Console | ||
*/ | ||
class MakeScope extends AbstractGenerator | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'module:make:scope | ||
{module : The alias of the module} | ||
{name : The class name}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new scope for the specified module.'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Scope'; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub(): string | ||
{ | ||
return __DIR__ . '/partial_stubs/scope.stub'; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return string | ||
*/ | ||
protected function getClass(string $name): string | ||
{ | ||
return 'Entities\\Scopes\\' . $name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace HT\Modules\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\Support\Str; | ||
|
||
/** | ||
* Command: RunSeed | ||
* @package HT\Modules\Console | ||
*/ | ||
class RunSeed extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'module:db:seed | ||
{module : The alias of the module} | ||
{--class= : The specified seeder need to run}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Run database seeder from the specified module.'; | ||
|
||
/** | ||
* The filesystem instance. | ||
* | ||
* @var \Illuminate\Filesystem\Filesystem | ||
*/ | ||
protected $files; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $moduleName; | ||
|
||
/** | ||
* Create a new controller creator command instance. | ||
* | ||
* @param \Illuminate\Filesystem\Filesystem $files | ||
* @return void | ||
*/ | ||
public function __construct(Filesystem $files) | ||
{ | ||
parent::__construct(); | ||
$this->files = $files; | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
try { | ||
$this->moduleName = $this->getModuleName(); | ||
if (! $this->moduleExists()) { | ||
$this->error('Module ' . $this->getModuleName() . ' does not exists!'); | ||
|
||
return; | ||
} | ||
$this->moduleSeed(); | ||
} catch (\Throwable $exception) { | ||
$this->error($exception->getMessage()); | ||
exit(); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getModuleName(): string | ||
{ | ||
return trim($this->argument('module')); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function moduleExists(): bool | ||
{ | ||
return $this->files->exists($this->modulePath()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function modulePath(): string | ||
{ | ||
return base_path(config('modules.directory') . '/' . $this->moduleName . '/'); | ||
} | ||
|
||
/** | ||
* module seed | ||
*/ | ||
public function moduleSeed() | ||
{ | ||
$result = []; | ||
if ($option = $this->option('class')) { | ||
$result[] = $option; | ||
} else { | ||
$seeders = $this->files->allFiles($this->modulePath() . '/database/seeds'); | ||
foreach ($seeders as $seeder) { | ||
$result[] = Str::replaceArray('.php', [''], $seeder->getFilename()); | ||
} | ||
} | ||
if (count($result) > 0) { | ||
array_walk($result, [$this, 'dbSeed']); | ||
$this->info("Module [{$this->getModuleName()}] seeded."); | ||
} | ||
} | ||
|
||
/** | ||
* Seed the specified module. | ||
* | ||
* @param string $class | ||
*/ | ||
protected function dbSeed($class) | ||
{ | ||
$this->call('db:seed', ['--class' => $class]); | ||
} | ||
} |
Oops, something went wrong.