Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stubs to generate Actions through the make command #78

Merged
merged 3 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/ActionServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ public function boot()
$this->namespace('\App\Actions')->group($group);
});

// Register the make:action generator command.

if ($this->app->runningInConsole()) {
// publish Stubs File
$this->publishes([
__DIR__ . '/Commands/stubs/action.stub' => base_path('stubs/action.stub'),
], 'stubs');

// Register the make:action generator command.
$this->commands([
MakeActionCommand::class,
]);
Expand Down
19 changes: 16 additions & 3 deletions src/Commands/MakeActionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,30 @@ class MakeActionCommand extends GeneratorCommand
*/
protected function getStub()
{
return __DIR__.'/stubs/action.stub';
return $this->resolveStubPath('/stubs/action.stub');
}

/**
* Resolve the fully-qualified path to the stub.
*
* @param string $stub
* @return string
*/
protected function resolveStubPath($stub)
{
return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
? $customPath
: __DIR__ . $stub;
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Actions';
return $rootNamespace . '\Actions';
}
}